Hi everybody,
I am new with CVI. It's fun, but I have a big problem that's why I'm here 😉 !
I have an EVA Board with a microcontroleur Siemens C167 which generates signals, and a GUI on my computer to configure the signals I want. THe 2 entities are linked by the RS232 serial port. The new protocol I'm trying to set for the synchronization of both is asynchronous. At the begining, my microcontroler send a byte to "ping" the computer. I send back an ack, and at this reception, the GUI set a variable. I would like to do a thread which listens the communication from the µC, because it's not the only frame the GUI has to receive.
It looks like (I am sorry I am using CVI 5.0 😞 , so threads are hard) :
static volatile int exiting = 0; //variable of end
static int received;
int main (int argc, char *argv[])
{
static DWORD idThreadEcoute; //id of the listening thread
static HANDLE hThread;
[...]
if (InitComPort ()) //Inits Com
return 1;
//creation of the thread
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ThreadEcoute, NULL, 0, &idThreadEcoute);
while(received!=TRAMECONTACTOK);
received=TRAMEKO;
RunUserInterface ();
return 0;
}
static int CVICALLBACK ThreadEcoute(DWORD dParameter)
{
unsigned char toSend ;
unsigned char Ack;
while (!exiting)
{
if (ComRd (COMPORT, &Ack, 1) == 1)
{
switch (Ack)
{
case 0xAA : // reception of a ping from the PSG LIght
toSend= 0xC3;
if (ComWrt (COMPORT, &toSend, 1)!=1)
return 1;
break;
case 0xF1 : // reception of an acknoledge for a first contact
received=TRAMECONTACTOK;
break;
....
}
}
}
}
It doesn't work, and i can't debug with CVI. I break at createThread and after on the while, and it loops on this one. Aftter, when I stop the debug, I have this nice message : "An asynchronous callback thread caused an exception. Program will be terminated."
What am i wrong ?
thanks a lot !
Julie