private void Connect(ModbusPkt pkt) { bool success = MB.Connect(pkt.IpAddress, pkt.IpPort); AsyncComplete ac = new AsyncComplete(MB, pkt) { Success = success }; parent.Invoke(new EventHandler(delegate { Complete(this, ac); })); }
private void Reconnect() { try { m_Modbus.Disconnect(); Thread.Sleep(200); m_Modbus.Connect(); } catch (Exception ex) { log.AddERRORLOG(string.Format("重连异常:{0}\r\n{1}", ex.Message, ex.StackTrace)); } }
public async Task Connect() { var res = Modbus.Connect(_client); if (res.IsError) { MessageBox.Show(res.ErrorValue); } else { _client = res.ResultValue; MessageBox.Show("Connected"); } await Task.CompletedTask; }
private void NastavHodnotuNaPozadovanemPinu(int Pin, bool Hodnota) { try { Modbus.Connect(); Stopwatch casovac = new Stopwatch(); casovac.Start(); Task.Factory.StartNew(async() => { while (PrectiHodnotuNaVystupu(Pin) != Hodnota || casovac.Elapsed < timeoutProZaslaniHodnotyNaVystup) { Modbus.WriteSingleCoil(Pin, Hodnota); await Task.Delay(10); } }); } catch (Exception e) { } }