Frameworks > Serial Framework
rs232 OnData problem
abadon:
Hi,
I have a problem with OnData event.
When I receive a short messages all is OK. But when device sends me a big message, i don't have all message in buffor. I'm sure that meaasge was sending by device because i see that on serial monitor.
My OnData function :
void CCSerialAdapter::OnData(LPVOID lpBuffer, DWORD dwSize)
{
const char cSeparator = CHAR(10);
char* Buf;
Buf = (char*)LocalAlloc(LPTR, dwSize + 1);
ZeroMemory(Buf, dwSize + 1);
CopyMemory(Buf, lpBuffer, dwSize);
...
LocalFree((HLOCAL)Buf);
}
My connection proprtites :
m_pClient->SetTransport( wcl::ctSerial );
m_pClient->GetSerialParams()->SetPort(iPort);
m_pClient->GetSerialParams()->SetBaudRate( wcl::br115200 );
wcl::CwclBuffers buffers( m_pClient );
buffers.SetReadBuffer( 4126 );
buffers.SetWriteBuffer( 4126 );
m_pClient->SetBuffers( buffers );
This is my firs time to use WCL so forgive me if my question is stupid :)
Thx,
Mike Petrichenko:
Hi,
Ondata event fires when intenal PCs buffer is full. Your long message from device can be splitted to more than on OnData even.
abadon:
That's correct, i have more than one event and I add all to my queue.
Thats my all OnData function:
void CCSerialAdapter::OnData(LPVOID lpBuffer, DWORD dwSize)
{
const char cSeparator = CHAR(10);
char* Buf;
Buf = (char*)LocalAlloc(LPTR, dwSize + 1);
ZeroMemory(Buf, dwSize + 1);
CopyMemory(Buf, lpBuffer, dwSize);
QStringList strList = QStringList::split( cSeparator , Buf, false );
for ( int i = 0 ; i< strList.count() ; i++ )
{
if ( strList[ i ].length() >= 1 )
{
m_QuaueMutex.lock();
m_AnswerList.push_back( strList[ i ] );
m_QuaueMutex.unlock();
}
}
LocalFree( ( HLOCAL ) Buf );
}
All messages i have in m_AnswerList.
I found funny thing , when i add sleep(300) in the end of the function, everything works almost good ( i loose only one line ).
Thx
Mike Petrichenko:
What is BT driver you use? I have to check it and add Sleep (or somthing) into WCL code to prevent such issue in the future :)
abadon:
I don't use any blueTooth , i have only rs232 ports.
Thx.
Navigation
[0] Message Index
[#] Next page
Go to full version