ClSerial.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. //-----------------------------------------------------------------------------
  2. // (c) 2008 by Basler Vision Technologies
  3. // Section: Vision Components
  4. // Project: GenApi
  5. // Author: Fritz Dierks
  6. // $Header$
  7. //
  8. // License: This file is published under the license of the EMVA GenICam Standard Group.
  9. // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
  10. // If for some reason you are missing this file please contact the EMVA or visit the website
  11. // (http://www.genicam.org) for a full copy.
  12. //
  13. // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
  14. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
  17. // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  20. // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. // POSSIBILITY OF SUCH DAMAGE.
  24. //-----------------------------------------------------------------------------
  25. /*!
  26. \file
  27. \brief Exported C functions as defined by the Camera Link standard v1.1
  28. */
  29. #ifndef CLPROTOCOL_CLSERIAL_H
  30. #define CLPROTOCOL_CLSERIAL_H
  31. #include <CLProtocol\CLSerialTypes.h>
  32. //==============================================================================
  33. // Macros
  34. //==============================================================================
  35. #if (defined(__cplusplus) || defined(__cplusplus__))
  36. #define USER_EXTERN_C extern "C"
  37. #else
  38. #define USER_EXTERN_C
  39. #endif
  40. #ifdef CLSERIAL_EXPORTS
  41. #define CLSERIALEXPORT USER_EXTERN_C __declspec(dllexport)
  42. #else
  43. #define CLSERIALEXPORT USER_EXTERN_C __declspec(dllimport)
  44. #endif
  45. #ifndef CLSERIALCC
  46. // Note that the CLAllSerial.dll uses __stdcall instead of __cdecl
  47. #define CLSERIALCC __cdecl
  48. #endif
  49. //==============================================================================
  50. // exported functions
  51. //==============================================================================
  52. /*! \ingroup PublicInterfaces */
  53. /*@{*/
  54. /*! \defgroup CLSerialInterface CLSerial C-Function Interface */
  55. /*@{*/
  56. /*!
  57. \brief This function returns the name of the manufacturer represented by the index parameter
  58. and the version of the Camera Link specifications with which the specified .dll complies.
  59. \return At completion, this function returns one of the following status codes:
  60. CL_ERR_NO_ERR
  61. CL_ERR_BUFFER_TOO_SMALL
  62. CL_ERR_FUNCTION_NOT_FOUND
  63. CL_ERR_INVALID_INDEX
  64. */
  65. CLSERIALEXPORT CLINT32 CLSERIALCC
  66. clGetManufacturerInfo (
  67. CLINT8* ManufacturerName, /*!< A pointer to a user-allocated buffer into which the function
  68. copies the manufacturer name. The returned name is
  69. NULL-terminated. In the case that the .dll conforms to the October 2000 spec,
  70. this parameter will contain the file name of the .dll rather than
  71. the manufacturer name. */
  72. CLUINT32* bufferSize, /*!< As an input, this value should be the size of the buffer that
  73. is passed. On successful return, this parameter contains the
  74. number of bytes written into the buffer, including the NULL
  75. termination character. On CL_ERR_BUFFER_TOO_SMALL,
  76. this parameter contains the size of the buffer needed to write
  77. the data text. */
  78. CLUINT32* version /*!< The version of the Camera Link Specifications with which this
  79. .dll complies. */
  80. );
  81. /*!
  82. \brief This function initializes the device referred to by serialIndex and returns
  83. a pointer to an internal serial reference structure.
  84. \return
  85. On completion, this function returns one of the following status codes:
  86. CL_ERR_NO_ERR
  87. CL_ERR_PORT_IN_USE
  88. CL_ERR_INVALID_INDEX
  89. */
  90. CLSERIALEXPORT CLINT32 CLSERIALCC
  91. clSerialInit(
  92. CLUINT32 serialIndex, //!< A zero-based index value. For n serial devices
  93. //!< in your system supported by this library,
  94. //!< serialIndex has a range of 0 to(n-1).
  95. //!< The order of the serial devices is vendor specific.
  96. hSerRef* serialRefPtr //!< Points to a value that contains, on a successful call,
  97. ); //!< a pointer to the vendor-specific reference to the current session.
  98. /*!
  99. \brief This function reads numBytes from the serial device referred to by serialRef.
  100. clSerialRead will return when numBytes are available at the serial port or
  101. when the serialTimeout period has passed.
  102. Upon success, numBytes are copied into buffer.
  103. In the case of any error, including CL_ERR_TIMEOUT, no data is copied into buffer.
  104. \return On completion, this function returns one of the following status codes:
  105. CL_ERR_NO_ERR
  106. CL_ERR_TIMEOUT
  107. CL_ERR_INVALID_REFERENCE
  108. */
  109. CLSERIALEXPORT CLINT32 CLSERIALCC
  110. clSerialRead(
  111. hSerRef serialRef, //!< The value obtained from the clSerialInit function.
  112. CLINT8* buffer, //!< Points to a user-allocated buffer. Upon a successful call,
  113. //!< buffer contains the data read from the serial device.
  114. //!< Upon failure, this buffer is not affected.
  115. //!< Caller should ensure that buffer is at least numBytes in size.
  116. CLUINT32* bufferSize, //!< This is the number of bytes requested by the caller.
  117. CLUINT32 serialTimeOut //!< Indicates the timeout in milliseconds.
  118. );
  119. /*!
  120. \brief This function writes the data in the buffer to the serial device referenced by serialRef.
  121. \return On completion, this function returns one of the following status codes:
  122. CL_ERR_NO_ERR
  123. CL_ERR_INVALID_REFERENCE
  124. CL_ERR_TIMEOUT
  125. */
  126. CLSERIALEXPORT CLINT32 CLSERIALCC
  127. clSerialWrite(
  128. hSerRef serialRef, //!< The value obtained from the clSerialInit function.
  129. CLINT8* buffer, //!< Contains data to write to the serial device.
  130. CLUINT32* bufferSize, //!< Contains the buffer size indicating
  131. //!< the number of bytes to be written.
  132. //!< Upon a successful call, bufferSize contains the number of
  133. //!< bytes written to the serial device.
  134. CLUINT32 serialTimeOut //!< Indicates the timeout in milliseconds.
  135. );
  136. /*!
  137. \brief This function closes the serial device and cleans up the resources associated with serialRef.
  138. Upon return, serialRef is no longer usable.
  139. */
  140. CLSERIALEXPORT void CLSERIALCC
  141. clSerialClose(
  142. hSerRef serialRef //!< The value obtained from the clSerialInit function for clean up.
  143. );
  144. /*!
  145. \brief This function returns the number of serial ports in your system from a specified manufacturer.
  146. Use this number to determine the number of times you should loop through the
  147. clGetSerialPortIdentifier function.
  148. \return At completion, this function returns one of the following status codes:
  149. CL_ERR_NO_ERR
  150. CL_ERR_FUNCTION_NOT_FOUND
  151. CL_ERR_MANU_DOES_NOT_EXIST
  152. */
  153. CLSERIALEXPORT CLINT32 CLSERIALCC
  154. clGetNumSerialPorts(
  155. CLUINT32* numSerialPorts //!< The number of serial ports in your system
  156. ); //!< that you can access with the current .dll.
  157. /*
  158. \brief This function returns a manufacturer-specific identifier for each serial port in your system.
  159. \return At completion, this function returns one of the following status codes:
  160. CL_ERR_NO_ERR
  161. CL_BUFFER_TOO_SMALL
  162. CL_ERR_FUNCTION_NOT_FOUND
  163. CL_ERR_INVALID_INDEX
  164. */
  165. CLSERIALEXPORT CLINT32 CLSERIALCC
  166. clGetSerialPortIdentifier(
  167. CLUINT32 serialIndex, //!< A zero-based index value. The valid range for serialIndex
  168. //!< is 0 to n-1, where n is the value of numSerialPorts,
  169. //!< as returned by clGetNumManuSerialPorts.
  170. CLINT8* PortID, //!< Manufacturer-specific identifier for the serial port.
  171. //!< In the case that the manufacturer .dll conforms to the
  172. //!< October 2000 specification, on return this parameter will
  173. //!< be "Port #n" where n is a unique index for the port.
  174. CLUINT32 *bufferSize //!< As an input, this value should be the size of the buffer that
  175. ); //!< is passed. On successful return, this parameter contains
  176. //!< the number of bytes written into the buffer,
  177. //!< including the NULL termination character.
  178. //!< On CL_ERR_BUFFER_TOO_SMALL, this parameter contains the size
  179. //!< of the buffer needed to write the data text.
  180. /*!
  181. \brief This function will output how many bytes have are available at the port specified by serialRef.
  182. \return At completion, this function returns one of the following status codes:
  183. CL_ERR_NO_ERR
  184. CL_ERR_INVALID_REFERENCE
  185. CL_ERR_FUNCTION_NOT_FOUND
  186. */
  187. CLSERIALEXPORT CLINT32 CLSERIALCC
  188. clGetNumBytesAvail(
  189. hSerRef serialRef, //!< The value obtained by the clSerialInit function.
  190. CLUINT32 *numBytes //!< The number of bytes currently available to be read from the port.
  191. );
  192. /*!
  193. \brief This function will discard any bytes that are available in the input buffer.
  194. \return At completion, this function returns one of the following status codes:
  195. CL_ERR_NO_ERR
  196. CL_ERR_INVALID_REFERENCE
  197. */
  198. CLSERIALEXPORT CLINT32 CLSERIALCC
  199. clFlushPort(
  200. hSerRef serialRef //!< The value obtained by the clSerialInit function that describes the port to be flushed.
  201. );
  202. /*!
  203. \brief This function returns the valid baud rates of the current interface.
  204. \return At completion, this function returns one of the following status codes:
  205. CL_ERR_NO_ERR
  206. CL_ERR_INVALID_REFERENCE
  207. CL_ERR_FUNCTION_NOT_FOUND
  208. */
  209. CLSERIALEXPORT CLINT32 CLSERIALCC
  210. clGetSupportedBaudRates(
  211. hSerRef serialRef, //!< Points to a value that contains, on a successful call,
  212. //!< a pointer to the vendor-specific reference to the current session.
  213. CLUINT32 *baudRates //!< Bitfield that describes all supported baud rates of the serial port
  214. ); //!< as described by serialRefPtr. See Table B-2 of the Camera Link
  215. //!< docu for more information on constants.
  216. /*!
  217. \brief This function sets the baud rate for the serial port of the selected device.
  218. Use clGetSupportedBaudRate to determine supported baud rates.
  219. \return On completion, this function returns one of the following status codes:
  220. CL_ERR_NO_ERR
  221. CL_ERR_INVALID_REFERENCE
  222. CL_ERR_BAUD_RATE_NOT_SUPPORTED
  223. */
  224. CLSERIALEXPORT CLINT32 CLSERIALCC
  225. clSetBaudRate(
  226. hSerRef serialRef, //!< The value obtained from the clSerialInit function.
  227. CLUINT32 baudRate //!< The baud rate you want to use. This parameter expects the
  228. ); //!< values represented by the CL_BAUDRATE constants in table B-2.
  229. //!< By default, the baud rate for serial communication is 9600.
  230. /*!
  231. \brief This function converts an error code to error text for display in a
  232. dialog box or in a standard I/O window.
  233. Note: clGetErrorText first looks for the error code in CCTserial.dll.
  234. If the error code is not found in CCTserial.dll, it is not a standard Camera Link error.
  235. clGetErrorText then passes the error code to the manufacturer-specific .dll,
  236. which returns the manufacturer-specific error text.
  237. \return On completion, this function returns one of the following status codes:
  238. CL_ERR_NO_ERR
  239. CL_ERR_BUFFER_TOO_SMALL
  240. CL_ERR_ERROR_NOT_FOUND
  241. */
  242. CLSERIALEXPORT CLINT32 CLSERIALCC
  243. clGetErrorText(
  244. CLINT32 errorCode, //!< The error code used to find the appropriate error text.
  245. //!< An error code is returned by every function in this library.
  246. CLINT8* errorText, //!< A caller-allocated buffer which contains the
  247. //!< NULL-terminated error text on function return.
  248. CLUINT32* errorTextSize //!< On success, contains the number of bytes written
  249. ); //!< into the buffer, including the NULL-termination character.
  250. //!< This value should be the size in bytes of the error text
  251. //!< buffer passed in. On CL_ERR__BUFFER_TOO_SMALL,
  252. //!< contains the size of the buffer needed to write the error text.
  253. /*@}*/ // CLSerialInterface
  254. /*@}*/ // PublicInterfaces
  255. //==============================================================================
  256. // helper functions
  257. //==============================================================================
  258. #endif // CLPROTOCOL_CLSERIAL_H