Access to USB port

GEphil's picture

Forums: 

I am new to Debian Linux, but have previous UNIX experience - mainly as a toolmaker whose products were programs used by other engineers but that was during the mid 1980s.

My colleague installed Debian Linux 2.6 on an ordinary desktop PC not long ago, and I made a test program using gnu C which communicates with my employer's hardware device over an RS485 bus, using a USB-RS485 converter between a USB port and the device. For the purposes of this enquiry I don't think the protocol is important, other than to note that I need the port speed=57600, 8 data bits, 1 stop bit.

I used stty -F /dev/ttyUSB0 57600 raw -cstopb to achieve this. To access the port, I was doing an fopen("/dev/ttyUSB0","r+"), following which I was able to fwrite messages to the port, and fread the replies back. If no reply was available, fread would return 0. On exit the program would fclose the port.

Last week, this was working Smile

BTW I had also done a chmod 666 /dev/ttyUSB0 to let my program access the port.

Since then, the PC has been rebooted. The port config has been lost, which shouldn't be a trouble, because I can use stty and chmod as before ...

... but now, my program hangs when I do the fread. I have seen the Tx and Rx leds on the USB-RS485 converter flash so I believe I sent a message, and the device replied.

I'm beginning to think there was something else I might have done to /dev/ttyUSB0, which I've since forgotten about.

Can't say I've seen threads on similar subject, but I apologise if there is one which I've missed.

EDIT: If I have the data that I wish to be transmitted stored in a file, I am able to

cat file > /dev/ttyUSB0

which causes the device to generate its response, so I can

cat /dev/ttyUSB0 > responsefile

and examine its contents with an appropriate tool (none of this stuff is man-readable btw). So I'm convinced there's something I'm missing about the way in which Linux has been told that a user program is wanting to access /dev/ttyUSB0.

I tried the open/read/write

GEphil's picture

I tried the open/read/write/close family of syscalls instead of the fopen/fread/fwrite/fclose family of library routines. The program works Smile