private void BtnConnect_Click(object sender, RoutedEventArgs e) { List <S7PLCHelper> list = new List <S7PLCHelper>(); foreach (var item in Equipments) { list.Add(new S7PLCHelper() { PLCIP = item.IP, PLCType = PLCType.S7_1500.ToString() }); } plc?.DisConnect(); plc = new S7Implement() { S7PLCHelpers = list }; var temp = plc.Connect(); if (temp.Success) { MessageBox.Show("连接成功"); } else { MessageBox.Show($"连接失败:{temp.Msg}"); } }
private void timer1_Elapsed(object sender, ElapsedEventArgs e) { if (_PLCDriver.IP == null || isFirst == true) { return; } if (!IsConnect) { lock (this) { _PLCDriver.Connect(); if (MessageEventHandler != null) { MessageEventHandler(Name + DateTime.Now + "已重新连接", null); } } } }
private void BtnOPCConnect_Click(object sender, RoutedEventArgs e) { plc = new OPCImplement("192.168.10.3") { Equipments = Equipments }; plc?.DisConnect(); var temp = plc.Connect(); if (temp.Success) { MessageBox.Show("连接成功"); } else { MessageBox.Show($"连接失败:{temp.Msg}"); } }