User`s manual

Table Of Contents
UC-7400-CE User’s Manual Programming Examples
5-4
rCom = createComHandle(sPort, baudrate);
if (rCom == NULL)
{
printf("Fail to create read port\n");
CloseHandle(wCom);
return 2;
}
/* for a thread to handle receiving */
if (CreateThread( NULL, 0, comReadThread, (LPDWORD) rCom, NULL, 0 )==NULL)
{
printf("Fail to create a receiving thread\n");
CloseHandle(wCom);
CloseHandle(rCom);
return 3;
}
for (i=0; i< MAX_DATA_LEN;i++)
buffer[i] = (unsigned char) ('a'+i%26);
PurgeComm(wCom,PURGE_TXCLEAR | PURGE_TXABORT);
while(loop++ < 100)
{
if (WriteFile(wCom, buffer, MAX_DATA_LEN, &rtn, NULL)==0)
{
printf("Fail to write\n");
break;
}
WaitForSingleObject(waitH, 100);
}
CloseHandle(wCom);
CloseHandle(rCom);
CloseHandle(waitH);
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
comPair(L"COM3", L"COM4", 38400);
return 0;
}