Hey ppl,
I'm doing a project which needs serial communication. I'm sending and receiving data from a PIC through the serial port. I'm using Windows XP and dev cpp.
I'm succesfully sending data by my program to the PIC. I'm using inpout32.dll file to access serial port because windows dosen't give direct access to those ports.
The problem occurs when reading the data I get from the PIC. I need to read 30 characters sent by the PIC, but I couldn't do it by my program. But I get all that data to hyperterminal.
So is there any syntax or header file in c to read data from serial port????

There is no standard library functions in C for serial port access because it is too platform dependent.

The Win32 API does support serial ort access however mildly confusingly you have to use CreateFile to open a serial port and ReadFile and WriteFile to read and write data to it.

There are a bunch of specific comfiguration and tuning functions reference available here.

hey,
I'm new to this serial port programming thing and I don't understand how i should use these functions in my c program.
can u two give me a simple example c program using these functions 4 me to figure out how to use these functions???

It is no trivial thing to do. Read the link I posted because it contains a few examples.
1) call CreateFile() to open the port
2) Set the port configuration (data bits, stop, bits, parity)
3) Check if anything is at the port, it there is then call ReadFile() to read it. If you use overlapped mode MS-Windows will call your function when data is available at the port.

That is all explained in the link I posted above. Study it carefully.

Edited 6 Years Ago by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.