Buffer Interface
Classes | Public Member Functions | Static Public Member Functions | List of all members
CLComm::CLAllSerial Class Reference

Wrapper around the Camera Link serial port API. More...

#include <CLAllSerial.hpp>

Classes

struct  PrivateData
 

Public Member Functions

 CLAllSerial (BFVOID)
 
 ~CLAllSerial (BFVOID)
 
BFVOID serialInit (const CLUINT32 SerialIndex)
 
BFVOID bfSerialInit (const CLUINT32 BoardIndex)
 
BFVOID bfSWConnectorSerialInit (const CLUINT32 Switch, const CLUINT32 Connector)
 
BFVOID serialClose (BFVOID)
 
BFBOOL hasInit (BFVOID) const
 
BFBOOL hasBFSerial (BFVOID) const
 
CLUINT32 getSerialIndex (void) const
 
CLUINT32 getBoardNumber (void) const
 
void getSWConnector (CLUINT32 &Switch, CLUINT32 &Connector) const
 
CLUINT32 serialWrite (std::string const &Message, const CLUINT32 SerialTimeout)
 
CLUINT32 serialWrite (std::vector< CLINT8 > const &Buffer, const CLUINT32 SerialTimeout)
 
CLUINT32 serialWrite (const CLINT8 *const Buffer, const BFSIZET BufferLen, const CLUINT32 SerialTimeout)
 
std::string serialRead (const CLUINT32 NumBytesToRead, const CLUINT32 SerialTimeout)
 
CLUINT32 serialRead (std::vector< CLINT8 > &Buffer, const CLUINT32 ReadLen, const CLUINT32 SerialTimeout) const
 
CLUINT32 serialRead (CLINT8 *const Buffer, const CLUINT32 BufferSize, const CLUINT32 SerialTimeout) const
 
BFVOID flushPort (BFVOID)
 
CLUINT32 getNumBytesAvail (BFVOID) const
 
CLUINT32 getSupportedBaudRates (BFVOID) const
 
BFVOID setBaudRate (const CLUINT32 BaudRate)
 
BFVOID bfSerialSettings (const CLUINT32 BaudRate, const DataBits dataBits, const Parity parity, const StopBits stopBits)
 
std::string bfSerialRead (const CLUINT32 MaxBytesToRead) const
 
CLUINT32 bfSerialRead (std::vector< BFCHAR > &Buffer, const CLUINT32 MaxBytesToRead) const
 
CLUINT32 bfSerialRead (PBFCHAR Buffer, const CLUINT32 MaxBytesToRead) const
 
BFVOID bfSerialCancelRead (BFVOID)
 
CLUINT32 bfGetBaudRate (BFVOID) const
 

Static Public Member Functions

static std::string getErrorText (const CLINT32 ErrorCode)
 
static BFBOOL getErrorText (const CLINT32 ErrorCode, BFCHAR *const hBuf, BFSIZET *const pSize)
 
static CLUINT32 getNumPorts (BFVOID)
 
static BFVOID getPortInfo (const CLUINT32 SerialIndex, std::string &ManufacturerName, std::string &PortID, CLUINT32 &Version)
 
static BFBOOL getPortInfo (const CLUINT32 SerialIndex, BFCHAR *const ManufacturerName, BFSIZET *const pManNameSize, BFCHAR *const PortID, BFSIZET *const pPortIdSize, CLUINT32 &Version)
 
static BFVOID bfsVersion (CLUINT32 &majorVersionRef, CLUINT32 &minorVersionRef)
 

Detailed Description

Wrapper around the Camera Link serial port API.

Both the CLAllSerial.h and BFSerial.h interfaces are exposed, although the BitFlow serial functions will only be operable for ports on BitFlow boards.

Constructor & Destructor Documentation

CLAllSerial::CLAllSerial ( BFVOID  )

Initialize a new CLComm::CLAllSerial instance.

39  : m_pd (*new PrivateData)
40 { }
CLAllSerial::~CLAllSerial ( BFVOID  )

Clean up the CLAllSerial instance and its resources.

References serialClose().

46 {
47  serialClose();
48  delete &m_pd;
49 }
BFVOID serialClose(BFVOID)
Definition: CLAllSerial.cpp:343

Member Function Documentation

CLUINT32 CLAllSerial::bfGetBaudRate ( BFVOID  ) const

Return the current baud-rate of the CLSerial port.

Returns
The current port baud rate, of the following options:
Exceptions
BFCLException- Thrown if an error occurs while retrieving the baud rate.

References BFCL_ERROR_SERNOTFOUND, CLComm::BFCLException::check(), clBFGetBaudRate(), and hasBFSerial().

715 {
716  if (!hasBFSerial())
718 
719  unsigned int baudRate;
720  BFCLException::check( clBFGetBaudRate(m_pd.bfSerRef, &baudRate) );
721  return baudRate;
722 }
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
BFBOOL hasBFSerial(BFVOID) const
Definition: CLAllSerial.cpp:376
BFSERIALEXPORT int BFSERIALCC clBFGetBaudRate(void *serBFRef, unsigned int *baudRate)
#define BFCL_ERROR_SERNOTFOUND
Definition: BFSerial.h:72
BFVOID CLAllSerial::bfSerialCancelRead ( BFVOID  )

Cancel the active call to clBFSerialRead.

