I've downloaded the API C++ source code and I've modified the main.ccp for my use. In my program I use a function for writing to serial port "COM1" the letter "w"; this function is called in my "void main" in a loop where the program read by "rr.getVariable("command", buffer, 64)" the value of my variable "command".
This is my loop:
do
{
rr.getVariable("command", buffer,64);
printf("buffer: %s\n",buffer);
RS232(L"w");
Sleep(500);
}
while(buffer!="exit");
The serial port function is:
void RS232(wchar_t *comando)
{
//-------------OPEN PORT----------------------
HANDLE myPortH= CreateFileW(
port,
GENERIC_WRITE,
FILE_SHARE_WRITE,
0,
OPEN_ALWAYS,
FILE_FLAG_OVERLAPPED,
0);
if (myPortH == INVALID_HANDLE_VALUE)
{
printf("Error: %d. \n", GetLastError());
return;
}
else printf("todo bien\n");
//--------------SETUP COMMUNICATION PORT------------------
GetCommState(myPortH,&dcb);
dcb.BaudRate = CBR_115200;
dcb.ByteSize = 8;
dcb.fNull = false;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fParity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
SetCommState(myPortH,&dcb);
//-------------WRITE PORT-----------------------------------
WriteFileEx(myPortH,comando,wcslen(comando),&o,0);
CloseHandle(myPortH);
return;
}
When my program entry in my do-while loop it crashes with this error debug: "exception not managed to 0x00000000 in RRealm2.exe: 0xC0000005: access violation to the read 0x00000000.
Debug report point to RR_API::read(......) method in "RR_API.cpp":
int RR_API::read(int hSocket, unsigned char *buffer, int len)
{
struct timeval tim;
fd_set fds;
do
{
FD_ZERO(&fds);
FD_SET(hSocket, &fds);
tim.tv_sec = (timeout/1000);
tim.tv_usec = (timeout%1000)*10;
breakpoint error---> if (select(1024, &fds, NULL, NULL, &tim)<=0)
{
return(-2);
}
}
while (!(FD_ISSET(hSocket, &fds)));
return recv(hSocket, (char *)buffer, len, NULL);
}
Can help me someone?? Sorry for my bad english, I'm italian.
|
|