I currently have two buttons in my main window, which become temporarily disabled (for 2 seconds) when pressed. However sometimes (but not always) when I press the buttons, they first "flash" (which I assume is the "button pressed" animation), and don't become disabled. Is this a bug? I'm not sure what could be causing it?
Here are the callback functions i'm using:
Code: Select all
/* "Wsun" button callback */
void cMain::OnButtonClickedWsun(wxCommandEvent& evt)
{
m_btn_wsun->Disable();
mbWriteMode = 1; //set flag, event handled in Modbus thread
evt.Skip();
}
/* "Wysun" button callback */
void cMain::OnButtonClickedWysun(wxCommandEvent& evt)
{
m_btn_wysun->Disable();
mbWriteMode = -1; //set flag, event handled in Modbus thread
evt.Skip();
}
Here is the helper thread:
Code: Select all
/* Modbus helper thread */
wxThread::ExitCode cMain::Entry()
{
while (!GetThread()->TestDestroy())
{
{
//Enter critical section
wxCriticalSectionLocker lock(ModbusCS);
if (mbWriteMode != 0) //writing to register, pause all other communication
{
if (mbWriteMode == 1)
{
mbWriteConfigStatus = -1; //modbus_write_register(ctx, 4001, 1);
}
else if (mbWriteMode == -1)
{
mbWriteConfigStatus = -1; // = modbus_write_register(ctx, 4001, 0);
}
if (mbWriteConfigStatus == -1)
{
m_static_txt_mberror_write->Show(); //show error
wxThread::Sleep(1000); //wait for 1s
m_static_txt_mberror_write->Hide(); //hide error
mbWriteConfigStatus = 0;
}
else
{
wxThread::Sleep(1000); //wait for 1s
}
if (mbWriteMode == 1)
{
m_btn_wsun->Enable();
}
else if (mbWriteMode == -1)
{
m_btn_wysun->Enable();
}
mbWriteMode = 0; //clear flag
}
else //continue reading input registers
{
mbReadADCErrorsStatus = modbus_read_input_registers(ctx, 3006, 1, &ADCErrors);
wxThread::Sleep(20); //delay next poll by 20ms
mbReadADCStatus = modbus_read_input_registers(ctx, 3001, 5, ADCReadings);
}
//Signal to main thread that new data has been received
wxQueueEvent(GetEventHandler(), new wxThreadEvent());
}
//Delay next Modbus message cycle by 200ms
wxThread::Sleep(200);
}
//Destroy thread
return (wxThread::ExitCode)0;
}
Ksawery