public void Usage() { HartCommunicationLite communication = new HartCommunicationLite("COM1"); List <CommandResult> commandResults = new List <CommandResult>(); AutoResetEvent resetEvent = new AutoResetEvent(false); communication.Receive += (sender, args) => { commandResults.Add(args); if (args.CommandNumber == 12) { resetEvent.Set(); } }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); communication.SendAsync(12); Assert.That(resetEvent.WaitOne(TimeSpan.FromSeconds(20)), Is.True); Assert.That(commandResults.Count, Is.EqualTo(2)); Assert.That(commandResults[0].CommandNumber, Is.EqualTo(0)); Assert.That(commandResults[0].ResponseCode.FirstByte, Is.EqualTo(0)); Assert.That(commandResults[1].CommandNumber, Is.EqualTo(12)); Assert.That(commandResults[1].ResponseCode.FirstByte, Is.EqualTo(0)); communication.Close(); }
public void Usage() { HartCommunicationLite communication = new HartCommunicationLite("COM1") { AutomaticZeroCommand = false }; CommandResult receivedCommandResult = null; AutoResetEvent resetEvent = new AutoResetEvent(false); communication.Receive += (sender, args) => { receivedCommandResult = args; resetEvent.Set(); }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult commandResult = communication.SendZeroCommand(); Assert.That(commandResult, Is.Not.Null); Assert.That(commandResult.CommandNumber, Is.EqualTo(0)); Assert.That(commandResult.ResponseCode.FirstByte, Is.EqualTo(0)); Assert.That(resetEvent.WaitOne(TimeSpan.FromSeconds(2)), Is.True); Assert.That(commandResult.Address, Is.EqualTo(receivedCommandResult.Address)); Assert.That(commandResult.CommandNumber, Is.EqualTo(receivedCommandResult.CommandNumber)); Assert.That(commandResult.PreambleLength, Is.EqualTo(receivedCommandResult.PreambleLength)); Assert.That(commandResult.ResponseCode.FirstByte, Is.EqualTo(receivedCommandResult.ResponseCode.FirstByte)); Assert.That(commandResult.ResponseCode.SecondByte, Is.EqualTo(receivedCommandResult.ResponseCode.SecondByte)); communication.Close(); }
public void ConnectResponseResultShouldBeComPortNotExisting() { HartCommunicationLite communication = new HartCommunicationLite("notExisting"); OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.ComPortNotExisting)); }
public void Usage() { const string PORT_NAME = "COM1"; HartCommunicationLite communication = new HartCommunicationLite(PORT_NAME); OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); communication.Close(); }
public void Usage() { HartCommunicationLite communication = new HartCommunicationLite("COM1"); Assert.That(communication.Address, Is.Null); LongAddress newAddress = new LongAddress(22, 22, new byte[] { 11, 22, 33 }); communication.SwitchAddressTo(newAddress); Assert.That(communication.Address.ToByteArray(), Is.EqualTo(newAddress.ToByteArray())); }
public void ConnectResponseResultShouldBeComPortIsAlreadyOpened() { const string PORT_NAME = "COM1"; System.IO.Ports.SerialPort serialPort = new System.IO.Ports.SerialPort(PORT_NAME); serialPort.Open(); HartCommunicationLite communication = new HartCommunicationLite(PORT_NAME); OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.ComPortIsOpenAlreadyOpen)); serialPort.Close(); }
public void ShouldReturnNullIfNoZeroCommandSend() { HartCommunicationLite communication = new HartCommunicationLite("COM1") { AutomaticZeroCommand = false }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult commandResult = communication.Send(12); Assert.That(commandResult, Is.Null); communication.Close(); }
public void WriteAssemblyNumber() { HartCommunicationLite communication = new HartCommunicationLite("COM1"); OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult commandResult = communication.Send(19, new byte[] { 1, 2, 3 }); Assert.That(commandResult, Is.Not.Null); Assert.That(commandResult.CommandNumber, Is.EqualTo(19)); Assert.That(commandResult.Data, Is.EqualTo(new byte[] { 1, 2, 3 })); Assert.That(commandResult.ResponseCode.FirstByte, Is.EqualTo(0)); communication.Close(); }
public void Usage() { HartCommunicationLite communication = new HartCommunicationLite("COM1") { AutomaticZeroCommand = false }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult command = communication.SendZeroCommand(); Assert.That(command, Is.Not.Null); Assert.That(command.CommandNumber, Is.EqualTo(0)); Assert.That(command.ResponseCode.FirstByte, Is.EqualTo(0)); communication.Close(); }
public void ShouldSendFirstZeroCommand() { HartCommunicationLite communication = new HartCommunicationLite("COM1") { AutomaticZeroCommand = true //true is default }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult commandResult = communication.Send(12); Assert.That(commandResult, Is.Not.Null); Assert.That(commandResult.CommandNumber, Is.EqualTo(12)); Assert.That(commandResult.ResponseCode.FirstByte, Is.EqualTo(0)); communication.Close(); }
public void FirstSendZeroCommandSynchronSecondSendCommand12Asynchron() { HartCommunicationLite communication = new HartCommunicationLite("COM1"); List <CommandResult> commandResults = new List <CommandResult>(); AutoResetEvent resetEvent = new AutoResetEvent(false); communication.Receive += (sender, args) => { commandResults.Add(args); if (args.CommandNumber == 13) { resetEvent.Set(); } }; OpenResult openResult = communication.Open(); Assert.That(openResult, Is.EqualTo(OpenResult.Opened)); CommandResult zeroCommand = communication.SendZeroCommand(); for (int i = 0; i < 10; i++) { communication.SendAsync(12); } communication.SendAsync(13); Assert.That(resetEvent.WaitOne(TimeSpan.FromSeconds(100)), Is.True); Assert.That(commandResults.Count, Is.EqualTo(12)); Assert.That(zeroCommand.CommandNumber, Is.EqualTo(0)); Assert.That(zeroCommand.ResponseCode.FirstByte, Is.EqualTo(0)); Assert.That(commandResults[1].CommandNumber, Is.EqualTo(12)); Assert.That(commandResults[1].ResponseCode.FirstByte, Is.EqualTo(0)); communication.Close(); }
public void Initialize(string comPort) { _hartCommunicationLite = new HartCommunicationLite(comPort); }
public void Usage() { var communication = new HartCommunicationLite("COM1"); Assert.That(communication.AutomaticZeroCommand, Is.True); }