This project is read-only.
SendAsync

Use the SendAsync method to send commands asynchron to a field device. Use the Receive event to handle the results.

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

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

Comments

No comments yet.