public static ObservableCollection<double> valuo = new ObservableCollection<double>();
public void Mobeas() {
SerialPort tt = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
try
{
tt.Open();
ModbusSerialMaster msm = ModbusSerialMaster.CreateRtu(tt);
Task.Run(new Action(() =>
{
while (true)
{
Task.Delay(100).Wait();
valuo.Clear();
ushort[] boo = msm.ReadHoldingRegisters(1, 0, 10);
for (int i = 0; i < boo.Length; i++)
{
valuo.Add(boo[i]);
}
}
}));
}
catch {
tt.Close();
}
}
C# Modbus连接
最新推荐文章于 2024-09-27 22:19:06 发布