Yes, at home i use VC6 (no ,NET). Current at my work place, i use a new installation of visual studio.NET 2002 Enterprise = VC7
problems complain by the complier,
Could not find HANDLE, DWORD, COMMTIMEOUTS, DCB, GetCommState... so on and so for for the various instant needed to initialise the serial port. I'm puzzled by that because I have added the <Windows.h>. By right that should do the trick. At home it can compile and work. At work place it fails.
Below is part of my code sample. should be easy for u guys.
#include <Windows.h>
#define BUFSIZE 128
int main(int argc, char* argv[])
{
DCB myDCB;
COMMTIMEOUTS myTimeout;
DWORD bytesWritten, commStatus;
HANDLE hcom;
/*Specify the Serial Port to be Used "Com#" Where # is the Port Number*/
char myPort[] = "Com4";
char myData[100];
/*Open Comm Port with Read/Write access, Exclusive Access, No Security, Open Existing
No Overlapping IO, NULL Handler*/
hcom = CreateFile(myPort,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if (hcom == INVALID_HANDLE_VALUE)
{
printf("Serial Port Open Error: %d\n",GetLastError());
return 0;
}
/*Setup Comm Port Input and Output Buffer Size*/
SetupComm(hcom,BUFSIZE,BUFSIZE);
/*Get Default DCB Values and Overwrite Required Values*/
if(GetCommState(hcom,&myDCB)==0)
{
printf("Serial Port Values Unavailable\n");
}
else
{
myDCB.BaudRate = CBR_9600;
myDCB.ByteSize = 8;
myDCB.Parity = NOPARITY;
myDCB.StopBits = ONESTOPBIT;
myDCB.fAbortOnError = TRUE;
myDCB.EofChar = 10;
if(SetCommState(hcom,&myDCB)==0)
{
printf("Unable to write Serial Port Configuration Values\n");
}
else
{
GetCommTimeouts(hcom,&myTimeout);
myTimeout.ReadIntervalTimeout = 50;
myTimeout.ReadTotalTimeoutConstant = 50;
myTimeout.ReadTotalTimeoutMultiplier = 10;
myTimeout.WriteTotalTimeoutConstant = 50;
myTimeout.WriteTotalTimeoutMultiplier = 10;
SetCommTimeouts(hcom,&myTimeout);
printf("Waiting for Data\n");
SetCommMask(hcom,EV_RXCHAR|EV_ERR);
WaitCommEvent(hcom,&commStatus,0);
if (commStatus & EV_RXCHAR)
{
ReadFile(hcom,&myData,20,&bytesWritten,0);
printf("Data Recieved: %s\n", myData);
}
else if(commStatus & EV_ERR)
{
printf("Error Reading From %s", myPort);
}
}
}
CloseHandle(hcom);
getch();
return 0;
}