Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

communication with serial a port

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello,

I would like to know the functions available to write/read... on a port.

thank you!
 
Hi:

What operating system are you using? I have no experience with Windows/DOS, but in unix, everything is treated as a file.

In every case I've seen, you open, read, write, and close serial ports low-level, meaning you don't use the stream functions, fopen, fputs, etc.

Generally, an open is something like:


if ((lpr_fd = open("/dev/serialport", O_RDWR|O_SYNC)) == -1)
{
printf("error opening port\n");
exit(1);
}

Also, it depends on the hardware hooked to your port. Last year, I wrote an article on communicating with unix serial and network devices. Read it here:


Regards,

Ed
 
The linux programmers guide contains examples of how to use a serial port in Linux. There is also a program called miniterm.c which you can compile and use to read/write from/to a serial port. Coupled with this there are two HOWTOS which look at programming serial ports, one is heavily based on the LPG miniterm.c .example.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top