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

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

Inheritance diagram for ZaberBinaryPort:
IZaberPort

Public Member Functions

 ZaberBinaryPort (string portName)
 Initializes a new instance of the ZaberBinaryPort class using the specified port name. 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...
 
void Open ()
 Opens a new serial port connection. More...
 
BinaryReply Read ()
 Reads a reply from a device. More...
 
void Write (BinaryCommand command)
 Sends a command to the port's devices. More...
 
void Write (byte[] command)
 Writes an array of bytes to the port. More...
 

Public Attributes

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

Properties

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 binary protocol.

Constructor & Destructor Documentation

ZaberBinaryPort ( string  portName)
inline

Initializes a new instance of the ZaberBinaryPort 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.

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.

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.

BinaryReply 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 ( BinaryCommand  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 ( byte[]  command)
inline

Writes an array of bytes to the port.

This method will always write the first six bytes of command to the port. In order to behave as intended, the last four bytes must encode the desired data in a little-endian representation, as specified by Zaber's Binary Protocol Manual.

Parameters
commandAn array of "raw" bytes 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

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: