Serial Port Question

Discussion to talk about software related topics only.
Post Reply
Vernon
Posts: 177
Joined: Sat Oct 10, 2009 6:33 pm

Serial Port Question

Post by Vernon »

SerialClose(1);
fdserial = OpenSerial(1, 9600, 1 ,8, eParityNone);
SerialClose(0);
ffserial = OpenSerial(0, 115200, 1 ,8, eParityNone);

ReplaceStdio( 0, ffserial ); // stdin
ReplaceStdio( 1, fdserial ); // stdout
ReplaceStdio( 2, ffserial ); // stderr

I have the above. Is it possible to read from a port when it is not the stdio?

Thanks!
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Serial Port Question

Post by rnixon »

Absolutely. I think the normal mode for any type of data port is to read/write directly. I only use stdio for debugging in release mode or status messages on a debug serial port.
sblair
Posts: 162
Joined: Mon Sep 12, 2011 1:54 pm

Re: Serial Port Question

Post by sblair »

Yes you can read/write to any serial port that you have opened an fd to regardless of the stdio settings. I use multiple serial ports all the time.

Scott
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: Serial Port Question

Post by pbreed »

functions are read
and write

read the header file

nburn\include\iosys.h



int read(int fd ,char * buf, int maxlen);
Where fd is the fd gotten from the serial open...
reads what is availible and returns.
If no data is availible it blocks until it gets at least one charactor...

If you need timeouts..
int ReadWithTimeout( int fd, char *buf, int nbytes, unsigned long timeout );


int write(int fd, const char * buf, int len);
Post Reply