Hi.
In my project, before RunInterface function I start a thread for the comunication port.
In this thread first of all I open the comunication port and set the settings for it.
In the main program I need to change the port at one moment. Now I ask how can do that?
I will explain what I tryed to do.
In the main program I closed the port and than I use the same function to start a new
threadpool.
This mettod works but for a limited number of times. After a few number of changing the
port the call of the thread function stops to work.
I think that I need to stop the first thead before starting another one.
I tryed to change the port in the main program :
rs232Status2 = CloseCom (comport);
GetCtrlIndex (GetPort_handle, Config_ComPort, &portindex);
GetValueFromIndex (GetPort_handle, Config_ComPort, portindex, &comport);
cmtStatus = CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE,ThreadFunction,
NULL,&threadID);
This is the thread rutine:
int CVICALLBACK ThreadFunction (void *functionData)
{
int status;
SetBreakOnLibraryErrors (0);
OpenComConfig (comport, "", 19200, 0, 8, 1, 5000, 512);
status = GetComStat (comport);
if(status>=0)
{
/* Turn off Hardware handshaking (loopback test will not function with
it on) */
SetCTSMode (comport, LWRS_HWHANDSHAKE_OFF);
ComSetEscape (comport, 4);
/* Make sure Serial buffers are empty */
FlushInQ (comport);
FlushOutQ (comport);
EventMask=LWRS_RXFLAG;
rs232Status2 = InstallComCallback (comport, EventMask, 0, 0xff,
SerialaCallback, 0);
}
else
{
SetBreakOnLibraryErrors (1);
MessagePopup("Error","This port do not exist.");
return 0;
}
SetBreakOnLibraryErrors (1);
/* Start a loop that will process events for this thread */
while (quitflag == 0)
{
ProcessSystemEvents ();
}
/* Close the open COM port before exiting */
rs232Status2 = CloseCom (comport);
return 0;
}
Thanks.