예제 #1
1
        public void RTU_ADU_DocSampleReq()
        {
            var DocRequest = new byte[]
            {
                0x01,
                0x10, 0x00, 0x01, 0x00, 0x01, 0x02, 0xFF, 0xFF,
                0xA6, 0x31,
            };

            var DocResponse = new byte[]
            {
                0x01,
                0x10, 0x00, 0x01, 0x00, 0x01,
                0x50, 0x09,
            };

            var ClientPDU = new WriteMultipleRegistersPDU(1, new int[] { 0xFFFF });
            var Device = new RTU_Device(1);

            var ClientADU = new RTU_ADU(Device, ClientPDU);

            CollectionAssert.AreEqual(DocRequest, ClientADU.BuildRequest());

            Assert.AreEqual(Status.OK, ClientADU.CheckResponse(DocResponse));

            

        }
예제 #2
0
        public RTU_ADU(RTU_Device Device, IProtocolDataUnit PDU)
        {
            if (!(Device is RTU_Device))
                throw new ArgumentException("Wrong Device type");

            this.PDU = PDU;
            this.Device = Device;
        }
예제 #3
0
        public void RTU_ADU_LifeCycle()
        {
            var ClientPDU = new ReadHoldingRegistersPDU(5, 10);
            var Device = new RTU_Device(1);
            var ClientADU = new RTU_ADU(Device, ClientPDU);

            var ServerADU = new RTU_ADU(Device);

            ServerADU.CheckRequest(ClientADU.BuildRequest());
        }
예제 #4
0
        public RTU_ADU(RTU_Device Device, IProtocolDataUnit PDU)
        {
            if (!(Device is RTU_Device))
            {
                throw new ArgumentException("Wrong Device type");
            }

            this.PDU    = PDU;
            this.Device = Device;
        }
예제 #5
0
            public myDevice()
            {
                Client = new RTU_Client("COM10", 19200);
                Client.MaxCount = 10;
                Device = new RTU_Device(1);

                Value = 0;
                Timer = new Timer(25);
                Timer.Elapsed += Timer_Elapsed;
                Timer.Enabled = true;
            }
예제 #6
0
        void Listen()
        {
            var Device = new RTU_Device(Address);

            
            Buffer = new List<byte>();

            try
            {
                while (true)
                {
                    var ADU = new RTU_ADU(Device);

                    Port.DiscardInBuffer();
                    Buffer.Clear();

                    #region Recieve first byte
                    Port.ReadTimeout = SerialPort.InfiniteTimeout;

                    Buffer.Add((byte)Port.ReadByte());
                    //ByteRecievedEvent(Buffer.Last());

                    #endregion

                    #region Recieve All bytes
                    Port.ReadTimeout = ByteTimeout;


                    try
                    {
                        while(true)
                            Buffer.Add((byte)Port.ReadByte());
                            //ByteRecievedEvent(Buffer.Last());
                        
                    }
                    catch (TimeoutException) { }
                    #endregion

                    #region Handle Req
                    if ((ADU.CheckRequest(Buffer.ToArray())) == Status.OK)
                    {
                        ADU.PDU.Handle(this);
                        var Response = ADU.BuildResponse();
                        Port.Write(Response, 0, Response.Length);
                    }
                    #endregion

                }
            }
            catch (IOException)
            { }

          }
예제 #7
0
        void Listen()
        {
            var Device = new RTU_Device(Address);


            Buffer = new List <byte>();

            try
            {
                while (true)
                {
                    var ADU = new RTU_ADU(Device);

                    Port.DiscardInBuffer();
                    Buffer.Clear();

                    #region Recieve first byte
                    Port.ReadTimeout = SerialPort.InfiniteTimeout;

                    Buffer.Add((byte)Port.ReadByte());
                    //ByteRecievedEvent(Buffer.Last());

                    #endregion

                    #region Recieve All bytes
                    Port.ReadTimeout = ByteTimeout;


                    try
                    {
                        while (true)
                        {
                            Buffer.Add((byte)Port.ReadByte());
                        }
                        //ByteRecievedEvent(Buffer.Last());
                    }
                    catch (TimeoutException) { }
                    #endregion

                    #region Handle Req
                    if ((ADU.CheckRequest(Buffer.ToArray())) == Status.OK)
                    {
                        ADU.PDU.Handle(this);
                        var Response = ADU.BuildResponse();
                        Port.Write(Response, 0, Response.Length);
                    }
                    #endregion
                }
            }
            catch (IOException)
            { }
        }
예제 #8
0
 public RTU_ADU(RTU_Device Device)
 {
     this.Device = Device;
 }
예제 #9
0
 public RTU_ADU(RTU_Device Device)
 {
     this.Device = Device;
 }