Esempio n. 1
0
        /// <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();
            }
        }
Esempio n. 2
0
        /// <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();
            }
        }
Esempio n. 3
0
        internal ModbusTransport(ICommChannel streamResource)
        {
            Debug.Assert(streamResource != null, "Argument streamResource cannot be null.");

            _streamResource          = streamResource;
            _retries                 = streamResource.Data.ReTryCount;
            _waitToRetryMilliseconds = streamResource.Data.ReTryDuration;
        }
Esempio n. 4
0
        public static ModbusIpMaster CreateIp(ICommChannel streamResource)
        {
            if (streamResource == null)
            {
                throw new ArgumentNullException(nameof(streamResource));
            }

            return(new ModbusIpMaster(new ModbusIpTransport(streamResource)));
        }
Esempio n. 5
0
 /// <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();
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mComm"></param>
 public override void RegistorReceiveCallBack(ICommChannel mComm)
 {
     mComm.RegistorReceiveCallBack(this.OnReceiveData2);
 }
Esempio n. 10
0
 internal ModbusRtuTransport(ICommChannel streamResource)
     : base(streamResource)
 {
     Debug.Assert(streamResource != null, "Argument streamResource cannot be null.");
 }
Esempio n. 11
0
 /// <summary>
 ///
 /// </summary>
 public virtual void RegistorReceiveCallBack(ICommChannel mComm)
 {
     mComm.RegistorReceiveCallBack(OnReceiveData);
 }