我正在开发一个基于Shortbus dll RTU的项目。我已经设法读取了设备,但是随着设备数量的增加,每次读取的延迟都会增加太多。
我为每个设备使用了一个单独的计时器,但我没有得到任何结果,因为我必须将值写入数据库并比较旧值和新值以显示“工作”和“不工作”状态。
我希望扫描 227 台设备,但仅使用 32 台设备无法达到我需要的响应。
我正在使用 datagridview 来存储端口和 Modbus ID
http://postimage.org/' target='_blank'>http://s2.postimg.org/x1gdrkug9/modbus.gif'border='0' alt="modbus" />
http://postimage.org /index.php?lang=spanish'>分享图片
读取每一行的代码
private void lectura(int numerofila)
{
try
{
Variables.fila_actual = numerofila + 1;
ushort err;
Variables.sb1.SetCOMPort(Convert.ToUInt16(gridConf.Rows[con].Cells[4].Value), 9600, 8, 'N', 2);
Variables.sb1.SetCOMPort(Convert.ToUInt16(gridConf.Rows[numerofila].Cells[4].Value), 9600, 8, 'N', 2);
err = Variables.sb1.ReadWords(Convert.ToUInt16(gridConf.Rows[numerofila].Cells[3].Value), 1004, 1, out Variables.read, type3x: true);
gridConf.Rows[numerofila].Cells[7].Value = Variables.read[0];
}
catch
{
MessageBox.Show("Error in row " + Variables.numero_filas);
}
}
扫描值的网格视图
http://postimage.org/'target='_blank'>http://s11.postimg.org/7544cqyoj/modbus2.gif'border='0' alt="modbus2" />
http://postimage.org /index.php?lang=spanish'>subir 照片
在每 2 秒的滴答声中,我根据行数执行读数
private void timer1_Tick(object sender, EventArgs e)
{
lectura(0);
}
我尝试了线程,但它们阻塞了应用程序。任何帮助将不胜感激。