本文整理汇总了C#中Modbus.Message.ReadCoilsInputsRequest类的典型用法代码示例。如果您正苦于以下问题:C# ReadCoilsInputsRequest类的具体用法?C# ReadCoilsInputsRequest怎么用?C# ReadCoilsInputsRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReadCoilsInputsRequest类属于Modbus.Message命名空间,在下文中一共展示了ReadCoilsInputsRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: CalculateLrc
public void CalculateLrc()
{
ReadCoilsInputsRequest request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 1, 1, 10);
Assert.AreEqual(243, ModbusUtility.CalculateLrc(new byte[] { 1, 1, 0, 1, 0, 10 }));
}
开发者ID:nabrotzky,项目名称:OmniModbus,代码行数:5,代码来源:ModbusUtilityFixture.cs
示例17: CreateModbusRequestForReadCoils
public void CreateModbusRequestForReadCoils()
{
ReadCoilsInputsRequest req = new ReadCoilsInputsRequest(1, 2, 1, 10);
IModbusMessage request = ModbusMessageFactory.CreateModbusRequest(req.MessageFrame);
Assert.AreEqual(typeof (ReadCoilsInputsRequest), request.GetType());
}
开发者ID:Salman-Samian,项目名称:NModbus4,代码行数:6,代码来源:ModbusMessageFactoryFixture.cs
示例18: MessageFrameReadCoilsRequest
public void MessageFrameReadCoilsRequest()
{
ModbusMessage message = new ReadCoilsInputsRequest(Modbus.ReadCoils, 1, 2, 3);
byte[] expectedMessageFrame = { 1, Modbus.ReadCoils, 0, 2, 0, 3 };
Assert.AreEqual(expectedMessageFrame, message.MessageFrame);
}
开发者ID:ian588h,项目名称:nmodbus,代码行数:6,代码来源:ModbusMessageFixture.cs
示例19: ProtocolDataUnitReadCoilsRequest
public void ProtocolDataUnitReadCoilsRequest()
{
ModbusMessage message = new ReadCoilsInputsRequest(Modbus.ReadCoils, 1, 100, 9);
byte[] expectedResult = { Modbus.ReadCoils, 0, 100, 0, 9 };
Assert.AreEqual(expectedResult, message.ProtocolDataUnit);
}
开发者ID:ian588h,项目名称:nmodbus,代码行数:6,代码来源:ModbusMessageFixture.cs
示例20: ValidateResponse_MismatchingFunctionCodes
public void ValidateResponse_MismatchingFunctionCodes()
{
MockRepository mocks = new MockRepository();
ModbusTransport transport = mocks.PartialMock<ModbusTransport>();
IModbusMessage request = new ReadCoilsInputsRequest(Modbus.ReadCoils, 1, 1, 1);
IModbusMessage response = new ReadHoldingInputRegistersResponse(Modbus.ReadHoldingRegisters, 1,
new RegisterCollection());
mocks.ReplayAll();
transport.ValidateResponse(request, response);
mocks.VerifyAll();
}
开发者ID:Salman-Samian,项目名称:NModbus4,代码行数:13,代码来源:ModbusTransportFixture.cs
注:本文中的Modbus.Message.ReadCoilsInputsRequest类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论