Ejemplo n.º 1
0
 public void SetLocomotiveSpeedAndDirection(SpeedAndDirection data)
 {
     try
     {
         var msg = new SetLocoSpeedAndDirection_SpeedSteps128Message(data.EAddress, (byte)data.speed, (data.Direction == EDirection.Forwards) ? Direction.Forward : Direction.Reverse);
         msg.Write(serialPort.BaseStream);
     }
     catch (InvalidOperationException e)
     {
         //TODO return the exception information to the client
         IsConnected = false;
     }
 }
        public async Task SpeedAndDirection128ValidTestMethod()
        {
            var expectedMessageBytes = new byte[] {0xE4, 0x13, 0x00, 0x03,  0x94, 0x60};

            var testStream = new MemoryStream();
            var msgReq = new SetLocoSpeedAndDirection_SpeedSteps128Message(3, 20, Direction.Forward);
            await msgReq.WriteAsync(testStream);
            var actualMessageBytes = ReadStream(testStream);


            CollectionAssert.AreEqual(expectedMessageBytes, actualMessageBytes, 
                string.Format("message not valid, expected {0}, received {1}",
                ByteArrayToString(expectedMessageBytes), ByteArrayToString(actualMessageBytes)));

        }