using JiangsuEarthquake.Common; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JiangsuEarthquake.Models { public class ComModel2 : NotifyBase { private RTUModel2 rtuInstance2 = null; private VolCurCollectorModel2 volCurCollectorModel2 { get; set; } = new VolCurCollectorModel2(); private bool isConnected; /// /// 是否连接 /// public bool IsConnected { get { return isConnected; } set { isConnected = value; this.DoNotify(); } } /// /// 建立连接 /// /// public bool DoConnect(SerialInfo serialInfo) { rtuInstance2 = RTUModel2.GetInstance(serialInfo); //rtuInstance2.ResponseData = new Action>(volCurCollectorModel2.ParsingData); IsConnected = rtuInstance2.Connection(); return IsConnected; } /// /// 断开连接 /// /// public bool DisConnect() { rtuInstance2.Dispose(); IsConnected = false; return IsConnected; } public bool SendMessage(byte[] _send) { if (_send.Length == 0) return false; try { if (IsConnected) { rtuInstance2.Send(_send); return true; } else { return false; } } catch (Exception ex) { return false; } } } }