serial port reading

Hi,

I am a newbie in QNX. Hmm I am encountering a problem with reading from serial port.

I am using a Cool EcoRunner Dual Ethernet PC/104-CPU Board with QNX as the OS. I am using the CPU to control a robot which uses sensors to detect its position. This sensor will pass the readings to the CPU via serial port, RS-232.

But the problem occurs. Here is the sequence of how I read the data.

  1. Open the port using open()
  2. Read the data using read() function (I read many bytes at one time).

However, sometimes, the CPU board stops reading after managed to get a few readings (2-3 readings) from the serial port.

My question are:

  1. Are there anything need to be done to read from a serial port beside opening using open()

  2. I read somewhere in the forum that I need to use threadctl() command to give I/O priority to the program. Err… where should I put this command? is it before open() or after open() but before read()

Any answer is much appreciated.

Thx a lot :smiley:

1, by default the serial port uses hardware handshake. Either you disable it ( check tcsetattr() ) or you setup the proper cabling.
2, threadctl is only required if you directly access the IO port, which you aren’t doing since you are going to POSIX open/read calls.

Hi2, thx for the reply,

yup2, I disabled the handshaking already, I used the termios class to do it. In the program, I used “variable.c_cflag &= ~(IHFLOW|OHFLOW)”
will that do the job?

I also use the termios class to set other settings such as the baudrate, timeout & others.

hmmm so the threadctl will not help eh? hmmm

Thx a lot Mario :smiley:

You may use readcond(), and also set size of IO internal hardware FIFO buffer, by set it when start serial driver (see option for driver).

Hi,

Thx a lot qnxloader. Hmm just wondering, will they give the same performance? I mean, the read() and readcond()? or does readcond() has any advantage over read()?

Just now, I put the threadCtl in the program, now the program can works. In the program, I want to read 10 times from the sensor, and now, sometimes, it can read 10 out of 10. However, sometimes, it also failed to read.

Hmm so confused, are there anything that can render the CPU board to read data from serial port?

Thx

I have same problem, while do not set FIFO (-T4 and -t4 option of driver). By default FIFO is disable and time to time CPU Is not in time to receive data to driver buffer.

Hmm… wah, finally, there is somebody having same problem with me huehehehe :stuck_out_tongue: just kidding. Hmm then, how do you solved it? umm I am sorry, since I am a newbie, I don’t quite get it what you mean by set FIFO (-T4 and -t4 of driver) means. Do I have to set them out?

Is FIFO stands for Flow In Flow Out? which is the IHFLOW and OHFLOW?

Hmmm is your problem solved already? if it is, I really look forward on how you make the CPU always able to read the data.

Just thinking, will handshaking solves this?

Thx

You can not set IO FIFO after driver already started, now you may do like this:
slay devc-ser8250
devc-ser8250 -T4 -t4 -u1 0x3F8,4 &
waitfor /dev/ser1
stty +raw baud=115200 par=none -ihflow -ohflow -isflow -osflow </dev/ser1

read doc for devc-ser8250…

Hi2

Ooooh, so that means the configuration I have done inside the program (the one using termios), will not affect the serial port’s configuration (because the driver is started already)?

oh okay, I will try it tomorrow, coz the sensor is in my lab hehehe. Is it okay if I put the codes inside the bios script? after loading the driver?

Thx a lot :smiley:

It mean the FIFO setting cannot be set, but all the other stuff do work.

Hi,

oh okay, will test it out now. Thx

Hmmm I am sorry for being so blur. I have question about the settings of the devc-ser8250

After looking the details of devc-ser8250 here,
qnx.com/developers/docs/qnx_ … r8250.html
I still don’t get it what the -T uses for.

Then for the -t options, the document says that it is used to set 16550 threshold to 1, 4, 8 or 14 characters. Hmm is this 16550 the UART chip? then is it okay if I just put the highest threshold? 14 in this case? hmmm what does this number represent in the communication of serial port? is it the number of characters can be received for every read/write?

Hmm then the 0x3F8,4, I understand that the 0x3F8 is the address for the serial port, but what about the “4” behind it?

Thx

When you write() data this data send to driver buffer (-I -O option of driver) and then to FIFO(if it ENABLE).

For example -t4 option mean, that serial chipset will trigger interrupt after receive in his FIFO next 4 bytes or after timeout of time, that need to transfer 3/4(i not assure) of byte on current speed.
-T4 mean that data in FIFO will be send out if new portion of data will be 4 bytes or --//-- --//-- 3/4 --//–

-t - for receive in FIFO
-T -for send to FIFO
I don’t tips you to set it to MAX available(14). Set it to 4 or 8. Because the data may not be transfer yet and new portion of data will erase it.

Now simple read/write numbers of byte that you need.
0x3f8,4 - 0x3f8 -port 4- IRQ

The link that you write for QNX 6.1. This is from help for QNX 6.3.0:
-T number
Enable the transmit FIFO and set the number of characters to be
transmitted at each TX interrupt to 1, 4, 8, or 14. The default is 0
(FIFO disabled).
-t number
Enable the receive FIFO and set its threshold to 1, 4, 8, or 14
characters. The default is 0 (trigger disabled).

Woah, thx a lot qnxloader :smiley:

now, if I understand it correctly, if I set -t4, the chipset will only send interrupt telling that it got a new data if it has received 4 bytes from the serial port?

then for -T4, it only sends out new data if it has 4 bytes in it?

then… for FIFO, does it stand for First-In-First-Out queue?

so that means, if I want to get the message as soon as it is received from the device and want to send the message as soon as the CPU passes it, should I just add the -T0 -t0 (disable both) in the devc-ser8250?

Sorry for the trouble.

Thx again :smiley:

oh okay, thx a lot :smiley:

Hi,

wow!!! my problems are solved now, thanks a lot qnxloader, thx a lot mario :smiley: