{"id":9204,"date":"2022-04-19T06:04:15","date_gmt":"2022-04-19T06:04:15","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=9204"},"modified":"2023-01-16T15:22:31","modified_gmt":"2023-01-16T09:52:31","slug":"linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/","title":{"rendered":"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 30px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 50px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"color: #000080;\">Pcd driver with multiple devices testing contd<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">In this article, Please download and open the file from this link:<\/span> <\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"https:\/\/drive.google.com\/file\/d\/1toWCdzLVCDoyOGyhD17vVnMfAl-JDzNE\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/drive.google.com\/file\/d\/1toWCdzLVCDoyOGyhD17vVnMfAl-JDzNE\/view?usp=sharing<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">I&#8217;m going to explain that program now. The file name is&nbsp; dev_read.c.&nbsp;<\/span><span style=\"font-weight: 400; color: #000000;\">This is a very simple program to open and read data from the device file.<\/span><\/p>\n<figure id=\"attachment_9207\" aria-describedby=\"caption-attachment-9207\" style=\"width: 779px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-9207\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-1-19.png\" alt=\"Figure 1. dev_read.c\" width=\"779\" height=\"388\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-19.png 779w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-19-300x149.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-19-768x383.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-19-600x299.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-19-120x60.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-19-500x249.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-19-200x100.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-19-400x199.png 400w\" sizes=\"(max-width: 779px) 100vw, 779px\" \/><figcaption id=\"caption-attachment-9207\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. dev_read.c<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let me explain this program. So, there is a buffer here, as shown in Figure 2, the global buffer. Where I&#8217;m going to keep the data, whatever I&#8217;m going to read from the device.<\/span><\/p>\n<figure id=\"attachment_9208\" aria-describedby=\"caption-attachment-9208\" style=\"width: 777px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-9208\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-2-14.png\" alt=\"Figure 2. Program\" width=\"777\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-14.png 777w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-14-300x153.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-14-768x392.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-14-600x307.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-14-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-14-500x255.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-14-200x102.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-14-400x204.png 400w\" sizes=\"(max-width: 777px) 100vw, 777px\" \/><figcaption id=\"caption-attachment-9208\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Program<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let me just explain what this program does. First of all, I actually open a device file here. In this case, I select pcdev-3. You can take this device file information through the command line itself. But for this exercise, I just hardcoded it.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You can implement the command line version. I&#8217;m going to open this device file with read-only access mode.&nbsp;<\/span><\/p>\n<figure id=\"attachment_9209\" aria-describedby=\"caption-attachment-9209\" style=\"width: 779px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-9209\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-3-13.png\" alt=\"Figure 3. Error checking\" width=\"779\" height=\"394\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13.png 779w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13-300x152.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13-768x388.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13-600x303.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13-500x253.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13-540x272.png 540w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13-200x101.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13-400x202.png 400w\" sizes=\"(max-width: 779px) 100vw, 779px\" \/><figcaption id=\"caption-attachment-9209\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Error checking<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, this does the error checking here(shown in Figure 3). If open returns negative value, then the open is failed. And appropriate userspace errno variable will be set, you can use this perror API to decode that errno value and print the meaning of that.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If the open is failure, then I just go to the end, and I execute close(fd), and I just return.<\/span><\/p>\n<figure id=\"attachment_9210\" aria-describedby=\"caption-attachment-9210\" style=\"width: 925px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9210\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-4-13.png\" alt=\"Figure 4. Out implementation\" width=\"925\" height=\"470\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-13.png 925w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-13-300x152.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-13-768x390.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-13-600x305.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-13-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-13-500x254.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-13-200x102.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-13-400x203.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-13-800x406.png 800w\" sizes=\"(max-width: 925px) 100vw, 925px\" \/><figcaption id=\"caption-attachment-9210\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Out implementation<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, please note that many people argue that using goto is bad in programming, that is true. But it is OK if it is a straight jump, and if it is simple in kernel module development, and the goto is used. If it is a straight jump and it is very helpful in error handling.<\/span><\/p>\n<figure id=\"attachment_9211\" aria-describedby=\"caption-attachment-9211\" style=\"width: 778px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9211\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-5-13.png\" alt=\"Figure 5. Open was successful\" width=\"778\" height=\"386\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-13.png 778w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-13-300x149.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-13-768x381.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-13-600x298.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-13-120x60.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-13-500x248.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-13-200x99.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-13-400x198.png 400w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><figcaption id=\"caption-attachment-9211\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Open was successful<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, it prints &#8220;open was successful&#8221; here, as shown in Figure 5.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And this is a block where it does reading. We are going to attempt reading twice. Here is a read API.&nbsp;<\/span><\/p>\n<figure id=\"attachment_9212\" aria-describedby=\"caption-attachment-9212\" style=\"width: 781px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9212\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-6-13.png\" alt=\"Figure 6. Code block\" width=\"781\" height=\"387\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-13.png 781w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-13-300x149.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-13-768x381.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-13-600x297.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-13-120x59.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-13-500x248.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-13-200x99.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-13-400x198.png 400w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><figcaption id=\"caption-attachment-9212\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. Code block<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s just explore this read.<\/span><\/p>\n<figure id=\"attachment_9213\" aria-describedby=\"caption-attachment-9213\" style=\"width: 781px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9213\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-7-12.png\" alt=\"Figure 7. Read method\" width=\"781\" height=\"394\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-12.png 781w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-12-300x151.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-12-768x387.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-12-600x303.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-12-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-12-500x252.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-12-540x272.png 540w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-12-200x101.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-12-400x202.png 400w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><figcaption id=\"caption-attachment-9213\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. Read method<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Read from file descriptor, and it takes these 3 arguments (shown in Figure 7). The fd, which you got from open and this, is a place to give your user buffer pointer, and this is how many bytes you want to read.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_9214\" aria-describedby=\"caption-attachment-9214\" style=\"width: 778px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9214\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-8-12.png\" alt=\"Figure 8. Read method\" width=\"778\" height=\"389\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-12.png 778w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-12-300x150.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-12-768x384.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-12-600x300.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-12-120x60.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-12-500x250.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-12-200x100.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-12-400x200.png 400w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><figcaption id=\"caption-attachment-9214\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. Read method<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Remember that, on success, this read can return either 0 or a positive value. On success, the number of bytes read is returned. If it is 0, then that indicates end of file, and the file position is advanced by this number.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">It is not an error if this number is smaller than the number of bytes requested.&nbsp;<\/span><span style=\"font-weight: 400;\">This may happen, for example, because fewer bytes are actually available right now. The read system call may also return negative value. If it is negative value, then that could be because of these reasons. So, read returns 0 or a positive value or a negative value.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">That&#8217;s why I&#8217;m checking for all those conditions. If it is 0, then I just print this is end of file, and I just break this loop. And if return is negative, then something went wrong. I just break. If the return is positive, then this block will get executed, as shown in Figure 9.<\/span><\/p>\n<figure id=\"attachment_9215\" aria-describedby=\"caption-attachment-9215\" style=\"width: 780px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9215\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-9-10.png\" alt=\"Figure 9. If the return is positive\" width=\"780\" height=\"395\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-10.png 780w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-10-300x152.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-10-768x389.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-10-600x304.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-10-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-10-500x253.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-10-540x272.png 540w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-10-200x101.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-10-400x203.png 400w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><figcaption id=\"caption-attachment-9215\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. If the return is positive<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s see how we use read here (shown in Figure 10).<\/span><\/p>\n<figure id=\"attachment_9216\" aria-describedby=\"caption-attachment-9216\" style=\"width: 857px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9216\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-10-8.png\" alt=\"Figure 10. Read data from \u2018fd\u2019\" width=\"857\" height=\"442\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-8.png 857w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-8-300x155.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-8-768x396.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-8-600x309.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-8-120x62.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-8-500x258.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-8-200x103.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-8-400x206.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-8-800x413.png 800w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><figcaption id=\"caption-attachment-9216\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Read data from \u2018fd\u2019<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">First of all, I give fd here and the buffer address. This buffer is traced&nbsp;<\/span><span style=\"font-weight: 400;\">by this variable total_read. So, this total_read is initially 0.&nbsp;<\/span><span style=\"font-weight: 400;\">That means we start from the beginning.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This(total_read) variable actually holds count of total number of data bytes read so far. Initially, it is 0. And the remaining variable holds the remaining data bytes to be read.&nbsp; Initially, it is(remaining) initialized to this(TRY_READ) value.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">It is(TRY_READ is now 10. That means this program wants to read 10 bytes of data. That&#8217;s why the remaining is initially set to 10. So, the remaining is used as a count here.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s say, you execute this(ret=read (fd,&amp;buffer[total_read], remaining) system call and it returns 5. Let&#8217;s say 5 is less than remaining. That&#8217;s why the total_read is incremented by 5. Remaining is decremented by 5, and this logic again tries to read one more time.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">That&#8217;s why n != 2, and the<\/span><b> remaining<\/b><span style=\"font-weight: 400;\"> shouldn&#8217;t be 0. If <\/span><b>remaining<\/b><span style=\"font-weight: 400;\"> becomes 0, then there is nothing to read. This while loop breaks. I hope you get this. So, it tries to read one more time.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, it just dumps the buffer here (as shown in Figure 11).<\/span><\/p>\n<figure id=\"attachment_9217\" aria-describedby=\"caption-attachment-9217\" style=\"width: 857px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9217\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-11-8.png\" alt=\"Figure 11. Dumps buffer\" width=\"857\" height=\"420\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-8.png 857w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-8-300x147.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-8-768x376.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-8-600x294.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-8-120x59.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-8-500x245.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-8-200x98.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-8-400x196.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-8-800x392.png 800w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><figcaption id=\"caption-attachment-9217\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 11. Dumps buffer<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Let&#8217;s try this. Download this code and just compile that with gcc, &nbsp; -o.&nbsp;<\/span><span style=\"font-weight: 400;\">Let me give the name dev_read.<\/span><\/span><\/p>\n<figure id=\"attachment_9218\" aria-describedby=\"caption-attachment-9218\" style=\"width: 857px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9218\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-12-8.png\" alt=\"Figure 12. Compile the code with gcc\" width=\"857\" height=\"463\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-8.png 857w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-8-300x162.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-8-768x415.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-8-600x324.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-8-120x65.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-8-500x270.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-8-200x108.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-8-400x216.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-8-800x432.png 800w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><figcaption id=\"caption-attachment-9218\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 12. Compile the code with gcc<\/span><\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Before testing this, let me use the echo command to put some data into the pcdev-3. I copy some data. I paste here. And let&#8217;s put this in \/dev pcdev-3.<\/span><\/p>\n<figure id=\"attachment_9219\" aria-describedby=\"caption-attachment-9219\" style=\"width: 857px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9219\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-13-7.png\" alt=\"Figure 13. Putting some data in \/dev\/pcdev-3 using echo command\" width=\"857\" height=\"437\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-7.png 857w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-7-300x153.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-7-768x392.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-7-600x306.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-7-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-7-500x255.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-7-200x102.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-7-400x204.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-13-7-800x408.png 800w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><figcaption id=\"caption-attachment-9219\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 13. Putting some data in \/dev\/pcdev-3 using echo command<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s do dmesg| tail as shown in Figure 14.<\/span><\/p>\n<figure id=\"attachment_9220\" aria-describedby=\"caption-attachment-9220\" style=\"width: 856px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9220\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-14-6.png\" alt=\"Figure 14. Dmesg | tail logs\" width=\"856\" height=\"437\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-14-6.png 856w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-14-6-300x153.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-14-6-768x392.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-14-6-600x306.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-14-6-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-14-6-500x255.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-14-6-200x102.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-14-6-400x204.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-14-6-800x408.png 800w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><figcaption id=\"caption-attachment-9220\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 14. Dmesg | tail logs<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You can see that we actually wrote 479 bytes.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s execute&nbsp; \/devread.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, you can see that we actually read 10 bytes of data. So, our application read 10 bytes of data from this device file.<\/span><\/p>\n<figure id=\"attachment_9221\" aria-describedby=\"caption-attachment-9221\" style=\"width: 858px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9221\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-15-5.png\" alt=\"Figure 15. .\/devread\" width=\"858\" height=\"438\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-15-5.png 858w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-15-5-300x153.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-15-5-768x392.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-15-5-600x306.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-15-5-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-15-5-500x255.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-15-5-200x102.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-15-5-400x204.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-15-5-800x408.png 800w\" sizes=\"(max-width: 858px) 100vw, 858px\" \/><figcaption id=\"caption-attachment-9221\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 15. .\/devread<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, now let&#8217;s edit this code to get the read count via the command line.<\/span><\/p>\n<figure id=\"attachment_9222\" aria-describedby=\"caption-attachment-9222\" style=\"width: 854px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9222\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-16-4.png\" alt=\"Figure 16. Edit the code to get the read count via command line\" width=\"854\" height=\"436\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-16-4.png 854w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-16-4-300x153.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-16-4-768x392.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-16-4-600x306.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-16-4-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-16-4-500x255.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-16-4-200x102.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-16-4-400x204.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-16-4-800x408.png 800w\" sizes=\"(max-width: 854px) 100vw, 854px\" \/><figcaption id=\"caption-attachment-9222\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 16. Edit the code to get the read count via command line<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s make use of the command line arguments. So, that&#8217;s why let&#8217;s edit this main arguments as int argc, and the second argument is argv.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Here, let&#8217;s just test a if(argc !=2), then let&#8217;s conclude that it&#8217;s wrong usage. Printf&nbsp;<\/span><span style=\"font-weight: 400;\">&#8220;wrong usage&#8221;. Usage is you have to execute the file with the read count.&nbsp;<\/span><span style=\"font-weight: 400;\">So, goto out. That means you have to execute this program with a readcount value.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And now, let&#8217;s extract the read count from this a argv pointer variable, as shown in Figure 17.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Basically, it contains a string data. The argv actually contains the string data.&nbsp;<\/span><span style=\"font-weight: 400;\">That&#8217;s why we have to use atoi. (ASCII to integer) of&nbsp; argv1. Remaining is equal to. Let me just print the initial value of a remaining.<\/span><\/span><\/p>\n<figure id=\"attachment_9223\" aria-describedby=\"caption-attachment-9223\" style=\"width: 782px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9223\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-17-5.png\" alt=\"Figure 17. Extracting the read count\" width=\"782\" height=\"397\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-17-5.png 782w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-17-5-300x152.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-17-5-768x390.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-17-5-600x305.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-17-5-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-17-5-500x254.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-17-5-200x102.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-17-5-400x203.png 400w\" sizes=\"(max-width: 782px) 100vw, 782px\" \/><figcaption id=\"caption-attachment-9223\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 17. Extracting the read count<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">For this atoi standard library call, you have to include stdlib.h. Let&#8217;s include that. <\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s compile, and let&#8217;s execute. So, here it is. It&#8217;s a wrong usage.<\/span><\/p>\n<figure id=\"attachment_9224\" aria-describedby=\"caption-attachment-9224\" style=\"width: 781px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9224\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-18-5.png\" alt=\"Figure 18. Executing .\/devread\" width=\"781\" height=\"398\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-18-5.png 781w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-18-5-300x153.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-18-5-768x391.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-18-5-600x306.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-18-5-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-18-5-500x255.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-18-5-200x102.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-18-5-400x204.png 400w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><figcaption id=\"caption-attachment-9224\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 18. Executing .\/devread<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_9225\" aria-describedby=\"caption-attachment-9225\" style=\"width: 781px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9225\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-19-3.png\" alt=\"Figure 19. Executing .\/devread for 10 bytes\" width=\"781\" height=\"396\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-19-3.png 781w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-19-3-300x152.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-19-3-768x389.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-19-3-600x304.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-19-3-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-19-3-500x254.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-19-3-200x101.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-19-3-400x203.png 400w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><figcaption id=\"caption-attachment-9225\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 19. Executing .\/devread for 10 bytes<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s execute with 10, as shown in Figure 19. Read requested is 10, open was successful, read 10 bytes of data. This is a data.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s request for 10000 bytes, as shown in Figure 20, and here it is. Read requested 10000 bytes. But, the first read actually got only 1024, because our device has limitations. And that&#8217;s why our program again tried for reading some data, but it got zero.<\/span><\/p>\n<figure id=\"attachment_9226\" aria-describedby=\"caption-attachment-9226\" style=\"width: 778px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9226\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-20-3.png\" alt=\"Figure 20. Executing .\/devread for 10000 bytes\" width=\"778\" height=\"393\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-20-3.png 778w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-20-3-300x152.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-20-3-768x388.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-20-3-600x303.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-20-3-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-20-3-500x253.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-20-3-540x272.png 540w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-20-3-200x101.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-20-3-400x202.png 400w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><figcaption id=\"caption-attachment-9226\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 20. Executing .\/devread for 10000 bytes<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">It printed end of file. That&#8217;s why the total_read was 1024, and this was the data.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Check the dmesg(shown in Figure 21).<\/span><\/p>\n<figure id=\"attachment_9227\" aria-describedby=\"caption-attachment-9227\" style=\"width: 778px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9227\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-21-3.png\" alt=\"Figure 21. Dmesg | tail logs\" width=\"778\" height=\"398\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-21-3.png 778w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-21-3-300x153.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-21-3-768x393.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-21-3-600x307.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-21-3-120x61.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-21-3-500x256.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-21-3-200x102.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-21-3-400x205.png 400w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><figcaption id=\"caption-attachment-9227\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 21. Dmesg | tail logs<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here you can see that the open was successful, and our application requested for 10000 bytes. But the successfully read data was 1024 and you can see that, our application again&nbsp; requested for&nbsp; 8976&nbsp; bytes. That was read executing for the second time.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Since there is nothing to read from the device, our driver does return zero.&nbsp;<\/span><span style=\"font-weight: 400;\">That&#8217;s a reason why our application printed here end of file, then our application closed the file. So, the release was successful.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">I have mentioned the link to download this application at the beginning of this article, try to download it and a test your driver what you have written, and let me know if you have any questions. I&#8217;ll see you in the next article.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\">lick here:&nbsp;&nbsp;<\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Pcd driver with multiple devices testing contd &nbsp; &nbsp; In this article, Please download and open the file from this link: https:\/\/drive.google.com\/file\/d\/1toWCdzLVCDoyOGyhD17vVnMfAl-JDzNE\/view?usp=sharing &nbsp; I&#8217;m going to explain that program now. The file name is&nbsp; dev_read.c.&nbsp;This is a very simple program to open and read data from the device file. &nbsp; Let me explain this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9209,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[18],"class_list":["post-9204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-linux-device-driver-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd<\/title>\n<meta name=\"description\" content=\"Pcd driver with multiple devices testing contd.The file name is\u00a0 dev_read.c.\u00a0This is a very simple program to open and read data from the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd\" \/>\n<meta property=\"og:description\" content=\"Pcd driver with multiple devices testing contd.The file name is\u00a0 dev_read.c.\u00a0This is a very simple program to open and read data from the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-19T06:04:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-16T09:52:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13.png\" \/>\n\t<meta property=\"og:image:width\" content=\"779\" \/>\n\t<meta property=\"og:image:height\" content=\"394\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd\",\"datePublished\":\"2022-04-19T06:04:15+00:00\",\"dateModified\":\"2023-01-16T09:52:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/\"},\"wordCount\":1542,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-3-13.png\",\"keywords\":[\"Linux Device Driver Programming Tutorial\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/\",\"name\":\"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-3-13.png\",\"datePublished\":\"2022-04-19T06:04:15+00:00\",\"dateModified\":\"2023-01-16T09:52:31+00:00\",\"description\":\"Pcd driver with multiple devices testing contd.The file name is\u00a0 dev_read.c.\u00a0This is a very simple program to open and read data from the\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-3-13.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-3-13.png\",\"width\":779,\"height\":394,\"caption\":\"Figure 3. Error checking\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd","description":"Pcd driver with multiple devices testing contd.The file name is\u00a0 dev_read.c.\u00a0This is a very simple program to open and read data from the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/","og_locale":"en_US","og_type":"article","og_title":"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd","og_description":"Pcd driver with multiple devices testing contd.The file name is\u00a0 dev_read.c.\u00a0This is a very simple program to open and read data from the","og_url":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-04-19T06:04:15+00:00","article_modified_time":"2023-01-16T09:52:31+00:00","og_image":[{"width":779,"height":394,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd","datePublished":"2022-04-19T06:04:15+00:00","dateModified":"2023-01-16T09:52:31+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/"},"wordCount":1542,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13.png","keywords":["Linux Device Driver Programming Tutorial"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/","url":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/","name":"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13.png","datePublished":"2022-04-19T06:04:15+00:00","dateModified":"2023-01-16T09:52:31+00:00","description":"Pcd driver with multiple devices testing contd.The file name is\u00a0 dev_read.c.\u00a0This is a very simple program to open and read data from the","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-13.png","width":779,"height":394,"caption":"Figure 3. Error checking"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-57-pcd-driver-with-multiple-devices-testing-contd\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Linux Device Driver Programming Lecture 57| Pcd driver with multiple devices testing contd"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/9204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=9204"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/9204\/revisions"}],"predecessor-version":[{"id":13636,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/9204\/revisions\/13636"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/9209"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=9204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=9204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=9204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}