lundi 13 avril 2015

Read from serial port in Windows

I'm trying to read serial data from rs232. My rs232 is connected in comport COM11. I specified COM11 in my serial.h file. below is the code.



void port_open()
{
hSerial =
CreateFile("COM11",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
..


My main c code is



#include <stdio.h>
#include "serial.h"
void main()
{
while(1)
{
port_open();
printf("%s\n",port_read());
}
}


After run the c code, im getting...



serial port does not exist
some other error occured. Inform user.
error getting state
error setting serial port state
error setting port state
error reading from input buffer


--------------------------------
Process exited after 0.4768 seconds with return value 0
Press any key to continue . . .


I think my program cant able to find the comport. How to resolve this? Thanks


Aucun commentaire:

Enregistrer un commentaire