Exceptions
BFCLException- Thrown if an error occurs while canceling the read.

References BFCL_ERROR_SERNOTFOUND, CLComm::BFCLException::check(), clBFSerialCancelRead(), and hasBFSerial().

692 {
693  if (!hasBFSerial())
695 
696  BFCLException::check( clBFSerialCancelRead(m_pd.bfSerRef) );
697 }
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
BFBOOL hasBFSerial(BFVOID) const
Definition: CLAllSerial.cpp:376
BFSERIALEXPORT int BFSERIALCC clBFSerialCancelRead(void *serBFRef)
#define BFCL_ERROR_SERNOTFOUND
Definition: BFSerial.h:72
BFVOID CLAllSerial::bfSerialInit ( const CLUINT32  BoardIndex)

Alternate initializer, initializing from a BitFlow board index, rather than from the CLSerial port index, which may or may not directly correspond.

Parameters
[in]BoardIndex- The index of the BitFlow board whos Camera Link serial port should be opened.
Exceptions
BiException- Thrown if an error occurs opening the frame grabber.
BFCLException- Thrown if an error occurs initializing the port.

References BiTypeAny, BrdOpenOptions, BiException::check(), CLComm::BFCLException::check(), CL_ERR_NO_ERR, clBFGetSerialRefFromBoardHandle(), clBFSerialInitFromBoardHandle(), clSerialClose(), and serialClose().

253 {
254  serialClose();
255 
256  // Open the BitFlow board.
257  Bd hBoard;
258  BiException::check(0, BiBrdOpenEx(BiTypeAny, BoardIndex, &hBoard, BrdOpenOptions) );
259 
260  // Initialize the CL serial port.
261  hSerRef clSerRef;
262  CLINT32 rc = clBFSerialInitFromBoardHandle(hBoard, &clSerRef);
263  if (CL_ERR_NO_ERR != rc)
264  {
265  BiBrdClose(hBoard);
267  }
268 
269  // Get the serial reference.
270  BFVOID *bfSerRef;
271  rc = clBFGetSerialRefFromBoardHandle(hBoard, &bfSerRef);
272  if (BF_OK != rc)
273  {
274  clSerialClose(clSerRef);
275  BiBrdClose(hBoard);
277  }
278 
279  // Store the CLSerial handles.
280  m_pd.clSerRef = clSerRef;
281  m_pd.bfSerRef = bfSerRef;
282  m_pd.hBoard = hBoard;
283 
284  m_pd.boardNumber = BoardIndex;
285 }
#define CL_ERR_NO_ERR
Definition: clallserial.h:113
BFVOID serialClose(BFVOID)
Definition: CLAllSerial.cpp:343
Definition: CLAllSerial.cpp:8
CLALLSERIALEXPORT void CLALLSERIALCC clSerialClose(hSerRef serialRef)
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
void * hSerRef
Definition: clallserial.h:69
static void check(Bd hBoard, const BFU32 error)
Definition: BFException.cpp:306
#define BiTypeAny
Definition: BiDef.h:33
BFSERIALEXPORT int BFSERIALCC clBFGetSerialRefFromBoardHandle(Bd hBoard, void **serBFRefPtr)
void *** Bd
Definition: BFType.h:88
void BFVOID
Definition: BFTypeNT.h:32
int CLINT32
Definition: clallserial.h:74
BFSERIALEXPORT int BFSERIALCC clBFSerialInitFromBoardHandle(Bd hBoard, void **serialRefPtr)
std::string CLAllSerial::bfSerialRead ( const CLUINT32  MaxBytesToRead) const

Reads data from the serial device. This method will wait efficiently for data to become available on the port, then return that length of data. No more than MaxBytesToRead will be read at a time, but the length read may be less than that.

Parameters
[in]MaxBytesToRead- The maximum number of bytes to be read.
Returns
The data read, formatted as a null-terminated string.
Exceptions
BFCLException- Thrown if an error occurs while reading the data.

References BFCL_ERROR_SERNOTFOUND, CLComm::BFCLException::check(), and hasBFSerial().

Referenced by bfSerialRead().

634 {
635  if (!hasBFSerial())
637 
638  std::vector<BFCHAR> buf (MaxBytesToRead);
639  const CLUINT32 bytesRead = bfSerialRead(buf.data(), MaxBytesToRead);
640  return std::string (buf.data(), bytesRead);
641 }
unsigned int CLUINT32
Definition: clallserial.h:80
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
std::string bfSerialRead(const CLUINT32 MaxBytesToRead) const
Definition: CLAllSerial.cpp:633
BFBOOL hasBFSerial(BFVOID) const
Definition: CLAllSerial.cpp:376
#define BFCL_ERROR_SERNOTFOUND
Definition: BFSerial.h:72
CLUINT32 CLAllSerial::bfSerialRead ( std::vector< BFCHAR > &  Buffer,
const CLUINT32  MaxBytesToRead 
) const

Reads data from the serial device. This method will wait efficiently for data to become available on the port, then return that length of data. Returns the number of bytes read.

Parameters
[out]Buffer- Output buffer for the data read, This will be resized to fit the data read, if necessary.
[in]MaxBytesToRead- The maximum number of bytes to be read.
Returns
The number of bytes read from the serial port.
Exceptions
BFCLException- Thrown if an error occurs while reading the data.

