Buffer Interface
CLAllSerial.hpp
Go to the documentation of this file.
1 #include <BFSerial.h>
2 #include <clallserial.h>
3 
4 #include <BFException.hpp>
5 
6 #include <string>
7 #include <vector>
8 
14 namespace CLComm
15 {
24  class BFDLL CLAllSerial
25  {
26  public:
29 
30  // Converts an error code to error text which can be displayed in a dialog box or in the standard I/O window.
31  static std::string getErrorText (const CLINT32 ErrorCode);
32  static BFBOOL getErrorText (const CLINT32 ErrorCode, BFCHAR *const hBuf, BFSIZET *const pSize);
33 
34  // Returns the number of Camera Link serial ports in this machine that are supported by clallserial.dll.
35  static CLUINT32 getNumPorts (BFVOID);
36 
37  // Provides information about the port specified by the serial index.
38  static BFVOID getPortInfo (const CLUINT32 SerialIndex, std::string &ManufacturerName, std::string &PortID, CLUINT32 &Version);
39  static BFBOOL getPortInfo (const CLUINT32 SerialIndex, BFCHAR *const ManufacturerName, BFSIZET *const pManNameSize, BFCHAR *const PortID, BFSIZET *const pPortIdSize, CLUINT32 &Version);
40 
41  // Retrieve the version of the loaded BFS library.
42  static BFVOID bfsVersion (CLUINT32 &majorVersionRef, CLUINT32 &minorVersionRef);
43 
44  // Initializes the device referred to by serialIndex. Only CL boards are considered a serial device. If the underlying
45  // CLSerial device is not a BitFlow device, the BFSerial extensions will not be enabled, and hasBFSerial will return false.
46  BFVOID serialInit (const CLUINT32 SerialIndex);
47 
48  // Alternate initializer, initializing from a BitFlow board index, rather than from the
49  // CLSerial port index, which may or may not directly correspond.
50  BFVOID bfSerialInit (const CLUINT32 BoardIndex);
51 
52  // Alternate initializer, initializing from a BitFlow board swith and connector, rather than from the
53  // CLSerial port index, which may or may not directly correspond.
54  BFVOID bfSWConnectorSerialInit (const CLUINT32 Switch, const CLUINT32 Connector);
55 
56  // Closes the serial device and cleans up resources associated with it. Does nothing, if the device is not Initialized.
57  BFVOID serialClose (BFVOID);
58 
59  // Return whether or not a port has been initialized.
60  BFBOOL hasInit (BFVOID) const;
61 
62  // Return whether or not the opened port supports the BitFlow CLSerial extensions.
63  BFBOOL hasBFSerial (BFVOID) const;
64 
65  // Retrieve the serial index initialized, or ~CLUINT32(0), if not open or not initialized by the serial index.
66  CLUINT32 getSerialIndex (void) const;
67 
68  // Retrieve the BitFlow board number initialized, or ~CLUINT32(0), if not open or not initialized by the BitFlow board nubmer.
69  CLUINT32 getBoardNumber (void) const;
70 
71  // Retrieve the BitFlow Switch and Connector initialized, or ~CLUINT32(0), if not open or not initialized by Switch and Connector.
72  void getSWConnector (CLUINT32 &Switch, CLUINT32 &Connector) const;
73 
74  // This method writes a string of characters to the serial device, returning the number of bytes written.
75  CLUINT32 serialWrite (std::string const& Message, const CLUINT32 SerialTimeout);
76 
77  // This method writes data to the serial device, returning the number of bytes written.
78  CLUINT32 serialWrite (std::vector<CLINT8> const& Buffer, const CLUINT32 SerialTimeout);
79  CLUINT32 serialWrite (const CLINT8 *const Buffer, const BFSIZET BufferLen, const CLUINT32 SerialTimeout);
80 
81  // Reads data from the serial device.
82  std::string serialRead (const CLUINT32 NumBytesToRead, const CLUINT32 SerialTimeout);
83 
84  // Reads data from the serial device, returning the number of bytes read.
85  CLUINT32 serialRead (std::vector<CLINT8> &Buffer, const CLUINT32 ReadLen, const CLUINT32 SerialTimeout) const;
86  CLUINT32 serialRead (CLINT8 *const Buffer, const CLUINT32 BufferSize, const CLUINT32 SerialTimeout) const;
87 
88  // Discards any bytes that are available in the input buffer.
89  BFVOID flushPort (BFVOID);
90 
91  // Returns the number of bytes that are received, but not yet read out of the the serial device.
92  CLUINT32 getNumBytesAvail (BFVOID) const;
93 
94  // Returns the valid baud rates of the interface.
95  CLUINT32 getSupportedBaudRates (BFVOID) const;
96 
97  // Sets the Baud Rate for the serial port.
98  BFVOID setBaudRate (const CLUINT32 BaudRate);
99 
100  // Set the BF CLSerial settings.
101  BFVOID bfSerialSettings (const CLUINT32 BaudRate, const DataBits dataBits, const Parity parity, const StopBits stopBits);
102 
103  // Reads data from the serial device. This method will wait efficiently for data to become
104  // available on the port, then return that length of data. No more than <paramref name="MaxBytesToRead"/>
105  // will be read at a time, but the length read may be less than that.
106  std::string bfSerialRead (const CLUINT32 MaxBytesToRead) const;
107 
108  // Reads data from the serial device. This method will wait efficiently for data to become
109  // available on the port, then return that length of data. Returns the number of bytes read.
110  CLUINT32 bfSerialRead (std::vector<BFCHAR> &Buffer, const CLUINT32 MaxBytesToRead) const;
111  CLUINT32 bfSerialRead (PBFCHAR Buffer, const CLUINT32 MaxBytesToRead) const;
112 
113  // Cancel the active call to clBFSerialRead.
114  BFVOID bfSerialCancelRead (BFVOID);
115 
116  // Return the current baud-rate of the CLSerial port.
117  CLUINT32 bfGetBaudRate (BFVOID) const;
118 
119  private:
120  struct PrivateData;
121  PrivateData &m_pd;
122 
123  // The class is non-copyable.
124  CLAllSerial (CLAllSerial const&);
125  CLAllSerial& operator= (CLAllSerial const&);
126  };
127 
170  class BFDLL BFCLException : public BFExceptionBase
171  {
172  public:
173  // Throw a BFCLException, if errorCode isn't CL_ERR_NO_ERR.
174  static BFVOID check (const CLINT32 errorCode);
175 
176  // No error constructor.
177  BFCLException (void);
178 
179  // Error constructor.
180  BFCLException (const CLINT32 number);
181 
182  // Copy constructors.
183  BFCLException (BFCLException const& to_copy);
184  BFCLException (BFCLException &&to_take);
185 
186  // Copy operator.
187  BFCLException& operator= (BFCLException const& to_copy);
188  BFCLException& operator= (BFCLException &&to_take);
189  };
190 }
unsigned int CLUINT32
Definition: clallserial.h:80
char BFCHAR
Definition: BFTypeNT.h:33
Exception thrown for CLAllSerial.h and BFSerial.h API errors.
Definition: CLAllSerial.hpp:170
Base class of all BitFlow exception classes.
Definition: BFException.hpp:11
Wrapper around the Camera Link serial port API.
Definition: CLAllSerial.hpp:24
enum _DataBits DataBits
size_t BFSIZET
Definition: BFTypeNT.h:93
char * PBFCHAR
Definition: BFTypeNT.h:33
Class library for the Camera Link serial port API.
void BFVOID
Definition: BFTypeNT.h:32
int CLINT32
Definition: clallserial.h:74
enum _Parity Parity
enum _StopBits StopBits
int BFBOOL
Definition: BFTypeNT.h:34
char CLINT8
Definition: clallserial.h:85