Table of Contents

Class ComPort

Namespace
NominalSystems.External
Assembly
NominalSystems.External.dll

The base class for all ComPort Integrations

public class ComPort
Inheritance
ComPort

Constructors

ComPort()

Default constructor for the software

public ComPort()

Fields

USBBaudRate

The BaudRate of the Serial Port Connection. The value is less than zero if unconfigured or the close function has been called

public int USBBaudRate

Field Value

int

USBPortName

The COMPort the SerialPort has connected to. The Length is zero when unconfigured or the close function has been called

public string USBPortName

Field Value

string

Properties

IsCDHolding

Boolean to store the status of CDHolding for the ComPort, true if Carrier detected

public bool IsCDHolding { get; }

Property Value

bool

IsDsrHolding

Boolean to store the status of DsrHolding, true if a Data Set Ready signal has been sent to the port

public bool IsDsrHolding { get; }

Property Value

bool

IsOpen

Boolean to store the status of the ComPort, true is Open

public bool IsOpen { get; }

Property Value

bool

NumBytesInBuffer

The Number of Bytes available in the read buffer

public int NumBytesInBuffer { get; }

Property Value

int

Methods

Close()

Called to close a Serial Port connection

public bool Close()

Returns

bool

Returns if closing the comport was successful

Flush()

Called to clear the ComPort buffer

public void Flush()

ListComPorts()

Called to list ComPorts that can be used for a connection

public static string[] ListComPorts()

Returns

string[]

An array of available Serial Ports as a String

Open(string, int)

Called to Create and open a Serial Port connection

public bool Open(string portName, int baudRate)

Parameters

portName string

The name of the ComPort to open

baudRate int

The baud rate of the connection

Returns

bool

Returns if opening the comport was successful

PublishByte(byte, bool)

Called to write a Byte to the ComPort

public void PublishByte(byte bytePayload, bool useLengthHeader = false)

Parameters

bytePayload byte

The Byte to write to the ComPort

useLengthHeader bool

Enables sending the size of the Byte before the value of the Byte

PublishByteArray(byte[], bool)

Called to write a Byte array to the ComPort

public void PublishByteArray(byte[] byteArrayPayload, bool useLengthHeader = false)

Parameters

byteArrayPayload byte[]

The Byte array to write to the ComPort

useLengthHeader bool

Enables sending the length of the Byte array before the array

PublishDouble(double, bool)

Called to write a Double to the ComPort

public void PublishDouble(double doublePayload, bool useLengthHeader = false)

Parameters

doublePayload double

The Double to write to the ComPort

useLengthHeader bool

Enables sending the size of the Double before the value of the Double

PublishDoubleArray(double[], bool)

Called to write an array of Doubles to the ComPort

public void PublishDoubleArray(double[] doubleArrayPayload, bool useLengthHeader = true)

Parameters

doubleArrayPayload double[]

The Double array to write to the ComPort

useLengthHeader bool

Enables sending the size of the Double array before the values of the Double array. Required for the matching Receive functions

PublishFloat(float, bool)

Called to write a Float to the ComPort

public void PublishFloat(float floatPayload, bool useLengthHeader = false)

Parameters

floatPayload float

The Float to write to the ComPort

useLengthHeader bool

Enables sending the size of the Float before the value of the Float as a byte array

PublishFloatArray(float[], bool, bool)

Called to write a Float array to the ComPort

public void PublishFloatArray(float[] floatArrayPayload, bool useLengthHeader = false, bool useArrayLengthHeader = true)

Parameters

floatArrayPayload float[]

The Float array to write to the ComPort

useLengthHeader bool

Enables sending the size of the Float before the value of the Float as a byte array

useArrayLengthHeader bool

Enables sending the length of the Float array before the array. Required for the matching Receive functions

PublishInt(int, bool)

Called to write a Integer to the ComPort

public void PublishInt(int intPayload, bool useLengthHeader = false)

Parameters

intPayload int

The Integer to write to the ComPort

useLengthHeader bool

Enables sending the size of the Integer before the value of the Integer

PublishIntArray(int[], bool, bool)

Called to write a Integer array to the ComPort

public void PublishIntArray(int[] integerArrayPayload, bool useLengthHeader = false, bool useArrayLengthHeader = true)

Parameters

integerArrayPayload int[]

The Integer array to write to the ComPort

useLengthHeader bool

Enables sending the size of the Integer before the value of the Integer as a byte array

useArrayLengthHeader bool

Enables sending the length of the Integer array before the array. Required for the matching Receive functions

PublishLine(string, bool)

Called to write a String to the ComPort with a NewLine terminator included after the String

public void PublishLine(string stringPayload, bool useLengthHeader = false)

Parameters

stringPayload string

The String to write to the ComPort

useLengthHeader bool

Enables sending the length of the String with the NewLine terminator included before the String as Bytes

PublishString(string, bool)

Called to write a String to the ComPort

public void PublishString(string stringPayload, bool useLengthHeader = false)

Parameters

stringPayload string

The String to write to the ComPort

useLengthHeader bool

Enables sending the length of the String before the String as Bytes