References BFCL_ERROR_SERNOTFOUND, bfSerialRead(), CLComm::BFCLException::check(), and hasBFSerial().

655 {
656  if (!hasBFSerial())
658 
659  if (MaxBytesToRead > Buffer.size())
660  Buffer.resize(MaxBytesToRead);
661 
662  return bfSerialRead(Buffer.data(), MaxBytesToRead);
663 }
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
std::string bfSerialRead(const CLUINT32 MaxBytesToRead) const
Definition: CLAllSerial.cpp:633
BFBOOL hasBFSerial(BFVOID) const
Definition: CLAllSerial.cpp:376
#define BFCL_ERROR_SERNOTFOUND
Definition: BFSerial.h:72
CLUINT32 CLAllSerial::bfSerialRead ( PBFCHAR  Buffer,
const CLUINT32  MaxBytesToRead 
) const

Reads data from the serial device. This method will wait efficiently for data to become available on the port, then return that length of data. Returns the number of bytes read.

Parameters
[out]Buffer- Output buffer for the data read.
[in]MaxBytesToRead- The maximum number of bytes to be read. Buffer should be no smaller than this byte size.
Returns
The number of bytes read from the serial port.
Exceptions
BFCLException- Thrown if an error occurs while reading the data.

References BFCL_ERROR_SERNOTFOUND, CLComm::BFCLException::check(), clBFSerialRead(), and hasBFSerial().

677 {
678  if (!hasBFSerial())
680 
681  unsigned int bufferSize = MaxBytesToRead;
682  BFCLException::check( clBFSerialRead(m_pd.bfSerRef, Buffer, &bufferSize) );
683  return bufferSize;
684 }
BFSERIALEXPORT int BFSERIALCC clBFSerialRead(void *serBFRef, char *buffer, unsigned int *bufferSize)
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
BFBOOL hasBFSerial(BFVOID) const
Definition: CLAllSerial.cpp:376
#define BFCL_ERROR_SERNOTFOUND
Definition: BFSerial.h:72
BFVOID CLAllSerial::bfSerialSettings ( const CLUINT32  BaudRate,
const DataBits  dataBits,
const Parity  parity,
const StopBits  stopBits 
)

Set the BF CLSerial settings.

Parameters
[in]BaudRate- The baud rate to set, of the following options:
[in]dataBits- The serial port data bits to use, of the following options:
[in]parity- The serial port parity to use, of the following options:
[in]stopBits- The serial port stop bits to use, of the following options:
Exceptions
BFCLException- Thrown if an error occurs while setting the settings.

References BFCL_ERROR_SERNOTFOUND, CLComm::BFCLException::check(), clBFSerialSettings(), and hasBFSerial().

615 {
616  if (!hasBFSerial())
618 
619  BFCLException::check( clBFSerialSettings(m_pd.bfSerRef, BaudRate, dataBits, parity, stopBits) );
620 }
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
BFSERIALEXPORT int BFSERIALCC clBFSerialSettings(void *serBFRef, unsigned int baudRate, unsigned int dataBits, unsigned int parity, unsigned int stopBits)
BFBOOL hasBFSerial(BFVOID) const
Definition: CLAllSerial.cpp:376
#define BFCL_ERROR_SERNOTFOUND
Definition: BFSerial.h:72
BFVOID CLAllSerial::bfsVersion ( CLUINT32 majorVersionRef,
CLUINT32 minorVersionRef 
)
static

Retrieve the version of the loaded BFS library.

Parameters
[out]majorVersionRef- Ouput integer for the major part of the version number.
[out]minorVersionRef- Ouput integer for the minor part of the version number.
Exceptions
BFCLException- Thrown if an error occurs retrieving the version number.

References BFSVersion(), and CLComm::BFCLException::check().

210 {
211  BFCLException::check( BFSVersion(&majorVersionRef, &minorVersionRef) );
212 }
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
BFSERIALEXPORT BFRC BFSERIALCC BFSVersion(PBFU32 pMajorVersion, PBFU32 pMinorVersion)
BFVOID CLAllSerial::bfSWConnectorSerialInit ( const CLUINT32  Switch,
const CLUINT32  Connector 
)

Alternate initializer, initializing from a BitFlow board swith and connector, rather than from the CLSerial port index, which may or may not directly correspond.

Parameters
[in]Switch- The switch setting on the BitFlow board whos Camera Link serial port should be opened.
[in]Connector- The connector index to open on the board.
Exceptions
BiException- Thrown if an error occurs opening the frame grabber.
BFCLException- Thrown if an error occurs initializing the port.

References BI_CIERROR_CIBRDOPEN, BI_CIERROR_CISYSBOARDFINDSWCONNECTOR, BrdOpenOptions, BiException::check(), CLComm::BFCLException::check(), CL_ERR_NO_ERR, clBFGetSerialRefFromBoardHandle(), clBFSerialInitFromBoardHandle(), clSerialClose(), and serialClose().

