Send

Use method Send to communicate with a field device. The method returns an object of type CommandResult.

[Test]
public void Usage()
{
  HartCommunicationLite communication = new HartCommunicationLite("COM1");

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

Use the overloading method to send data bytes to the field device.

[Test]
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();
}

Last edited May 5, 2011 at 3:29 PM by schubertj, version 3

Comments

No comments yet.