PublishStringArray(string[], bool, bool)

Called to write an array of Strings to the ComPort

public void PublishStringArray(string[] stringArrayPayload, bool useLengthHeader = true, bool useArrayLengthHeader = true)

Parameters

stringArrayPayload string[]

The String array to write to the ComPort

useLengthHeader bool

Enables sending the length of the String before each String as Bytes. Required for the matching Receive functions

useArrayLengthHeader bool

Enables sending the length of the String array before the array. Required for the matching Receive functions

PublishStringLineArray(string[], bool, bool)

Called to write an array of Strings with a NewLine terminator included after each String

public void PublishStringLineArray(string[] stringArrayPayload, bool useLengthHeader = false, bool useArrayLengthHeader = true)

Parameters

stringArrayPayload string[]

The String array to write to the ComPort

useLengthHeader bool

Enables sending the length of the String with the NewLine terminator included before each String as Bytes

useArrayLengthHeader bool

Enables sending the length of the String array before the array. Required for the matching Receive functions

ReceiveAll()

Called to read the entire contents of the ComPorts buffer

public string ReceiveAll()

Returns

string

The read data as a String

ReceiveByte()

Called to read a Byte from the ComPort buffer

public byte ReceiveByte()

Returns

byte

The read Byte

ReceiveByte(int)

Called to read a Byte from the ComPort buffer with a specified timeout

public byte ReceiveByte(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

byte

The read Byte

ReceiveByteArray(int)

Called to read the ComPort buffer as a Byte array

public byte[] ReceiveByteArray(int NumBytesToRead = -1)

Parameters

NumBytesToRead int

The number of Bytes to read. If -1, all available bytes are read

Returns

byte[]

The read Byte array

ReceiveByteArray(int, int)

Called to read the ComPort buffer as a Byte array with a specified timeout

public byte[] ReceiveByteArray(int NumBytesToRead, int timeout)

Parameters

NumBytesToRead int

The number of Bytes to read. If -1, all available bytes are read

timeout int

[ms] The specified timeout

Returns

byte[]

The read Byte array

ReceiveDouble()

Called to read a Double from the ComPorts buffer

public double ReceiveDouble()

Returns

double

The read data as a Double

ReceiveDouble(int)

Called to read a Double from the ComPorts buffer with a specified timeout

public double ReceiveDouble(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

double

The read data as a Double

ReceiveDoubleArray()

Called to read a Double array from the ComPorts buffer

public double[] ReceiveDoubleArray()

Returns

double[]

The read data as a Double array

ReceiveDoubleArray(int)

Called to read a Double array from the ComPorts buffer

public double[] ReceiveDoubleArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

double[]

The read data as a Double array

ReceiveFloat()

Called to read a Float from the ComPorts buffer

public float ReceiveFloat()

Returns

float

The read data as a Float

ReceiveFloat(int)

Called to read a Float from the ComPorts buffer with a specified timeout

public float ReceiveFloat(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

float

The read data as a Float

ReceiveFloatArray()

Called to read a Float array from the ComPorts buffer

public float[] ReceiveFloatArray()

Returns

float[]

The read data as a Float array

ReceiveFloatArray(int)

Called to read a Float array from the ComPorts buffer with a specified timeout

public float[] ReceiveFloatArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

float[]

The read data as a Float array

ReceiveInt()

Called to read a Integer from the ComPorts buffer

public int ReceiveInt()

Returns

int

The read data as a Integer

ReceiveInt(int)

Called to read a Integer from the ComPorts buffer with a specified timeout

public int ReceiveInt(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

int

The read data as a Integer

ReceiveIntArray()

Called to read a Integer array from the ComPorts buffer

public int[] ReceiveIntArray()

Returns

int[]

The read data as a Integer array

ReceiveIntArray(int)

Called to read a Integer array from the ComPorts buffer

public int[] ReceiveIntArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

int[]

The read data as a Integer array

ReceiveLine()

Called to read the ComPorts buffer until the NewLine Value

public string ReceiveLine()

Returns

string

The read data as a String

ReceiveLine(int)

Called to read the ComPorts buffer until the NewLine Value with a specified timeout

public string ReceiveLine(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

string

The read data as a String

ReceiveLineArray()

Called to read an array of Strings with a NewLine terminator from the ComPorts buffer

public string[] ReceiveLineArray()

Returns

string[]

The read data as a String array

ReceiveLineArray(int)

Called to read an array of Strings with a NewLine terminator from the ComPorts buffer

public string[] ReceiveLineArray(int timeout)

Parameters

timeout int

[ms] The specified timeout

Returns

string[]

The read data as a String array

ReceiveStringUntil(string)

Called to read the ComPorts buffer until a designated terminator

public string ReceiveStringUntil(string terminator)

Parameters

terminator string

The terminator to read the buffer to

Returns

string

The read data as a String

ReceiveStringUntil(string, int)

Called to read the ComPorts buffer until a designated terminator with a specified timeout

public string ReceiveStringUntil(string terminator, int timeout)

Parameters

terminator string

The terminator to read the buffer to

timeout int

[ms] The specified timeout

Returns

string

The read data as a String