Wireless Communication Library Support Forum
Frameworks => Bluetooth Framework => Topic started by: gaorio on November 09, 2012, 12:44:15 PM
-
In my DLL event OnData stops after the main application window changes.
To run the processes use the function
void BlueSerial :: DoEvents (void)
{
MSG msg;
while (PeekMessage (& msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (& msg);
DispatchMessage (& msg);
}
}
you can directly read the receive buffer? Because the event OnData stops?
-
Hello,
Yes, WCL has Read methods. But in any case WCL requires windows message loop to work. However, Read method has message processing inside so shoudl work in your enveronment.
-
I use CwclClient, but I can not find the Read Method
-
You have to use wclSyncClient. It is the same as wclClient except OnData event and Read method.
-
My problem is still present.
I think the main application message queue and eat my PeekMessage does not read the message read. The same procedures work well using the serial port (CreateFile)
-
Hello,
Can you please send me a code which reproduces the issue so we can run it here and find where problem is.
-
Attached the class bluetooth
The function that checks data is
CommandStatus __FASTCALLCLASSFAST Chk_Answer(unsigned char command)
{
unsigned short buffer_len;
short n_car;
unsigned char car;
CommandStatus status;
unsigned char rx_bcc;
unsigned char n_bcc_car;
unsigned long tim;
unsigned char rx_status;
unsigned char buffer[280];
short rx_data_len;
short rx_buffer_ptr;
// Inizializzazione attesa risposta
SerialPort->StartTimer(RX_INTERCAR_TIMER, EXECUTE_CMD_MASTER_TIMEOUT);
rx_status = RX_WAITSTX;
do
{
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
buffer_len = SerialPort->ReadData(buffer, usLenBufferRX);
for(n_car=0; n_car<buffer_len; n_car++)
{
car = buffer[n_car];
switch(rx_status)
{
case RX_WAITSTX: if(car == STX)
rx_status = RX_WAITCMD;
break;
case RX_WAITCMD: rx_buffer_ptr = 0;
if(rx_buffer_ptr == usLenBufferRX)
rx_status = RX_WAITSTX;
else
{
ucBufferRX[rx_buffer_ptr++] = car;
rx_status = RX_WAITCMDSTATUS;
}
break;
case RX_WAITCMDSTATUS:
if(rx_buffer_ptr == usLenBufferRX)
rx_status = RX_WAITSTX;
else
{
ucBufferRX[rx_buffer_ptr++] = car;
rx_status = RX_WAITLEN;
status = (CommandStatus)car;
if(status!=StatusCMD_DONE)
{
rx_status = RX_WAITBCC;
rx_data_len = 1;
}
}
break;
case RX_WAITLEN: if(rx_buffer_ptr == usLenBufferRX)
rx_status = RX_WAITSTX;
else
{
ucBufferRX[rx_buffer_ptr++] = car;
rx_data_len = car;
if(rx_data_len)
rx_status = RX_DATA;
else
rx_status = RX_WAITBCC;
}
break;
case RX_DATA: if(rx_buffer_ptr == usLenBufferRX)
rx_status = RX_WAITSTX;
else
{
ucBufferRX[rx_buffer_ptr++] = car;
rx_data_len--;
if(!rx_data_len)
rx_status = RX_WAITBCC;
}
break;
case RX_WAITBCC: rx_bcc = 0;
for(n_bcc_car=0; n_bcc_car<rx_buffer_ptr; n_bcc_car++)
rx_bcc += ucBufferRX[n_bcc_car];
if(car == rx_bcc)
rx_status = RX_WAITETX;
else
rx_status = RX_WAITSTX;
break;
case RX_WAITETX: if(car == ETX)
rx_status = RX_END;
else
rx_status = RX_WAITSTX;
break;
}
}
if(buffer_len)
SerialPort->StartTimer(RX_INTERCAR_TIMER, RX_INTERCAR_TIMEOUT);
if(rx_status!=RX_END)
tim=SerialPort->CheckTimer(RX_INTERCAR_TIMER);
else
tim = 1;
}while(tim && rx_status!=RX_END);
// time out
if(rx_status!=RX_END)
status = StatusCMD_ERROR;
gEndAnswer = status;
return (status);
}
[attachment deleted by admin]
-
Hello,
What is SerialPort? ReadData? SetTimer? WCL does not have such methods.
-
attached to the previous message is the class "BlueSerial.zip" with metod ReadData, SetTimer ....
-
Hello,
Ok, thank you. I am going to check that out.
-
Hello,
I have checked your code. If you would like to use Read method intead of OnData event then you do not need message loop. But I do recomend to use asynchronous calls and OnData event. WCL has serial port support as well so you can have one code for Serial and for Bluetooth communication.