Exemplo n.º 1
0
        public virtual void ExecuteCustomMessage_WriteMultipleRegisters()
        {
            ushort testAddress = 120;
            ushort[] testValues = new ushort[] { 10, 20, 30, 40, 50 };
            CustomReadHoldingRegistersRequest readRequest = new CustomReadHoldingRegistersRequest(3, SlaveAddress, testAddress, (ushort) testValues.Length);
            CustomWriteMultipleRegistersRequest writeRequest = new CustomWriteMultipleRegistersRequest(16, SlaveAddress, testAddress, new RegisterCollection(testValues));

            var response = Master.ExecuteCustomMessage<CustomReadHoldingRegistersResponse>(readRequest);
            ushort[] originalValues = response.Data;
            Master.ExecuteCustomMessage<CustomWriteMultipleRegistersResponse>(writeRequest);
            response = Master.ExecuteCustomMessage<CustomReadHoldingRegistersResponse>(readRequest);
            ushort[] newValues = response.Data;
            Assert.AreEqual(testValues, newValues);
            writeRequest = new CustomWriteMultipleRegistersRequest(16, SlaveAddress, testAddress, new RegisterCollection(originalValues));
            Master.ExecuteCustomMessage<CustomWriteMultipleRegistersResponse>(writeRequest);
        }
Exemplo n.º 2
0
 public virtual void ExecuteCustomMessage_ReadHoldingRegisters()
 {
     CustomReadHoldingRegistersRequest request = new CustomReadHoldingRegistersRequest(3, SlaveAddress, 104, 2);
     CustomReadHoldingRegistersResponse response = Master.ExecuteCustomMessage<CustomReadHoldingRegistersResponse>(request);
     Assert.AreEqual(new ushort[] { 0, 0 }, response.Data);
 }