I have integrated the EasyModBus Library and would now like to use the background worker to query values every 250ms via the ModBus. The message modbusclient is null appears in the background worker. How can I get the modbusclient function in the background worker? Is there any way to add a function?
private void backgroundworker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
label10.Text = modbusclient.ReadInputRegisters(4, 1)[0].ToString() + " kHz"; //read register 300005 for frequency
label11.Text = modbusclient.ReadInputRegisters(5, 1)[0].ToString() + " W"; //read register 300006 for power
label12.Text = modbusclient.ReadInputRegisters(6, 1)[0].ToString() + " %"; //read register 300007 for amplitude in %
TimeSpan t = TimeSpan.FromMilliseconds(Convert.ToDouble(modbusclient.ReadInputRegisters(8, 1)[0].ToString()));
string runningtime = string.Format("{0:D2}m:{1:D2}s",
t.Minutes,
t.Seconds);
label14.Text = runningtime;
}