Hello !
I have to send bytes at 9600 bps, but bytes MUST separated by at least 10ms. For example:
0xA5 (pause > 10ms) 0x5A (pause > 10ms) ...
I used the following method:
CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadFunction_COM, NULL, &threadID);
.
.
.
int CVICALLBACK ThreadFunction_COM (void *functionData)
{
InstallComCallback (impostazioni.porta, (LWRS_TXEMPTY), 0, 0, COM_Callback, 0);
flag.quit_thread = 1;
while (flag.quit_thread) ProcessSystemEvents ();
return 0;
}
.
.
.
void CVICALLBACK COM_Callback (int COMPort, int eventMask, void *callbackData)
{
if (eventMask == LWRS_TXEMPTY) flag.transmit_allowed = 1;
}
The sending function is:
for (i=0; i
{
int a = 0;
//Resetta il flag di trasmissione eseguita
flag.transmit_allowed = 0;
//Scrive un byte e attende che sia uscito dal buffer
ComWrtByte (porta, pacchetto[i]);
while (!flag.transmit_allowed);
//Attende intervallo tra i byte
Delay(0.01);
//Calcola checksum
pacchetto[pacchetto_len - 1] += pacchetto[i];
}
Unfortunately, sometimes, this method doesn't work....
In these cases, putting a breakpoint inside the COM callback function, the program never stops there (!!!!????).
I thought about another solution: I could use the funcion GetOutQLen(port) in this way:
for (i=0; i{
int a = 0;
//Resetta il flag di trasmissione eseguita
flag.transmit_allowed = 0;
//Scrive un byte e attende che sia uscito dal buffer
ComWrtByte (porta, pacchetto[i]);
while (GetOutQLen (porta));
//Attende intervallo tra i byte
Delay(impostazioni.byte_interval);
//Calcola checksum
pacchetto[pacchetto_len - 1] += pacchetto[i];
}
Apparently it works good. Is it a right way ??
Thank you very much !