298 {
299  serialClose();
300 
301  // Open the BitFlow board.
302  CiENTRY entry;
303  BFRC rc = CiSysBoardFindSWConnector(CISYS_TYPE_ANY, Switch, Connector, &entry);
304  if (BF_OK != rc)
306 
307  Bd hBoard;
308  rc = CiBrdOpen(&entry, &hBoard, BrdOpenOptions);
309  if (BF_OK != rc)
311 
312  // Initialize the CL serial port.
313  hSerRef clSerRef;
314  rc = clBFSerialInitFromBoardHandle(hBoard, &clSerRef);
315  if (CL_ERR_NO_ERR != rc)
316  {
317  CiBrdClose(hBoard);
319  }
320 
321  // Get the serial reference.
322  BFVOID *bfSerRef;
323  rc = clBFGetSerialRefFromBoardHandle(hBoard, &bfSerRef);
324  if (BF_OK != rc)
325  {
326  clSerialClose(clSerRef);
327  CiBrdClose(hBoard);
329  }
330 
331  // Store the CLSerial handles.
332  m_pd.clSerRef = clSerRef;
333  m_pd.bfSerRef = bfSerRef;
334  m_pd.hBoard = hBoard;
335 
336  m_pd.bfSwitch = Switch;
337  m_pd.bfConnector = Connector;
338 }
#define CL_ERR_NO_ERR
Definition: clallserial.h:113
BFVOID serialClose(BFVOID)
Definition: CLAllSerial.cpp:343
Definition: CLAllSerial.cpp:8
CLALLSERIALEXPORT void CLALLSERIALCC clSerialClose(hSerRef serialRef)
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
BFU32 BFRC
Definition: BFType.h:92
Definition: BiError.h:373
void * hSerRef
Definition: clallserial.h:69
static void check(Bd hBoard, const BFU32 error)
Definition: BFException.cpp:306
BFSERIALEXPORT int BFSERIALCC clBFGetSerialRefFromBoardHandle(Bd hBoard, void **serBFRefPtr)
void *** Bd
Definition: BFType.h:88
void BFVOID
Definition: BFTypeNT.h:32
Definition: BiError.h:372
BFSERIALEXPORT int BFSERIALCC clBFSerialInitFromBoardHandle(Bd hBoard, void **serialRefPtr)
BFVOID CLAllSerial::flushPort ( BFVOID  )

Discards any bytes that are available in the input buffer.

Exceptions
BFCLException- Thrown if an error occurs while flushing the serial port.

References CLComm::BFCLException::check(), and clFlushPort().

523 {
524  BFCLException::check( clFlushPort(m_pd.clSerRef) );
525 }
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clFlushPort(hSerRef serialRef)
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
CLUINT32 CLAllSerial::getBoardNumber ( void  ) const

Retrieve the BitFlow board number initialized, or ~CLUINT32(0), if not open or not initialized by the BitFlow board nubmer.

Returns
The BitFlow board number initialized, or ~CLUINT32(0), if not open or not initialized by the serial index.
397 {
398  return m_pd.boardNumber;
399 }
std::string CLAllSerial::getErrorText ( const CLINT32  ErrorCode)
static

Converts an error code to error text which can be displayed in a dialog box or in the standard I/O window.

Parameters
[in]ErrorCode- The code of the error text to retrieve.
Returns
The error text message.
Exceptions
BFCLException- Thrown if an error occurs retrieving the error text.

References BFCL_ERROR_15STOP5DATA, BFCL_ERROR_2STOP5DATA, BFCL_ERROR_BAUDRATE, BFCL_ERROR_BRDNOTFOUND, BFCL_ERROR_BRDOPEN, BFCL_ERROR_BYTES_AVAIL, BFCL_ERROR_DATA_IN, BFCL_ERROR_DATABITS, BFCL_ERROR_FIFO_EN, BFCL_ERROR_FLUSH_PORT, BFCL_ERROR_NOSIGNAL, BFCL_ERROR_NOSTRUC, BFCL_ERROR_NULLPTR, BFCL_ERROR_PARITY, BFCL_ERROR_RCVRFIFO, BFCL_ERROR_SERNOTFOUND, BFCL_ERROR_STOPBITS, BFCL_ERROR_TEMT, BFCL_ERROR_THRE, BFCL_WARN_SIG_CANCEL, CLComm::BFCLException::check(), CL_ERR_BUFFER_TOO_SMALL, clGetErrorText(), and MAX_STRING.

Referenced by getErrorText().

