Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 19440  / 2 Years ago, sat, october 1, 2022, 11:13:20

I have been writing an application in C++ that transmits radio messages by writing to a modem connected to the serial port. To do this I need to get a file descriptor using code of the form



fd1=open(“/dev/ttyS0″, O_RDWR | O_NOCTTY | O_NDELAY);


This made me curious about the nature of the items in /dev. To try to get an idea of the contents of these items I tried a



sudo cat /dev/ttyS0


only to get the message



cat: /dev/ttyS0: Input/output error


which didn't help my understanding at all. Are these items actually a file at all or just a kind of link that allows access to the driver functionality?


More From » drivers

 Answers
0

Everything in Linux is a file or a directory. Things in /dev are special files.



The majority of devices are either block or character devices; however other types of devices exist and can be created. In general, 'block devices' are devices that store or hold data, 'character devices' can be thought of as devices that transmit or transfer data. For example, diskette drives, hard drives and CD-ROM drives are all block devices while serial ports, mice and parallel printer ports are all character devices. There is a naming scheme of sorts but in the vast majority of cases these are completely illogical.



Devices are defined by type, such as 'block' or 'character', and 'major' and 'minor' number. The major number is used to categorize a device and the minor number is used to identify a specific device type. For example, all IDE device connected to the primary controller have a major number of 3. Master and slave devices, as well as individual partitions are further defined by the use of minor numbers.



Taken from Linux-Filesystem-Hierarchy






2 options:




  1. Try



     cat < /dev/ttyS0


    and see if that works.


  2. You might solve this error by adding your user to the same group (ie. dialout).



[#36765] Saturday, October 1, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nstitutencert

Total Points: 171
Total Questions: 126
Total Answers: 124

Location: Azerbaijan
Member since Fri, May 12, 2023
1 Year ago
;