/// <summary> /// /// </summary> public virtual void Init() { mComm = Device.GetCommChannel(); if (mComm != null) { mComm.CommChangedEvent += MComm_CommChangedEvent; mComm.RegistorReceiveCallBack(OnReceiveData); foreach (var vv in Device.ListTags()) { if (!string.IsNullOrEmpty(vv.DeviceInfo)) { if (mCachTags.ContainsKey(vv.DeviceInfo)) { mCachTags[vv.DeviceInfo].Add(vv.Id); } else { mCachTags.Add(vv.DeviceInfo, new List <int>() { vv.Id }); } } } mComm.Init(); } }
/// <summary> /// /// </summary> public void Init() { mIdMapTags = Device.Tags; foreach (var vv in Device.Tags) { string dbname = vv.Value.DatabaseName; string dvname = vv.Value.DeviceInfo; if (!mDatabaseMapTags.ContainsKey(dbname)) { mDatabaseMapTags.Add(dbname, vv.Value); } if (mDeviceMapTags.ContainsKey(dvname)) { mDeviceMapTags[dvname].Add(vv.Value); } else { List <Tagbase> ll = new List <Tagbase>() { vv.Value }; mDeviceMapTags.Add(dvname, ll); } } Channel = ServiceLocator.Locator.Resolve <ICommChannelRuntimeManager>().GetChannel(Device.ChannelName); Driver = ServiceLocator.Locator.Resolve <IDriverRuntimeManager>().GetDriver(Device.Name); if (Driver != null) { Driver.Device = this; Driver.Init(); } }
internal ModbusTransport(ICommChannel streamResource) { Debug.Assert(streamResource != null, "Argument streamResource cannot be null."); _streamResource = streamResource; _retries = streamResource.Data.ReTryCount; _waitToRetryMilliseconds = streamResource.Data.ReTryDuration; }
public static ModbusIpMaster CreateIp(ICommChannel streamResource) { if (streamResource == null) { throw new ArgumentNullException(nameof(streamResource)); } return(new ModbusIpMaster(new ModbusIpTransport(streamResource))); }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"> /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only /// unmanaged resources. /// </param> protected virtual void Dispose(bool disposing) { if (disposing) { if (_streamResource != null) { _streamResource.Dispose(); _streamResource = null; } //DisposableUtility.Dispose(ref _streamResource); } }
public UavTalkProto(ICommChannel communicationChannel, UAVObjectManager objMgr) { this.objMgr = objMgr; parser = new UavDataparser(objMgr); parser.onObjectReceived += new UavDataparser.onObjectReceivedDelegate(parser_onObjectReceived); txStats = new ComStats(); ch = communicationChannel; ch.onDataReceived += ch_onDataReceived; statTimer = new Timer(1000); statTimer.Elapsed += statTimer_Elapsed; statTimer.Start(); }
internal static byte[] ReadRequestResponse(ICommChannel streamResource) { // read header var mbapHeader = new byte[6]; int numBytesRead = 0; while (numBytesRead != 6) { int bRead = streamResource.Read(mbapHeader, numBytesRead, 6 - numBytesRead); if (bRead == 0) { throw new IOException("Read resulted in 0 bytes returned."); } numBytesRead += bRead; } Debug.WriteLine($"MBAP header: {string.Join(", ", mbapHeader)}"); var frameLength = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt16(mbapHeader, 4)); Debug.WriteLine($"{frameLength} bytes in PDU."); // read message var messageFrame = new byte[frameLength]; numBytesRead = 0; while (numBytesRead != frameLength) { int bRead = streamResource.Read(messageFrame, numBytesRead, frameLength - numBytesRead); if (bRead == 0) { throw new IOException("Read resulted in 0 bytes returned."); } numBytesRead += bRead; } Debug.WriteLine($"PDU: {frameLength}"); var frame = mbapHeader.Concat(messageFrame).ToArray(); Debug.WriteLine($"RX: {string.Join(", ", frame)}"); return(frame); }
internal static string ReadLine(ICommChannel stream) { var result = new StringBuilder(); var singleByteBuffer = new byte[1]; do { if (stream.Read(singleByteBuffer, 0, 1) == 0) { continue; } result.Append(Encoding.UTF8.GetChars(singleByteBuffer).First()); }while (!result.ToString().EndsWith(Modbus.NewLine)); return(result.ToString().Substring(0, result.Length - Modbus.NewLine.Length)); }
/// <summary> /// /// </summary> /// <param name="mComm"></param> public override void RegistorReceiveCallBack(ICommChannel mComm) { mComm.RegistorReceiveCallBack(this.OnReceiveData2); }
internal ModbusRtuTransport(ICommChannel streamResource) : base(streamResource) { Debug.Assert(streamResource != null, "Argument streamResource cannot be null."); }
/// <summary> /// /// </summary> public virtual void RegistorReceiveCallBack(ICommChannel mComm) { mComm.RegistorReceiveCallBack(OnReceiveData); }