Can't set serial port configuration in Linux in C
Hello.
I have writen some Linux program to comunicate my device. I have "same" my program for Windows ("same" because of it's same logic). I'm using 8N2 data frame format @ 9600 bps, with neither software (XOn/XOff) nor hardware (RTS/CTS) flow control. I don't use DTR, DCD, RI, DSR pins of RS-232 9-pin D-sub. I use only RX and TX pins to communicate with my device. In Linux I have this part of code: Code:
struct termios PortOpts, result; I get that message: **While configuring port2: Input/output error** I have a laptop, though I don't have any serial ports except for USB. Is this a reason? I run program as 'root'. Sorry for my broken English. |
Are you saying you do not have an old fashioned serial port but a USB virtualcom port (VCP) or (CDC class as it's sometimes called)?
If so, that would be: /dev/ttyUSBx or /dev/ttyACMx Where x is a number. If you search in dev for those files you will hopefully find one. You shouldn't run as root though really. Make your user member of dialout function and I think that will do you. |
Yes. I don't have the hardware serial port. But I've got the device in my /dev filesystem named /dev/ttyS0 with major and minor numbers 4 and 64 respectively.
I've got only /dev/tty, /dev/tty[0-63], /dev/ttyS[0-3]. I don't have USB virtualcom at hand riht now. But I do need to test the program in Linux. I could try pointing to some terminal but I'm afraid of its unforseen behaviour. UPD: I've added bsome more code (error checking after I retrieve serial port parameters): Code:
if (tcgetattr(fd, &PortOpts) < 0) { |
Yes, I would think the error is because you have no actual com port. Using Cutecom, I can, apparently, open the non-existant /dev/ttyS0 on my laptop, but I get errors on the command line.
You can buy FTDI based cables that have a 9 way D connector on one end and a USB connector on the other. That will give you a serial port, but called /dev/ttyUSBx and it will work perfectly. They're not expensive, only about £15. |
|
Use a terminal emulator such as minicom or C-Kermit to figure out how Linux has mapped device names to your hardware. Loop pins 2 & 3 on the serial port to establish that characters you type are displayed on the terminal emulator.
Once you've established the proper naming, use that in your code. Also, verify that you have permission to perform the operations your code performs. '/dev/ttyWhatever' is not a file descriptor; it is a device name. You haven't shown any code that uses the device name to open the device and create a file descriptor. Have you checked the return value from the open() call? --- rod. |
Quote:
|
All times are GMT -5. The time now is 07:34 AM. |