This project is read-only.
Open

First, you should open the connection. After successful connect you can communicate with a field device. The method Open configure the RTS and DTR signal and open the COM port.

The return value is a OpenResult. A successful open returns OpenResult.Opened.
[Test]
public void Usage()
{
  HartCommunicationLite communication = new HartCommunicationLite("COM1");

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

  communication.Close();
}
If COM port is already open, the return value is OpenResult.ComPortIsOpenAlreadyOpen.
[Test]
public void ComPortIsOpenAlreadyOpen()
{
  const string PORT_NAME = "COM1";

  SerialPort serialPort = new SerialPort(PORT_NAME);
  serialPort.Open();

  HartCommunicationLite communication = new HartCommunicationLite(PORT_NAME);

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

  serialPort.Close();
}
If COM port is not existing, the return value is OpenResult.ComPortNotExisting.
[Test]
public void ComPortNotExisting()
{
  HartCommunicationLite communication = new HartCommunicationLite("notExisting");

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

Last edited Feb 25, 2011 at 2:07 PM by schubertj, version 2

Comments

No comments yet.