Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


port control in watcom c/c++ under QNX

Posted on 1997-05-13
Medium Priority
Last Modified: 2010-08-05
I am trying to modify a program written in Watcom c/c++ under QNX 4. I want to let it communicate with another computer using serial port. So far I have just found functions like outp(), outw() to access the hardware,
but to communicate successfully one needs to specify the Baud rate, number of data bits, etc. Is there any function in Watcom c/c++ to do that? I couldn`t find the version of which I am using, I just know its accompanied manuals
were written in 1993. Thanks in advance
Question by:zhao040597
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 1250357
Specifying baud rate etc is a function of the serial device. This device can be programmed by writing to its output control ports using outp() and outw(). All you need to know is the port number and the specification for the device.


Accepted Solution

claudeb earned 270 total points
ID: 1250358
The following is from some code I wrote under QNX 4.2 for a communications program.  You should be able to get the info you need from this.  Also, take a look at the code for the qtalk program (you can get the source off the QNX ftp site).

int       CommPort;
char      PollPort;

strcpy(PollPort, "/dev/ser3");

/* Open the serial port */
if((CommPort = open(PollPort, O_RDWR)) == -1)
  /* Can't open port! */
  printf("Unable to open port '%s'", PollPort);

/* Set device to RAW mode */
if(dev_mode(CommPort, 0, _DEV_MODES) == -1)
  /* Can't set RAW mode on port */
  printf("Unable to set RAW mode on port.");

/* Drop DTR */
tcdropline(Port, 2000);
tcflush(Port, TCIOFLUSH);

/* Read something form port */
int Read_Data(int Chars, int Timeout, unsigned char *buf)
  int i, n = 0;
  unsigned char c;

  /* Return number of characters waiting? */
  if(!Chars) return(dev_ischars(CommPort));

  if(Chars > 0)
    while(Chars && (i = dev_read(CommPort, buf, Chars, Chars, 0,       Timeout, 0, 0)))
      if(i == -1)
        perror("Read_Data() get -1!");
        *buf = NAK;
      buf += i;
      Chars -= i;
      n += i;
    /* Read until I get a '\r' or a timeout */
    while((i = dev_read(CommPort, &c, 1, 1, 0, Timeout, 0, 0)))
      if(i == -1)
         perror("Read_Data() got -1");
         *buf = NAK;
      if(c == '\r') return(n);
      *buf = c;
      buf += i;
      n += i;

/* Send some data */
int Send_Data(char *Data, int Size, int WaitFor)
  int  i;
  unsigned char      c;

  if(Size == 0) Size = strlen(Data);
  /* Send data to port */
  write(CommPort, Data, Size);

  /* Do I need to wait for something? */
  if(WaitFor == NULL) return(TRUE);
    i = Read_Data(1, 100, &c);
  } while(i != 0 && c != WaitFor && c != NAK);
  return(c == WaitFor ? TRUE : FALSE);


Author Comment

ID: 1250359
Thanks for your answer.

But first, is this written in Watcom c/c++?
Second, what header file should I include?
Third, the serial ports of the two computers are 9-pin, and I connected them in this way:
        a            b
       4(DTR)          4(DTR)
       |               |
       |               |
       6(DSR)          6(DSR)
       7(RTS)          7(RTS)
       |               |
       |               |
       8(CTS)          8(CTS)

In this way, I have no problem to use Qbasic to communicate with each other(send and receive), but do you think your program will work in this way of connection? (Both computers are PC)

Since I just have some basic knowledge of c and totally unfamiliar with QNX, I want to make sure it should works before I look through a whole bunch of manuals.

Thank you.

Expert Comment

ID: 1250360
Yes, it was written under QNX using Watcom C 10.6.  The header files you'll need are:

#include <sys/dev.h>
#include <sys/kernel.h>
#include <sys/types.h>
#include <sys/qioctl.h>

I think those should do.  As far as your cable goes, it will work ONLY if you have XON/XOFF flow control.  You need a proper null modem cable which (I think) should be:


Hope this helps!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question