Metratec devices library 3.1.1.0
Public Member Functions | Properties | List of all members
CommunicationInterfaces.SerialInterface Class Reference

The Serial / COM version of the interface used for communication. More...

Inheritance diagram for CommunicationInterfaces.SerialInterface:
CommunicationInterfaces.ICommunicationInterface

Public Member Functions

 SerialInterface (int baudrate, string COMPort)
 The constructor.
 
override string ToString ()
 Returns a string that represents the current object.
 
void Connect ()
 The method to connect the communication interface.
 
void Disconnect ()
 The method used to close the connection to the reader.
 
void Send (byte[] data, int offset, int count)
 Method to write a byte-array to the device (e.g. a converted binary file)
 
void SendCommand (string data)
 The method used to send data to the reader.
 
byte[] Read (int count)
 Method to read a stream of bytes from device.
 
string ReadResponse ()
 The method used to synchronously read data from the reader.
 
- Public Member Functions inherited from CommunicationInterfaces.ICommunicationInterface
void Connect ()
 The method to connect the communication interface.
 
void Disconnect ()
 The method to close the communication interface.
 
void Send (byte[] data, int offset, int count)
 Method to write a byte-array to the device (e.g. a binary file)
 
void Send (byte[] data)
 Method to write a byte-array to the device (e.g. a binary file)
 
void Send (string data)
 Method to write a string to the device.
 
void SendCommand (string command)
 The method used to send a command to the reader.
 
byte[] Read (int count)
 Method to read a stream of bytes from device.
 
string ReadResponse ()
 The method used to synchronously read a reader response.
 

Properties

int BaudRate [get, set]
 The communication baud rate.
 
int ReceiveTimeout [get, set]
 The communication receive timeout.
 
string NewlineString [get, set]
 The communication new line string.
 
bool DataAvailable [get]
 Indicates whether data is available for reading.
 
bool IsConnected [get]
 Returns if the connection is established.
 
- Properties inherited from CommunicationInterfaces.ICommunicationInterface
int ReceiveTimeout [get, set]
 The communication receive timeout.
 
int BaudRate [get, set]
 The communication baud rate.
 
string NewlineString [get, set]
 The communication new line string.
 
bool DataAvailable [get]
 Indicates whether data is available for reading.
 
bool IsConnected [get]
 Connection flag.
 

Detailed Description

The Serial / COM version of the interface used for communication.

Constructor & Destructor Documentation

◆ SerialInterface()

CommunicationInterfaces.SerialInterface.SerialInterface ( int  baudrate,
string  COMPort 
)

The constructor.

Parameters
baudrateThe baud rate that the device uses
COMPortThe name of the COM Port that the device is attached to - e.g. "COM5"

Member Function Documentation

◆ Connect()

void CommunicationInterfaces.SerialInterface.Connect ( )

The method to connect the communication interface.

Exceptions
T:System.InvalidOperationExceptionThrown when the serial port could not be set up (e.g. wrong parameters, insufficient permissions, invalid port state).

Implements CommunicationInterfaces.ICommunicationInterface.

◆ Disconnect()

void CommunicationInterfaces.SerialInterface.Disconnect ( )

The method used to close the connection to the reader.

Implements CommunicationInterfaces.ICommunicationInterface.

◆ Read()

byte[] CommunicationInterfaces.SerialInterface.Read ( int  count)

Method to read a stream of bytes from device.

Parameters
countNumber of bytes to read
Returns
The bytes read

Implements CommunicationInterfaces.ICommunicationInterface.

◆ ReadResponse()

string CommunicationInterfaces.SerialInterface.ReadResponse ( )

The method used to synchronously read data from the reader.

Returns
The string read - without the trailing newline character(s)
Exceptions
T:System.TimeoutExceptionThrown when no answer is received for more than 400ms.
T:System.ObjectDisposedExceptionThrown when the underlying function reports a broken stream

Implements CommunicationInterfaces.ICommunicationInterface.

◆ Send()

void CommunicationInterfaces.SerialInterface.Send ( byte[]  data,
int  offset,
int  count 
)

Method to write a byte-array to the device (e.g. a converted binary file)

Parameters
dataThe overall byte-array of data
offsetThe starting address in the array
countThe number of characters to write

Implements CommunicationInterfaces.ICommunicationInterface.

◆ SendCommand()

void CommunicationInterfaces.SerialInterface.SendCommand ( string  data)

The method used to send data to the reader.

Parameters
dataThe data / command sent to the reader
Exceptions
T:System.ArgumentNullExceptionThrown when the specified data is null.
T:System.InvalidOperationExceptionThrown when an exception occurs when trying to access the port (e.g. port closed, timeout).
T:System.ObjectDisposedExceptionThrown when the underlying function reports a broken stream

Implements CommunicationInterfaces.ICommunicationInterface.

◆ ToString()

override string CommunicationInterfaces.SerialInterface.ToString ( )

Returns a string that represents the current object.

Returns
A string that represents the current object.

Property Documentation

◆ BaudRate

int CommunicationInterfaces.SerialInterface.BaudRate
getset

The communication baud rate.

Exceptions
T:System.InvalidOperationExceptionThrown in case baud rate setting did not work

Implements CommunicationInterfaces.ICommunicationInterface.

◆ DataAvailable

bool CommunicationInterfaces.SerialInterface.DataAvailable
get

Indicates whether data is available for reading.

Exceptions
T:System.ObjectDisposedExceptionThrown when the underlying function reports a broken stream

Implements CommunicationInterfaces.ICommunicationInterface.

◆ IsConnected

bool CommunicationInterfaces.SerialInterface.IsConnected
get

Returns if the connection is established.

Returns
True if the connection is established

Implements CommunicationInterfaces.ICommunicationInterface.

◆ NewlineString

string CommunicationInterfaces.SerialInterface.NewlineString
getset

The communication new line string.

Implements CommunicationInterfaces.ICommunicationInterface.

◆ ReceiveTimeout

int CommunicationInterfaces.SerialInterface.ReceiveTimeout
getset

The communication receive timeout.

Exceptions
T:System.InvalidOperationExceptionThrown in case baud rate setting did not work

Implements CommunicationInterfaces.ICommunicationInterface.


The documentation for this class was generated from the following file: