I have a new issue, where my App crashes on triggering one of the events.
On each itteration of my worker thread, I send events to one of the "main" windows, as well as an additional "diagnostics" window (which is tied to the same main window), under the condition that it is opened by the user:
Code: Select all
//Send event to main window
wxCommandEvent evt(wxEVT_RTU_UPDATE, wxID_ANY);
pMainEvtHandler->AddPendingEvent(evt);
//Send event to diagnostics window
if (mbGateway->pMain[nRTU]->mbDiagnosticsWindowIsOpen)
{
wxCommandEvent evt(wxEVT_DIAG_UPDATE, wxID_ANY);
pDiagEvtHandler->AddPendingEvent(evt);
}
Sending events to the main window works well, however as soon as the diagnostics window is opened, the app crashes when trying to send an event to it. The events are declared and defined in the same way in both windows. I tried using QueueEvent instead of AddPendingEvent, according to the recommendation found in AddPendingEvent, however it didn't help:
Code: Select all
//Send event to main window
wxCommandEvent* evt = new wxCommandEvent(wxEVT_RTU_UPDATE, wxID_ANY);
pMainEvtHandler->QueueEvent(evt);
//Send event to diagnostics window
if (mbGateway->pMain[nRTU]->mbDiagnosticsWindowIsOpen)
{
wxCommandEvent* evt = new wxCommandEvent(wxEVT_DIAG_UPDATE, wxID_ANY);
pDiagEvtHandler->QueueEvent(evt);
}
I'm not sure whether the problem might be with my App, or with the way I trigger the events.
Here is how I declare the events in cModbusGateway.h:
Code: Select all
DECLARE_EVENT_TYPE(wxEVT_RTU_UPDATE, -1)
DECLARE_EVENT_TYPE(wxEVT_DIAG_UPDATE, -1)
I define them in cModbusGateway.cpp:
Code: Select all
DEFINE_EVENT_TYPE(wxEVT_RTU_UPDATE)
DEFINE_EVENT_TYPE(wxEVT_DIAG_UPDATE)
Here is the event table in cMain.cpp:
Code: Select all
wxBEGIN_EVENT_TABLE(cMain, wxFrame)
EVT_COMMAND(wxID_ANY, wxEVT_RTU_UPDATE, cMain::OnModbusUpdate)
EVT_BUTTON(10001, cMain::OnButtonClickedWsun)
EVT_BUTTON(10002, cMain::OnButtonClickedWysun)
EVT_BUTTON(10003, cMain::OnButtonClickedCalibrate)
EVT_MENU(wxID_PREFERENCES, cMain::OnMenuClickedDiagnostics)
EVT_MENU(wxID_INFO, cMain::OnMenuClickedInformation)
EVT_MENU(wxID_EXIT, cMain::OnMenuClickedExit)
EVT_TIMER(10004, cMain::OnWriteTimer)
EVT_TIMER(10005, cMain::OnWriteErrorTimer)
EVT_CLOSE(cMain::OnClose)
wxEND_EVENT_TABLE()
Here is the event table in cDiagnostics.cpp:
Code: Select all
wxBEGIN_EVENT_TABLE(cDiagnostics, wxFrame)
EVT_COMMAND(wxID_ANY, wxEVT_DIAG_UPDATE, cDiagnostics::OnDiagnosticsUpdate)
EVT_TIMER(10006, cDiagnostics::OnDiagnosticsResetTimer)
EVT_BUTTON(10007, cDiagnostics::OnButtonClickedReset)
EVT_CLOSE(cDiagnostics::OnClose)
wxEND_EVENT_TABLE()
Regards,
Ksawery