Hi Mike,
Using the wclSyncClient, I implemented the following code:
//---------------------------------------------------------------------------
void __fastcall TMTSBTTool::SendOncePollBtnClick(TObject *Sender)
{
int Res;
char *msg, *rxMsg;
msg = new char[16];
rxMsg = new char[1000];
WORD CS;
unsigned int iBytesToRead, iReadTimeout;
msg[0]='i';
msg[1]='7';
msg[2]=0x0C;
msg[3]=0;
msg[4]=0;
msg[5]=0;
msg[6]=0;
msg[7]=0;
msg[8]=0;
msg[9]=0;
msg[10]=0;
msg[11]=0;
msg[12]=0;
msg[13]=0;
msg[14]=0x0C;
msg[15]=0;
DisplayMessageBytes("TX",msg,16);
Application->ProcessMessages();
iStartTime = timeGetTime();
iMsgByteCount = 0; // reset global variable
iBytesToRead=1;
iReadTimeout = 1000;
wclSyncClient->Write(msg, (unsigned int)16);
// wait for response
while (iMsgByteCount<16 && iMsgByteCount<1000)
{
if (wclSyncClient->DataAvailable)
{
Res = wclSyncClient->Read(rxMsg,iBytesToRead,iReadTimeout);
if (Res == WCL_E_SUCCESS)
{
MsgBuffer[iMsgByteCount]=rxMsg[0];
Sleep(0);
iMsgByteCount=iMsgByteCount+iBytesToRead;
}
else
{
LstBx->Items->Insert(0,"Read Error = "+String(Res));
}
}
else
iEndTime=iEndTime;
}
iEndTime = timeGetTime();
LstBx->Items->Insert(0,"Data Size = "+String(wclSyncClient->DataSize));
DisplayMessageBytes("RX",MsgBuffer,16);
LstBx->Items->Insert(0,"Ping Latency = "+String(iEndTime-iStartTime));
wclSyncClient->DataSize;
delete[] msg;
delete[] rxMsg;
}
The first read shows a good reply for the message I sent to our bluetooth device. All subsequent sends result in garbage.
I noticed that the DataSize value property in the wclSyncClient increases with each write. It almost seems like the act of reading the client does not clear out the contents from the last read, but I could be mistaken. I have attached a screen shot showing the progression when the send button is pressed several times.
Am I doing something wrong?
[attachment deleted by admin]