當前位置: 首頁>>代碼示例>>C#>>正文


C# Message.ReadCoilsInputsRequest類代碼示例

本文整理匯總了C#中Modbus.Message.ReadCoilsInputsRequest的典型用法代碼示例。如果您正苦於以下問題:C# ReadCoilsInputsRequest類的具體用法?C# ReadCoilsInputsRequest怎麽用?C# ReadCoilsInputsRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ReadCoilsInputsRequest類屬於Modbus.Message命名空間,在下文中一共展示了ReadCoilsInputsRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ReadDiscretes

        internal static ReadCoilsInputsResponse ReadDiscretes(ReadCoilsInputsRequest request, ModbusDataCollection<bool> dataSource)
        {
            DiscreteCollection data = DataStore.ReadData<DiscreteCollection, bool>(dataSource, request.StartAddress, request.NumberOfPoints);
            ReadCoilsInputsResponse response = new ReadCoilsInputsResponse(request.FunctionCode, request.SlaveAddress, data.ByteCount, data);

            return response;
        }
開發者ID:uqlpayne,項目名稱:UQ-iLab-BatchLabServer,代碼行數:7,代碼來源:ModbusSlave.cs

示例2: BuildMessageFrame

 public void BuildMessageFrame()
 {
     byte[] message = {17, Modbus.ReadCoils, 0, 19, 0, 37, 14, 132};
     ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 17, 19, 37);
     Assert.Equal(message,
         new ModbusRtuTransport(MockRepository.GenerateStub<IStreamResource>()).BuildMessageFrame(request));
 }
開發者ID:baminmru,項目名稱:vodopad-ip-server,代碼行數:7,代碼來源:ModbusRtuTransportFixture.cs

示例3: ReadRequestResponse

        public void ReadRequestResponse()
        {
            MockRepository mocks = new MockRepository();
            var mockTransport = mocks.StrictMock<IStreamResource>(null);

            byte[] mbapHeader = { 45, 63, 0, 0, 0, 6 };

            Expect.Call(mockTransport.Read(new byte[6], 0, 6)).Do(((Func<byte[], int, int, int>)delegate(byte[] buf, int offset, int count)
            {
                Array.Copy(mbapHeader, buf, 6);
                return 6;
            }));

            ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 1, 1, 3);

            Expect.Call(mockTransport.Read(new byte[6], 0, 6)).Do(((Func<byte[], int, int, int>)delegate(byte[] buf, int offset, int count)
            {
                Array.Copy(new byte[] { 1 }.Concat(request.ProtocolDataUnit).ToArray(), buf, 6);
                return 6;
            }));

            mocks.ReplayAll();
            Assert.AreEqual(ModbusIpTransport.ReadRequestResponse(mockTransport), new byte[] { 45, 63, 0, 0, 0, 6, 1, 1, 0, 1, 0, 3 });
            mocks.VerifyAll();
        }
開發者ID:KirillDZR,項目名稱:nmodbus,代碼行數:25,代碼來源:ModbusTcpTransportFixture.cs

示例4: BuildMessageFrame

 public void BuildMessageFrame()
 {
     byte[] expected = { 58, 48, 50, 48, 49, 48, 48, 48, 48, 48, 48, 48, 49, 70, 67, 13, 10 };
     ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 2, 0, 1);
     var actual = new ModbusAsciiTransport(MockRepository.GenerateStub<IStreamResource>()).BuildMessageFrame(request);
     Assert.AreEqual(expected, actual);
 }
開發者ID:nabrotzky,項目名稱:OmniModbus,代碼行數:7,代碼來源:ModbusAsciiTransportFixture.cs

示例5: ChecksumsMatchFail

 public void ChecksumsMatchFail()
 {
     ModbusRtuTransport transport = new ModbusRtuTransport(MockRepository.GenerateStub<IStreamResource>());
     ReadCoilsInputsRequest message = new ReadCoilsInputsRequest(Modbus.ReadCoils, 17, 19, 38);
     byte[] frame = { 17, Modbus.ReadCoils, 0, 19, 0, 37, 14, 132 };
     Assert.IsFalse(transport.ChecksumsMatch(message, frame));
 }
開發者ID:mesta1,項目名稱:nmodbus,代碼行數:7,代碼來源:ModbusRtuTransportFixture.cs

示例6: ChecksumsMatchSucceed

 public void ChecksumsMatchSucceed()
 {
     ModbusAsciiTransport transport = new ModbusAsciiTransport(MockRepository.GenerateStub<IStreamResource>());
     ReadCoilsInputsRequest message = new ReadCoilsInputsRequest(Modbus.ReadCoils, 17, 19, 37);
     byte[] frame = { 17, Modbus.ReadCoils, 0, 19, 0, 37, 182 };
     Assert.IsTrue(transport.ChecksumsMatch(message, frame));
 }