61 {
62  // Check the BitFlow CL error codes, first.
63  switch (ErrorCode)
64  {
65  case BFCL_ERROR_SERNOTFOUND: return "BFSerial error: The serial device was not found.";
66  case BFCL_ERROR_BRDNOTFOUND: return "BFSerial error: There are no R2 boards installed.";
67  case BFCL_ERROR_BRDOPEN: return "BFSerial error: Error opening board.";
68  case BFCL_ERROR_THRE: return "BFSerial error: Transmitter Holding Register not empty (THRE).";
69  case BFCL_ERROR_TEMT: return "BFSerial error: Transmitter not empty (TEMT).";
70  case BFCL_ERROR_FIFO_EN: return "BFSerial error: FIFO's are not enabled.";
71  case BFCL_ERROR_RCVRFIFO: return "BFSerial error: Error in RCVR FIFO.";
72  case BFCL_ERROR_BAUDRATE: return "BFSerial error: Invalid Buad Rate.";
73  case BFCL_ERROR_DATABITS: return "BFSerial error: Invalid number of data bits.";
74  case BFCL_ERROR_PARITY: return "BFSerial error: Invalid parity parameter.";
75  case BFCL_ERROR_15STOP5DATA: return "BFSerial error: To use 1.5 number of stop bits, 5 data bits must be used..";
76  case BFCL_ERROR_2STOP5DATA: return "BFSerial error: Can't use 5 data bits with 2 stop bits.";
77  case BFCL_ERROR_STOPBITS: return "BFSerial error: Invalid number of stop bits.";
78  case BFCL_ERROR_NOSIGNAL: return "BFSerial error: Can't create signal.";
79  case BFCL_ERROR_NOSTRUC: return "BFSerial error: Can't create ref structure.";
80  case BFCL_ERROR_NULLPTR: return "BFSerial error: BFNULL pointer.";
81  case BFCL_ERROR_BYTES_AVAIL: return "BFSerial error: Error getting the number of bytes available in the buffer.";
82  case BFCL_ERROR_FLUSH_PORT: return "BFSerial error: Error flushing the port.";
83  case BFCL_ERROR_DATA_IN: return "BFSerial error: The receive buffer could not be emptied.";
84  case BFCL_WARN_SIG_CANCEL: return "BFSerial warning: BFSerialRead signal was cancelled.";
85  }
86 
87  // Check the CLAllSerial error text function.
88  const char *const manuName = "BitFlow, Inc.";
89 
90  std::vector<CLINT8> buf (MAX_STRING);
91  CLUINT32 bufLen = CLUINT32(buf.size());
92 
93  CLINT32 rc = clGetErrorText(manuName, ErrorCode, buf.data(), &bufLen);
94  if (CL_ERR_BUFFER_TOO_SMALL == rc)
95  {
96  buf.resize(++bufLen);
97  rc = clGetErrorText(manuName, ErrorCode, buf.data(), &bufLen);
98  }
99 
101 
102  buf.push_back(0);
103  return buf.data();
104 }
#define BFCL_ERROR_PARITY
Definition: BFSerial.h:81
#define BFCL_WARN_SIG_CANCEL
Definition: BFSerial.h:93
unsigned int CLUINT32
Definition: clallserial.h:80
#define BFCL_ERROR_BRDOPEN
Definition: BFSerial.h:74
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
#define BFCL_ERROR_BRDNOTFOUND
Definition: BFSerial.h:73
#define BFCL_ERROR_DATABITS
Definition: BFSerial.h:80
#define BFCL_ERROR_15STOP5DATA
Definition: BFSerial.h:82
#define MAX_STRING
Definition: BFType.h:65
#define BFCL_ERROR_TEMT
Definition: BFSerial.h:76
#define BFCL_ERROR_DATA_IN
Definition: BFSerial.h:90
#define BFCL_ERROR_THRE
Definition: BFSerial.h:75
#define BFCL_ERROR_NOSTRUC
Definition: BFSerial.h:86
#define BFCL_ERROR_2STOP5DATA
Definition: BFSerial.h:83
#define BFCL_ERROR_FLUSH_PORT
Definition: BFSerial.h:89
#define BFCL_ERROR_SERNOTFOUND
Definition: BFSerial.h:72
#define BFCL_ERROR_FIFO_EN
Definition: BFSerial.h:77
#define BFCL_ERROR_STOPBITS
Definition: BFSerial.h:84
#define BFCL_ERROR_NULLPTR
Definition: BFSerial.h:87
#define BFCL_ERROR_NOSIGNAL
Definition: BFSerial.h:85
int CLINT32
Definition: clallserial.h:74
#define CL_ERR_BUFFER_TOO_SMALL
Definition: clallserial.h:114
#define BFCL_ERROR_RCVRFIFO
Definition: BFSerial.h:78
#define BFCL_ERROR_BAUDRATE
Definition: BFSerial.h:79
#define BFCL_ERROR_BYTES_AVAIL
Definition: BFSerial.h:88
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetErrorText(const CLINT8 *manuName, CLINT32 errorCode, CLINT8 *errorText, CLUINT32 *errorTextSize)
BFBOOL CLAllSerial::getErrorText ( const CLINT32  ErrorCode,
BFCHAR *const  hBuf,
BFSIZET *const  pSize 
)
static

Converts an error code to error text which can be displayed in a dialog box or in the standard I/O window.

Parameters
[in]ErrorCode- The code of the error text to retrieve.
[out]hBuf- The string buffer pointer, filled with as much data as is possible. May be nullptr.
[in,out]pSize- As input, the size of hBuf. As output, the buffer size requried.
Returns
True on success, false otherwise.
Exceptions
BFCLException- Thrown if an error occurs retrieving the error text.

References getErrorText().

118 {
119  return BufInHelpers::set_str(getErrorText(ErrorCode), hBuf, pSize);
120 }
static std::string getErrorText(const CLINT32 ErrorCode)
Definition: CLAllSerial.cpp:60
CLUINT32 CLAllSerial::getNumBytesAvail ( BFVOID  ) const

Returns the number of bytes that are received, but not yet read out of the the serial device.

Returns
The number of bytes that have been received, but net yet read out of the serial device.
Exceptions
BFCLException- Thrown if an error occurs while retrieving the number of bytes available.

References CLComm::BFCLException::check(), and clGetNumBytesAvail().

535 {
536  CLUINT32 numBytes;
537  BFCLException::check( clGetNumBytesAvail(m_pd.clSerRef, &numBytes) );
538  return numBytes;
539 }
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetNumBytesAvail(hSerRef serialRef, CLUINT32 *numBytes)
unsigned int CLUINT32
Definition: clallserial.h:80
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
CLUINT32 CLAllSerial::getNumPorts ( BFVOID  )
static

