serial port control

Hello!

I am a beginner in using qnx system, so sorry my simlpy questions!

I show my task with a very simply example:

I want to read some characters or numbers from serial port (from another hardware), and after some transformation (adding, multiplying ect.) I want to write it back to the serial port.

How can i make this work?
Is there any software which i can program the serial port with?
Are there any books about this topic?

Thank you

fd = open( “/dev/ser1” );
read(…);
write(…);
close(fd);

Maybe there’s a simpler solution, but the one I know is to create a c code and compile it. You can use ‘open’, ‘close’, ‘read’, ‘write’ for managing the serial port, and some other commands and structures (take a look at termios, tcgetattr, tcsetattr, setispeed, setospeed…) to configure it.

There’s a chapter about this topic in Posix Programmers Guide. I think it was around page 153.

Quick question:

I wrote the following snippet of code to test reading from the serial port:

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <fcntl.h>

using namespace std;

int main()
{ 
    int fd;
    int numRead;
    char buffer[255];
    
    fd = open("/dev/ser1", O_RDONLY);
	
    while(1)
    {
        memset(buffer, 0, sizeof(buffer));

        numRead = read(fd, buffer, sizeof(buffer));
        cout << "Read in " << numRead << " characters from serial port." << endl;
        cout << "Buffer is <" << buffer << ">" << endl;
    }
   
    return 0;
}

I attached a serial mouse to my serial port, ran the program and moved the mouse and I see nothing displayed to the screen.

Looking in /dev I see /dev/ser1 and the 8250 driver is started and running obviously (from pidin).

So from the command prompt I typed:

cat < dev/ser1

moved the mouse and again nothing.

Now on older PC hardware (very old hardware) doing that cat command with the same serial mouse displays characters when I move the mouse.

So since I don’t see anything on my current system does that mean I have some kind of hardware incompatible serial chip on my MB?

The box is a Dell GS 280 and from Windows the device manager reports it as an Intel 82801 chip set. I don’t see any driver that resembles this anyplace.

Is there any way to tell what kind of chipset is supported on this machine?

TIA,

Tim

A mouse runs at 1200 baud i beleive. You may also have to set the serial port to no flowcontrol (look at command line utility stty)

Mario,

Setting the baud rate to 1200 didn’t work. But once I turned off all the flow control it started to function just fine.

I guess the old hardware PC I have (about 8 years old) must be just different enough or old enough that it works with the defaults.

Thanks,

Tim

easysw.com/~mike/serial/serial.html

Hi!

I have another problem. Now I can write the serial port, but only with characters and strings. (e.g. n=write(fd, “stringr”,4):wink:

How can I write to the serial port a decimal number? Or a Hexadecimal?

Thanks!

One way could be:

char * pc;
double dec_number;
int i;

dec_number=2.3695;

pc=(char*)&dec_number;
i=0;
while(i<8)
i+=write(fd,pc+i,8-i);