#include <windows.h>
#include <stdio.h>
int main( int argc, char **argv )
{
HANDLE hSerial = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if (hSerial == INVALID_HANDLE_VALUE)
{
printf("Error opening port\r\n");
return -1;
}
char c;
DWORD dwBytesWrite = 0;
printf("<-: ");
do
{
if(!ReadFile(hSerial, &c, 1, &dwBytesWrite, NULL))
{
printf("read error\r\n");
return 1;
}
putc(c, stdout);
}
while(c != '\n');
char buf[] = ":r50=1,118,2662,0,155999,313968,824811,1390507,124,0,0,0,31396,3030,\r\n";
if(!WriteFile(hSerial, buf, sizeof(buf) - 1, &dwBytesWrite, NULL))
{
printf("write error\r\n");
return 2;
}
printf("->: %s", buf);
CloseHandle(hSerial);
return 0;
}