開發者ID:nabrotzky,項目名稱:OmniModbus,代碼行數:7,代碼來源:ModbusAsciiTransportFixture.cs

示例7: CreateReadInputsRequest

		public void CreateReadInputsRequest()
		{
			ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadInputs, 5, 1, 10);
			Assert.AreEqual(Modbus.ReadInputs, request.FunctionCode);
			Assert.AreEqual(5, request.SlaveAddress);
			Assert.AreEqual(1, request.StartAddress);
			Assert.AreEqual(10, request.NumberOfPoints);
		}
開發者ID:ian588h,項目名稱:nmodbus,代碼行數:8,代碼來源:ReadCoilsInputsRequestFixture.cs

示例8: CreateModbusMessageReadCoilsRequest

 public void CreateModbusMessageReadCoilsRequest()
 {
     ReadCoilsInputsRequest request = ModbusMessageFactory.CreateModbusMessage<ReadCoilsInputsRequest>(new byte[] { 11, Modbus.ReadCoils, 0, 19, 0, 37 });
     ReadCoilsInputsRequest expectedRequest = new ReadCoilsInputsRequest(Modbus.ReadCoils, 11, 19, 37);
     AssertModbusMessagePropertiesAreEqual(request, expectedRequest);
     Assert.AreEqual(expectedRequest.StartAddress, request.StartAddress);
     Assert.AreEqual(expectedRequest.NumberOfPoints, request.NumberOfPoints);
 }
開發者ID:mesta1,項目名稱:nmodbus,代碼行數:8,代碼來源:ModbusMessageFactoryFixture.cs

示例9: BuildMessageFrame

 public void BuildMessageFrame()
 {
     MockRepository mocks = new MockRepository();
     ModbusIpTransport mockModbusTcpTransport = mocks.PartialMock<ModbusIpTransport>(MockRepository.GenerateStub<IStreamResource>());
     ReadCoilsInputsRequest message = new ReadCoilsInputsRequest(Modbus.ReadCoils, 2, 10, 5);
     mocks.ReplayAll();
     Assert.AreEqual(new byte[] { 0, 0, 0, 0, 0, 6, 2, 1, 0, 10, 0, 5 }, mockModbusTcpTransport.BuildMessageFrame(message));
     mocks.VerifyAll();
 }
開發者ID:KirillDZR,項目名稱:nmodbus,代碼行數:9,代碼來源:ModbusTcpTransportFixture.cs

示例10: Write

		public void Write()
		{
			MockRepository mocks = new MockRepository();
			var mockTcpStreamAdapter = mocks.StrictMock<IStreamResource>();
			mockTcpStreamAdapter.Write(new byte[] { 255, 255, 0, 0, 0, 6, 1, 1, 0, 1, 0, 3 }, 0, 12);
			ModbusIpTransport mockModbusTcpTransport = mocks.PartialMock<ModbusIpTransport>(mockTcpStreamAdapter);
			Expect.Call(mockModbusTcpTransport.GetNewTransactionId()).Return(UInt16.MaxValue);
			mocks.ReplayAll();
			ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 1, 1, 3);
			mockModbusTcpTransport.Write(request);
			mocks.VerifyAll();
		}
開發者ID:ian588h,項目名稱:nmodbus,代碼行數:12,代碼來源:ModbusTcpTransportFixture.cs

示例11: UnicastMessage_ErrorSlaveException

        public void UnicastMessage_ErrorSlaveException()
        {
            MockRepository mocks = new MockRepository();
            ModbusTransport transport = mocks.PartialMock<ModbusTransport>();
            transport.Write(null);
            LastCall.IgnoreArguments();
            Expect.Call(transport.ReadResponse<ReadCoilsInputsResponse>())
                .Do((ThrowExceptionDelegate)delegate { throw new SlaveException(); });

            mocks.ReplayAll();

            ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadInputs, 2, 3, 4);
            Assert.Throws<SlaveException>(() => transport.UnicastMessage<ReadCoilsInputsResponse>(request));

            mocks.VerifyAll();
        }
開發者ID:baminmru,項目名稱:vodopad-ip-server,代碼行數:16,代碼來源:ModbusTransportFixture.cs