Returns the number of Camera Link serial ports in this machine that are supported by clallserial.dll.

Returns
The number of Camera Link serial ports installed on this system.
Exceptions
BFCLException- Thrown if an error occurs retrieving port count.

References CLComm::BFCLException::check(), and clGetNumPorts().

130 {
131  CLUINT32 numPorts;
132  BFCLException::check( clGetNumPorts(&numPorts) );
133  return numPorts;
134 }
unsigned int CLUINT32
Definition: clallserial.h:80
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetNumPorts(CLUINT32 *Ports)
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
BFVOID CLAllSerial::getPortInfo ( const CLUINT32  SerialIndex,
std::string &  ManufacturerName,
std::string &  PortID,
CLUINT32 Version 
)
static

Provides information about the port specified by the serial index.

Parameters
[in]SerialIndex- The index of the serial port who's info we are retrieving.
[out]ManufacturerName- Output string for the manufacturer.
[out]PortID- Output string for the port ID.
[out]Version- Output integer for the CLAllSerial version.
Exceptions
BFCLException- Thrown if an error occurs retrieving the port information.

References CLComm::BFCLException::check(), CL_ERR_BUFFER_TOO_SMALL, clGetPortInfo(), and MAX_STRING.

Referenced by getPortInfo().

147 {
148  std::vector<CLINT8> manuName (MAX_STRING);
149  CLUINT32 manuNameLen = CLUINT32(manuName.size());
150 
151  std::vector<CLINT8> pidName (MAX_STRING);
152  CLUINT32 pidNameLen = CLUINT32(pidName.size());
153 
154  CLINT32 rc = clGetPortInfo(SerialIndex, manuName.data(), &manuNameLen, pidName.data(), &pidNameLen, &Version);
155  if (CL_ERR_BUFFER_TOO_SMALL == rc)
156  {
157  manuName.resize(++manuNameLen);
158  pidName.resize(++pidNameLen);
159  rc = clGetPortInfo(SerialIndex, manuName.data(), &manuNameLen, pidName.data(), &pidNameLen, &Version);
160  }
161 
163 
164  manuName.push_back(0);
165  ManufacturerName = manuName.data();
166 
167  pidName.push_back(0);
168  PortID = pidName.data();
169 }
unsigned int CLUINT32
Definition: clallserial.h:80
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
#define MAX_STRING
Definition: BFType.h:65
int CLINT32
Definition: clallserial.h:74
#define CL_ERR_BUFFER_TOO_SMALL
Definition: clallserial.h:114
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetPortInfo(CLUINT32 serialIndex, CLINT8 *manufacturerName, CLUINT32 *nameBytes, CLINT8 *portID, CLUINT32 *IDBytes, CLUINT32 *version)
BFBOOL CLAllSerial::getPortInfo ( const CLUINT32  SerialIndex,
BFCHAR *const  ManufacturerName,
BFSIZET *const  pManNameSize,
BFCHAR *const  PortID,
BFSIZET *const  pPortIdSize,
CLUINT32 Version 
)
static

Provides information about the port specified by the serial index.

Parameters
[in]SerialIndex- The index of the serial port who's info we are retrieving.
[out]ManufacturerName- Output string buffer for the manufacturer. This may be nullptr.
[in,out]pManNameSize- As input, the ManufacturerName buffer size. As output, the required ManufacturerName buffer length, including null terminator.
[out]PortID- Output string buffer for the port ID. This may be nullptr.
[in,out]pPortIdSize- As input, the PortID buffer size. As output, the required PortID buffer length, including null terminator.
[out]Version- Output integer for the CLAllSerial version.
Returns
True on success, false otherwise.
Exceptions
BFCLException- Thrown if an error occurs retrieving the port information.

References getPortInfo().

188 {
189  std::string cppManufacturerName, cppPortID;
190  getPortInfo(SerialIndex, cppManufacturerName, cppPortID, Version);
191 
192  if (!BufInHelpers::set_str(cppManufacturerName, ManufacturerName, pManNameSize))
193  return false;
194 
195  if (!BufInHelpers::set_str(cppPortID, PortID, pPortIdSize))
196  return false;
197 
198  return true;
199 }
static BFVOID getPortInfo(const CLUINT32 SerialIndex, std::string &ManufacturerName, std::string &PortID, CLUINT32 &Version)
Definition: CLAllSerial.cpp:146
CLUINT32 CLAllSerial::getSerialIndex ( void  ) const

Retrieve the serial index initialized, or ~CLUINT32(0), if not open or not initialized by the serial index.

Returns
The index of the opened Camera Link serial port, or ~CLUINT32(0), if not open or not initialized by the serial index.
387 {
388  return m_pd.serialIndex;
389 }
CLUINT32 CLAllSerial::getSupportedBaudRates ( BFVOID  ) const

Returns the valid baud rates of the interface.

Returns
The valid baud rates of the interface, ORd together. The known flags are:
Exceptions
BFCLException- Thrown if an error occurs while retrieving the supported baud rates.

References CLComm::BFCLException::check(), and clGetSupportedBaudRates().

