Serial Port Access

Hi all, happy new year.

I am to connect a serial device to my serial port and access it (reading only). What is the set of commands (opening, reading, seeking)? Why is it not visible in /dev directory? What name will I see for the port when it becomes visible?

Thanks

Oh, I forgot, I need of course the means of controling the device properties (baud rate, parity, etc.) in order to be able to use the device, as well as the commands mentioned above.

Many thanks.

Could you explain what your device is. Serial port usually appear under /dev/ser1, /dev/ser2 etc. You can rarw send/receive data to it with open/read/write/close. As for devices connected to it, in order to appear under /dev they would need a driver and I’m not aware of any such driver on QNX6.

You probably need a custom driver.

I’m not aware of any OS that will actually scan the serial port for device detection. Unlike USB, serial port doesn’t have what it takes to support plug and play.

Hi again. Thanks for replying, Mario.
To clarify - I have to read from a device connected to the serial port and transmitting at 9600 Hzzzzzzzzz :slight_smile:
I was able to see data on the hyper terminal when running Windows on the same machine. When running QNX, I’m able to read data, but it is all -32 and 0 charcters. This is clearly not the data transmitted. I configured the port as shown below:
termios_p.c_cflag |= CS8; // 8 data bits
termios_p.c_cflag &=~CSTOPB; // 1 stop
termios_p.c_cflag &=~PARENB; // no parity

termios_p.c_cflag &=~IHFLOW; //no flow control
termios_p.c_cflag &=~OHFLOW; //no flow control

termios_p.c_cflag |= CLOCAL | CREAD; // ignore modem and enable receive

termios_p.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //raw;

termios_p.c_iflag &= ~(IXON | IXOFF); // no sw flow control

termios_p.c_oflag &= ~OPOST; // raw
//////////////////////////////////////////

tcsetattr(fd, TCSANOW, &termios_p);

speed = B9600;
cfsetispeed(&termios_p, speed);

Any ideas why the input is so boring?
Further more, when I read too fast, i.e. trying to read when the input buffer is empty, I get the appropriate answer - read less than expected, or -1. If I try reading again from the port I get blocked forever. If I run the driver again (devc-ser8250) from a different shell, I’m clear of that and can read again. I’m not using interrupts, as you can understand.

Cheers

You should do a tcgetattr(), then modify the termios struture to your liking and the do tcsetattr()

Try using qtalk (equivalent of hypertype) to check QNX is ok.

Maybe posting the code that open/read the serial port would help because I can’t figure out what you may be doing wrong.

Hi all.

Mario, thanks a million for the advise regarding the Qtalk application. I was able to read the input correctly after setting the attributes.
What I noticed then was that the attributes settings I perform in my application does not take effect. That means that everytime I run the application, although setting the attributes, it runs with the ones I used in the qtalk just before. Here is the whole attributes setting code. I will be grateful if you can spot the mistake:

fd = open("/dev/ser1", O_RDONLY);

tcgetattr(fd, &termios_p);

/*

 *    Set attributes

 */

termios_p.c_cflag &= ~CSIZE; // interesting (=CS8)

termios_p.c_cflag |= CS8; // 8 data bits

termios_p.c_cflag &=~CSTOPB; // 1 stop

termios_p.c_cflag &=~PARENB; // no parity

termios_p.c_cflag &=~IHFLOW; //no flow control

termios_p.c_cflag &=~OHFLOW; //no flow control

termios_p.c_cflag |= CLOCAL | CREAD; // ignore modem and enable receive

termios_p.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //raw;

termios_p.c_iflag &= ~(IXON | IXOFF); // no sw flow control

termios_p.c_oflag &= ~OPOST; // raw

speed = 9600;

cfsetispeed(&termios_p, speed);

tcsetattr(fd, TCSANOW, &termios_p);

Cheers,

Amirey

Found it, finally. One has to open the file (port) in read/write mode if it’s going to change the attributes, of course.
One quick note - I ran into something I haven’t seen any remark about. When oyu change the attributes you may have already some data received in the input buffer (or FIFO, or whatever). This data was received with the old attributes affecting it. That means it might be corrupted. To get rid of that, call tcsetattr(fd, TCSAFLUSH, &termios_p), with TCSAFLUSH, and then the input buffer is flushed. It is not relevant if the transmission is synchronized of course.
One last note - When I called tcsetattr, with the port opened as read-only, the call should have failed (returning -1). It did not, and I assumed the fault is somewhere else. Any ideas why it’s not failing?

i encounter the same problem too…my program hang at “tcsetattr”. is it because i’m in super user (su) mode? i tried at other serial ports and working fine. Only at one port gives me problem. Any reason why it halts at “tcsetattr”? Thanks!

Bryan