Core Serial Library in C#  1.2
Public Member Functions | Public Attributes | Properties | List of all members
ZaberAsciiPort Class Reference

Represents a port connected to devices using the ASCII protocol. More...

Inheritance diagram for ZaberAsciiPort:
IZaberPort

Public Member Functions

 ZaberAsciiPort (string portName)
 Initializes a new instance of the ZaberAsciiPort class using the specified port name. More...
 
 ZaberAsciiPort (string portName, int baudRate)
 Initializes a new instance of the ZaberAsciiPort class using the specified port name and baud rate. More...
 
void Close ()
 Closes the underlying SerialPort object's connection. More...
 
void Dispose ()
 Releases the resources used by the underlying SerialPort object. More...
 
void Drain ()
 Purges all input waiting on the input buffer, and attemps to drain all incoming data before returning. More...
 
List< IZaberAxisFindAxes ()
 Queries the port to find all connected axes. More...
 
List< ZaberAsciiDeviceFindDevices ()
 Queries the port to find all connected devices. More...
 
void Open ()
 Opens a new serial port connection. More...
 
AsciiReply Read ()
 Reads a reply from a device. More...
 
void Write (AsciiCommand command)
 Sends a command to the port's devices. More...
 
void Write (string command)
 Writes a command string to the port. More...
 

Public Attributes

const int InfiniteTimeout = System.IO.Ports.SerialPort.InfiniteTimeout
 Indicates that no time-out should occur. More...
 

Properties

int BaudRate [get]
 Gets the serial baud rate. More...
 
bool IsOpen [get]
 Whether the port is open. More...
 
string PortName [get]
 The name of the port. More...
 
int ReadTimeout [get, set]
 The number of milliseconds before a time-out occurrs when a read operation does not finish. More...
 

Detailed Description

Represents a port connected to devices using the ASCII protocol.

Constructor & Destructor Documentation

ZaberAsciiPort ( string  portName)
inline

Initializes a new instance of the ZaberAsciiPort class using the specified port name.

Parameters
portNameThe port to use (for example, COM1).
Exceptions
System.IO.IOExceptionThe specified port could not be found or opened.
ZaberAsciiPort ( string  portName,
int  baudRate 
)
inline

Initializes a new instance of the ZaberAsciiPort class using the specified port name and baud rate.

Parameters
portNameThe port to use (for example, COM1).
baudRateThe baud rate.
Exceptions
ArgumentExceptionportName is either null, or does not begin with "COM".

Member Function Documentation

void Close ( )
inline

Closes the underlying SerialPort object's connection.

This method will only try to close the port if it is open. Attempting to close an already-closed port will do nothing.

Implements IZaberPort.

void Dispose ( )
inline

Releases the resources used by the underlying SerialPort object.

void Drain ( )
inline

Purges all input waiting on the input buffer, and attemps to drain all incoming data before returning.

This method will block until there is a 100ms period of silence in serial communication, guaranteeing that the next time Read() is called, it will receive a full message sent by the device some time after the call to Drain().

This method is intended to be used when many commands have been sent without receiving any replies. If the user must suddenly read a reply to a certain command and has not been receiving replies otherwise, this method will allow them to immediately read the next incoming reply.

Do not use this method in any setting where a serial line may never be quiet for over 100ms, as it may block forever. Some examples of such a setup are multiple devices chained together being polled constantly for position, or at least one device connected with move tracking enabled.

Exceptions
InvalidOperationExceptionThe specified port is not open.

Implements IZaberPort.

List<IZaberAxis> FindAxes ( )
inline

Queries the port to find all connected axes.

This method will only find axes which respond at the specified baud rate and protocol.

Returns
A list of connected axes.

Implements IZaberPort.

List<ZaberAsciiDevice> FindDevices ( )
inline

Queries the port to find all connected devices.

This method will only find devices which respond at the specified baud rate and protocol.

In general, it is recommended to use FindAxes() to get all of the axes connected to a port. There are plenty of good reasons for getting a list of devices instead, but we encourage sending movement commands to individual axes, even if the device has only one axis. In any case, communication with devices should be done in terms of the device's axes, which can be done from FindDevices() like so:

// Home all connected devices' first axes.
foreach (ZaberAsciiDevice device in port.FindDevices())
{
device.GetAxis(1).Home();
}
Returns
A list of connected devices.
void Open ( )
inline

Opens a new serial port connection.

This method closes and re-opens the port if the port is already open.

Exceptions
UnauthorizedAccessExceptionAccess is denied to the port, or the current process or another process on the system already has the specified COM port open.
System.IO.IOExceptionAn attempt to open the port failed. Often this is caused by a port name being incorrect, or a port being disconnected.

Implements IZaberPort.

AsciiReply Read ( )
inline

Reads a reply from a device.

Returns
The reply read.
Exceptions
InvalidOperationExceptionThe specified port is not open.
TimeoutExceptionNo bytes were available to read.
void Write ( AsciiCommand  command)
inline

Sends a command to the port's devices.

Parameters
commandThe command to be sent.
Exceptions
ArgumentNullExceptionThe command passed is null.
InvalidOperationExceptionThe specified port is not open.
void Write ( string  command)
inline

Writes a command string to the port.

This method checks whether the command passed starts with '/' and ends with '\n', and adds them if they are absent.

Parameters
commandA string to be sent.
Exceptions
ArgumentNullExceptionThe command passed is null.
InvalidOperationExceptionThe specified port is not open.

Member Data Documentation

const int InfiniteTimeout = System.IO.Ports.SerialPort.InfiniteTimeout

Indicates that no time-out should occur.

Property Documentation

int BaudRate
get

Gets the serial baud rate.

bool IsOpen
get

Whether the port is open.

string PortName
get

The name of the port.

int ReadTimeout
getset

The number of milliseconds before a time-out occurrs when a read operation does not finish.

This property allows you to set the read time-out value. The time-out can be set to any value greater than zero, or set to -1, in which case no time-out occurrs. -1 is the default.


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