557 {
558  CLUINT32 baudRates;
559  BFCLException::check( clGetSupportedBaudRates(m_pd.clSerRef, &baudRates) );
560  return baudRates;
561 }
unsigned int CLUINT32
Definition: clallserial.h:80
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetSupportedBaudRates(hSerRef serialRef, CLUINT32 *baudRates)
void CLAllSerial::getSWConnector ( CLUINT32 Switch,
CLUINT32 Connector 
) const

Retrieve the BitFlow Switch and Connector initialized, or ~CLUINT32(0), if not open or not initialized by Switch and Connector.

Parameters
[out]Switch- Ouput integer reference set to the open board's switch setting, or ~CLUINT32(0), if not open or not initialized by Switch and Connector.
[out]Connector- Output integer reference set to the open board's connector index, or ~CLUINT32(0), if not open or not initialized by Switch and Connector.
408 {
409  Switch = m_pd.bfSwitch;
410  Connector = m_pd.bfConnector;
411 }
BFBOOL CLAllSerial::hasBFSerial ( BFVOID  ) const

Return whether or not the opened port supports the BitFlow CLSerial extensions.

Returns
The BFSerial port initialization status.

Referenced by bfGetBaudRate(), bfSerialCancelRead(), bfSerialRead(), and bfSerialSettings().

377 {
378  return !!m_pd.bfSerRef;
379 }
BFBOOL CLAllSerial::hasInit ( BFVOID  ) const

Return whether or not a port has been initialized.

Returns
The CLAllSerial port initialization status.
367 {
368  return !!m_pd.clSerRef;
369 }
BFVOID CLAllSerial::serialClose ( BFVOID  )

Closes the serial device and cleans up resources associated with it. Does nothing, if the device is not Initialized.

References clSerialClose().

Referenced by bfSerialInit(), bfSWConnectorSerialInit(), serialInit(), and ~CLAllSerial().

344 {
345  if (m_pd.clSerRef)
346  clSerialClose(m_pd.clSerRef);
347 
348  if (m_pd.hBoard)
349  CiBrdClose(m_pd.hBoard);
350 
351  m_pd.clSerRef = nullptr;
352  m_pd.bfSerRef = nullptr;
353  m_pd.hBoard = nullptr;
354 
355  m_pd.serialIndex = ~CLUINT32(0);
356  m_pd.boardNumber = ~CLUINT32(0);
357  m_pd.bfSwitch = ~CLUINT32(0);
358  m_pd.bfConnector = ~CLUINT32(0);
359 }
CLALLSERIALEXPORT void CLALLSERIALCC clSerialClose(hSerRef serialRef)
unsigned int CLUINT32
Definition: clallserial.h:80
BFVOID CLAllSerial::serialInit ( const CLUINT32  SerialIndex)

Initializes the device referred to by serialIndex. Only CL boards are considered a serial device. If the underlying CLSerial device is not a BitFlow device, the BFSerial extensions will not be enabled, and hasBFSerial will return false.

Parameters
[in]SerialIndex- The index of the Camera Link serial port to initialize.
Exceptions
BFCLException- Thrown if an error occurs initializing the port.

References CLComm::BFCLException::check(), clBFGetSerialRef(), clSerialInit(), and serialClose().

223 {
224  serialClose();
225 
226  // Open the CLAllSerial port.
227  hSerRef clSerRef;
228  BFCLException::check( clSerialInit(SerialIndex, &clSerRef) );
229 
230  // Determine if BFSerial support is available for this serial port.
231  BFVOID *bfSerRef;
232  CLINT32 rc = clBFGetSerialRef(SerialIndex, &bfSerRef);
233  if (BF_OK != rc)
234  bfSerRef = nullptr;
235 
236  // Store the CLSerial handles.
237  m_pd.clSerRef = clSerRef;
238  m_pd.bfSerRef = bfSerRef;
239 
240  m_pd.serialIndex = SerialIndex;
241 }
BFVOID serialClose(BFVOID)
Definition: CLAllSerial.cpp:343
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
void * hSerRef
Definition: clallserial.h:69
void BFVOID
Definition: BFTypeNT.h:32
int CLINT32
Definition: clallserial.h:74
BFSERIALEXPORT int BFSERIALCC clBFGetSerialRef(unsigned int portNum, void **serBFRefPtr)
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clSerialInit(CLUINT32 serialIndex, hSerRef *serialRefPtr)
std::string CLAllSerial::serialRead ( const CLUINT32  NumBytesToRead,
const CLUINT32  SerialTimeout 
)

Reads data from the serial device.

Parameters
[in]NumBytesToRead- The number of bytes to be read.
[in]SerialTimeout- Timeout after which the read should abort.
Returns
The data read, formatted as a null-terminated string.
Exceptions
BFCLException- Thrown if an error occurs reading from the serial port, including timeout.

Referenced by serialRead().

475 {
476  std::vector<CLINT8> buf (NumBytesToRead);
477  const CLUINT32 bytesRead = serialRead(buf, NumBytesToRead, SerialTimeout);
478  return std::string (buf.data(), bytesRead);
479 }
unsigned int CLUINT32
Definition: clallserial.h:80
std::string serialRead(const CLUINT32 NumBytesToRead, const CLUINT32 SerialTimeout)
Definition: CLAllSerial.cpp:474
CLUINT32 CLAllSerial::serialRead ( std::vector< CLINT8 > &  Buffer,
const CLUINT32  ReadLen,
const CLUINT32  SerialTimeout 
) const

