I wrote a serial class that essentially checks the com port for data that has arrived. I read the data one byte at a time and add it to an internal buffer.
Code: Select all
// Get the Bytes in queue
do
{
byte szBuf;
if (ReadFile(cThis->m_hSerial, &szBuf, 1, NULL, &ovRead))
{
GetOverlappedResult(cThis->m_hSerial, &ovRead, &dwBytesRead, FALSE);
cThis->m_Buffer.AddData(szBuf);
}
else
{
DWORD err = GetLastError();
(void)err;
}
} while (dwBytesRead > 0);
Code: Select all
void Buffer::AddData(byte c)
{
LockBuf();
m_byteArray.push_back(c);
m_bytesAvailable = true;
UnLockBuf();
}
according to this page https://wiki.wxwidgets.org/Making_a_render_loop I was thinking of doing something like this
Code: Select all
bool AppMain::OnInit()
{
receive_data_loop_on = false;
//put construction and showing of top-level window here (by using new statement)
Layout * layout = new Layout(wxT("Yapper"));
layout->Show(true);
activateReceiveDataLoop(true);
return true;
}
void AppMain::activateReceiveDataLoop(bool on)
{
if(on && !receive_data_loop_on)
{
Connect( wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(MyApp::onIdle) );
receive_data_loop_on = true;
}
else if(!on && receive_data_loop_on)
{
Disconnect( wxEVT_IDLE, wxIdleEventHandler(MyApp::onIdle) );
receive_data_loop_on = false;
}
}
void AppMain::onIdle(wxIdleEvent& evt)
{
if(render_loop_on)
{
// code to update the wxTextCtrl here
evt.RequestMore(); // Receive continuously, not only once on idle as long as com is connected
}
}