PC serial port communication program samples


Can I get sample code of PC serial port communication in qnx 6.2 .



char *outmsg=“Out the serial port”;
char inmsg[80];

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

/* write out the serial port */
write(fd, outmsg, strlen(outmsg);

/* read from the serial port */
read(fd, inmsg, sizeof(inmsg));


Thank you for the reply.

when I tried this source snippets, I am receiving alternate characters only.

can you suggest what i could do?


Sounds like something else might be reading the port as well?

Hello CDM

you are correct.

We could locate the problem. when this program was tried in com port 1 which was use for mouse, the com
port was read by both this program as well as the mouse program.

When we run this proram after the mouse had been removed and restarted the PC, it was working fine.

Thank you.

The QNX self hosted PC is having two com ports. Com1 is used for mouse. When I try to setup or open the
com port 2, error msg is coming. /dev/ser2 is not available. How do I configure com port2?


What is the output of “pidin -p devc-ser8250 ar”?

Hello CDM

In BIOS setup, com port2 was disabeled. After enable the com port2, it is working fine.

However, whenever we receive some msg in this com port using a phton application, the pc response for all the commands becomes slow.

what would be the reason?


thanks,but I hope read and write serial port by interrupt model,Can I get sample code of PC serial port communication in qnx

Unless you really have to, avoid using interrupt. Use the driver instead, it has numerous advantages:

  • Code is portable
  • Doesn’t have to be run as root
  • Much easier to debug
  • Could be use on any type of serial device (even serial over IP)
  • Can user serial port of another machine via network transparately (this feature alone is worth it, it saved my ass a couple of time)

If you want to use interrupt model, and have no idea how, that is an argument againt using it. First check documentation of serial port hardware, then check documentation of InterruptAttach/InterrupAttachEvent.

90% of the code will not be QNX related so look on the web for sample of serial port stuff.