Reads data from the serial device, returning the number of bytes read.

Parameters
[out]Buffer- Output buffer for the data read. This will be resized to fit the data read, if necessary.
[in]ReadLen- The number of bytes to be read.
[in]SerialTimeout- Timeout after which the read should abort.
Returns
The number of bytes read from the port.
Exceptions
BFCLException- Thrown if an error occurs reading from the serial port, including timeout.

References serialRead().

493 {
494  if (Buffer.size() < ReadLen)
495  Buffer.resize(ReadLen);
496  return serialRead(Buffer.data(), CLUINT32(Buffer.size()), SerialTimeout);
497 }
unsigned int CLUINT32
Definition: clallserial.h:80
std::string serialRead(const CLUINT32 NumBytesToRead, const CLUINT32 SerialTimeout)
Definition: CLAllSerial.cpp:474
CLUINT32 CLAllSerial::serialRead ( CLINT8 *const  Buffer,
const CLUINT32  BufferSize,
const CLUINT32  SerialTimeout 
) const

Reads data from the serial device, returning the number of bytes read.

Parameters
[out]Buffer- Output buffer for the data read.
[in]BufferSize- Size of the output Buffer.
[in]SerialTimeout- Timeout after which the read should abort.
Returns
The number of bytes read from the port.
Exceptions
BFCLException- Thrown if an error occurs reading from the serial port, including timeout.

References CLComm::BFCLException::check(), and clSerialRead().

511 {
512  CLUINT32 readSize = BufferSize;
513  BFCLException::check( clSerialRead(m_pd.clSerRef, Buffer, &readSize, SerialTimeout) );
514  return readSize;
515 }
unsigned int CLUINT32
Definition: clallserial.h:80
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clSerialRead(hSerRef serialRef, CLINT8 *buffer, CLUINT32 *bufferSize, CLUINT32 serialTimeout)
CLUINT32 CLAllSerial::serialWrite ( std::string const &  Message,
const CLUINT32  SerialTimeout 
)

This method writes a string of characters to the serial device, returning the number of bytes written.

Parameters
[in]Message- A string message to write to the port (null terminator excluded).
[in]SerialTimeout- Timeout after which the write should abort.
Returns
The number of bytes written to the serial port.
Exceptions
BFCLException- Thrown if an error occurs writing to the serial port, including timeout.

Referenced by serialWrite().

424 {
425  return serialWrite(Message.c_str(), Message.size(), SerialTimeout);
426 }
CLUINT32 serialWrite(std::string const &Message, const CLUINT32 SerialTimeout)
Definition: CLAllSerial.cpp:423
CLUINT32 CLAllSerial::serialWrite ( std::vector< CLINT8 > const &  Buffer,
const CLUINT32  SerialTimeout 
)

This method writes data to the serial device, returning the number of bytes written.

Parameters
[in]Buffer- Buffer of data to be written to the serial port.
[in]SerialTimeout- Timeout after which the write should abort.
Returns
The number of bytes written to the serial port.
Exceptions
BFCLException- Thrown if an error occurs writing to the serial port, including timeout.

References serialWrite().

439 {
440  return serialWrite(Buffer.data(), Buffer.size(), SerialTimeout);
441 }
CLUINT32 serialWrite(std::string const &Message, const CLUINT32 SerialTimeout)
Definition: CLAllSerial.cpp:423
CLUINT32 CLAllSerial::serialWrite ( const CLINT8 *const  Buffer,
const BFSIZET  BufferLen,
const CLUINT32  SerialTimeout 
)

This method writes data to the serial device, returning the number of bytes written.

Parameters
[in]Buffer- Buffer of data to be written to the serial port.
[in]BufferLen- Byte size of the data to be written.
[in]SerialTimeout- Timeout after which the write should abort.
Returns
The number of bytes written to the serial port.
Exceptions
BFCLException- Thrown if an error occurs writing to the serial port, including timeout.

References CLComm::BFCLException::check(), and clSerialWrite().

455 {
456  // Make the buffer mutable the "proper" and expensive way.
457  std::vector<CLINT8> mBuffer (Buffer, Buffer + BufferLen);
458 
459  CLUINT32 bufferSize = CLUINT32(mBuffer.size());
460  BFCLException::check( clSerialWrite(m_pd.clSerRef, mBuffer.data(), &bufferSize, SerialTimeout) );
461  return bufferSize;
462 }
unsigned int CLUINT32
Definition: clallserial.h:80
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clSerialWrite(hSerRef serialRef, CLINT8 *buffer, CLUINT32 *bufferSize, CLUINT32 serialTimeout)
BFVOID CLAllSerial::setBaudRate ( const CLUINT32  BaudRate)

Sets the Baud Rate for the serial port.

Parameters
[in]BaudRate- The baud rate to set, of the following options:
Exceptions
BFCLException- Thrown if an error occurs while setting the baud rate.

References CLComm::BFCLException::check(), and clSetBaudRate().

579 {
580  BFCLException::check( clSetBaudRate(m_pd.clSerRef, BaudRate) );
581 }
static BFVOID check(const CLINT32 errorCode)
Definition: CLAllSerial.cpp:733
CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clSetBaudRate(hSerRef serialRef, CLUINT32 baudRate)

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