AutomaticZeroCommand

If AutomaticZeroCommand is set to true, command 0 is automatic send before any other command is sent. Command 0 is important to receive the long address. Every command (anything but command 0) needs the long address for communication.

The default value for AutomaticZeroCommand is true.
[Test]
public void Usage()
{
  HartCommunicationLite communication = new HartCommunicationLite("COM1")

  OpenResult openResult = communication.Open();
  Assert.That(openResult, Is.EqualTo(OpenResult.Opened));

  commandResult = communication.Send(12);  //this works because AutomaticZeroCommand is true and command 0 was automatically sent.
  Assert.That(commandResult, Is.Not.Null);
  Assert.That(commandResult.CommandNumber, Is.EqualTo(12));
  Assert.That(commandResult.ResponseCode.FirstByte, Is.EqualTo(0));

  CloseResult closeResult = communication.Close();
  Assert.That(closeResult, Is.EqualTo(CloseResult.Closed));
}
If AutomaticZeroCommand is set to false, use SendZeroCommand method before use Send method.
[Test]
public void Usage()
{
  HartCommunicationLite communication = new HartCommunicationLite("COM1");
  communication.AutomaticZeroCommand = false;

  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));

  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));

  CloseResult closeResult = communication.Close();
  Assert.That(closeResult, Is.EqualTo(CloseResult.Closed));
}
If AutomaticZeroCommand is set to false and method SendZeroCommand was not call, Send method returns null.
[Test]
public void ShouldReturnNullIfNoZeroCommandSend()
{
  HartCommunicationLite communication = new HartCommunicationLite("COM1");
  communication.AutomaticZeroCommand = false;

  OpenResult openResult = communication.Open();
  Assert.That(openResult, Is.EqualTo(OpenResult.Opened));

  CommandResult commandResult = communication.Send(12);
  Assert.That(commandResult, Is.Null);

  CloseResult closeResult = communication.Close();
  Assert.That(closeResult, Is.EqualTo(CloseResult.Closed));
}

Last edited Mar 14, 2011 at 3:27 PM by schubertj, version 3

Comments

No comments yet.