示例12: UnicastMessage_WrongResponseFunctionCode

        public void UnicastMessage_WrongResponseFunctionCode()
        {
            MockRepository mocks = new MockRepository();
            ModbusTransport transport = mocks.PartialMock<ModbusTransport>();
            transport.Write(null);
            LastCall.IgnoreArguments().Repeat.Times(Modbus.DefaultRetries + 1);
            // read 4 coils from slave id 2
            Expect.Call(transport.ReadResponse<ReadCoilsInputsResponse>())
                .Return(new ReadCoilsInputsResponse(Modbus.ReadCoils, 2, 0, new DiscreteCollection()))
                .Repeat.Times(Modbus.DefaultRetries + 1);

            mocks.ReplayAll();

            ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadInputs, 2, 3, 4);
            Assert.Throws<IOException>(() => transport.UnicastMessage<ReadCoilsInputsResponse>(request));

            mocks.VerifyAll();
        }
開發者ID:baminmru,項目名稱:vodopad-ip-server,代碼行數:18,代碼來源:ModbusTransportFixture.cs

示例13: UnicastMessage_PurgeReceiveBuffer

		public void UnicastMessage_PurgeReceiveBuffer()
		{
			MockRepository mocks = new MockRepository();
			IStreamResource serialResource = mocks.StrictMock<IStreamResource>();
			ModbusSerialTransport transport = new ModbusRtuTransport(serialResource);

			serialResource.DiscardInBuffer();
			serialResource.Write(null, 0, 0);
			LastCall.IgnoreArguments();

			// mangled response
			Expect.Call(serialResource.Read(new byte[] { 0, 0, 0, 0 }, 0, 4)).Return(4);

			serialResource.DiscardInBuffer();
			serialResource.Write(null, 0, 0);
			LastCall.IgnoreArguments();

			// normal response
			ReadCoilsInputsResponse response = new ReadCoilsInputsResponse(Modbus.ReadCoils, 2, 1, new DiscreteCollection(true, false, true, false, false, false, false, false));

			// read header
			Expect.Call(serialResource.Read(new byte[] { 0, 0, 0, 0 }, 0, 4)).Do(((Func<byte[], int, int, int>) delegate(byte[] buf, int offset, int count)
			{
				Array.Copy(response.MessageFrame, 0, buf, 0, 4);
				return 4;
			}));

			// read remainder
			Expect.Call(serialResource.Read(new byte[] { 0, 0 }, 0, 2)).Do(((Func<byte[], int, int, int>) delegate(byte[] buf, int offset, int count)
			{
				Array.Copy(ModbusUtility.CalculateCrc(response.MessageFrame), 0, buf, 0, 2);
				return 2;
			}));

			mocks.ReplayAll();

			ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 2, 3, 4);
			transport.UnicastMessage<ReadCoilsInputsResponse>(request);

			mocks.VerifyAll();
		}
開發者ID:ian588h,項目名稱:nmodbus,代碼行數:41,代碼來源:ModbusSerialTransportFixture.cs

示例14: UnicastMessage

        public void UnicastMessage()
        {
            MockRepository mocks = new MockRepository();
            ModbusTransport transport = mocks.PartialMock<ModbusTransport>();
            transport.Write(null);
            LastCall.IgnoreArguments();
            // read 4 coils from slave id 2
            Expect.Call(transport.ReadResponse<ReadCoilsInputsResponse>())
                .Return(new ReadCoilsInputsResponse(Modbus.ReadCoils, 2, 1, new DiscreteCollection(true, false, true, false, false, false, false, false)));
            transport.OnValidateResponse(null, null);
            LastCall.IgnoreArguments();

            mocks.ReplayAll();

            ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 2, 3, 4);
            ReadCoilsInputsResponse expectedResponse = new ReadCoilsInputsResponse(Modbus.ReadCoils, 2, 1, new DiscreteCollection(true, false, true, false, false, false, false, false));
            ReadCoilsInputsResponse response = transport.UnicastMessage<ReadCoilsInputsResponse>(request);
            Assert.AreEqual(expectedResponse.MessageFrame, response.MessageFrame);

            mocks.VerifyAll();
        }
開發者ID:nabrotzky,項目名稱:OmniModbus,代碼行數:21,代碼來源:ModbusTransportFixture.cs

示例15: CalculateLrc2

 public void CalculateLrc2()
 {
     //: 02 01 0000 0001 FC
     ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 2, 0, 1);
     Assert.AreEqual(252, ModbusUtility.CalculateLrc(new byte[] { 2, 1, 0, 0, 0, 1}));
 }
開發者ID:nabrotzky,項目名稱:OmniModbus,代碼行數:6,代碼來源:ModbusUtilityFixture.cs


注:本文中的Modbus.Message.ReadCoilsInputsRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。