ClAllSerial.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Title : clallserial.h
  4. // Created : 12/03/2003 @ 14:27:00
  5. //
  6. // Copyright (c) 2004. National Instruments Corporation
  7. // All rights reserved.
  8. //
  9. // Redistribution and use in source and binary forms, with or without
  10. // modification, are permitted, provided that each of the following
  11. // conditions are met. By using the software in any manner, you agree
  12. // to each of the following:
  13. // - All redistributions of the software must be accompanied with the
  14. // above copyright notice (provided however that for redistributions
  15. // in binary form, the copyright notice may be omitted), the above
  16. // preamble, this list of conditions, and the disclaimer set forth below.
  17. // - Except for the copyright notice required above, neither the name
  18. // or trademarks of National Instruments Corporation (NI) nor the names
  19. // of its contributors may be used in any manner (including, but not
  20. // limited to, using the same to endorse or promote products derived from
  21. // this software) without the specific prior written permission of NI.
  22. //
  23. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. // "AS IS" WITHOUT WARRANTY OF ANY KIND. NO WARRANTIES, EITHER EXPRESS
  25. // OR IMPLIED, ARE MADE WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
  26. // NOT LIMITED TO, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
  27. // FOR A PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT, OR ANY OTHER
  28. // WARRANTIES THAT MAY ARISE FROM USAGE OF TRADE OR COURSE OF DEALING.
  29. // THE COPYRIGHT HOLDERS AND CONTRIBUTORS DO NOT WARRANT, GUARANTEE, OR
  30. // MAKE ANY REPRESENTATIONS REGARDING THE USE OF OR THE RESULTS OF THE
  31. // USE OF THE SOFTWARE IN TERMS OF CORRECTNESS, ACCURACY, RELIABILITY,
  32. // OR OTHERWISE AND DO NOT WARRANT THAT THE OPERATION OF THE SOFTWARE
  33. // WILL BE UNINTERRUPTED OR ERROR FREE. THE ENTIRE RISK AS TO THE
  34. // PERFORMANCE OF THE SOFTWARE IS WITH YOU. IN NO EVENT SHALL THE
  35. // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  36. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  37. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  38. // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  39. // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  40. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  41. // THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF ADVISED OF THE
  42. // POSSIBILITY OF SUCH DAMAGE.
  43. //
  44. //////////////////////////////////////////////////////////////////////////////
  45. #ifndef CLPROTOCOL_CLALLSERIAL_H
  46. #define CLPROTOCOL_CLALLSERIAL_H
  47. #include <CLProtocol\CLSerialTypes.h>
  48. //==============================================================================
  49. // Macros
  50. //==============================================================================
  51. #if (defined(__cplusplus) || defined(__cplusplus__))
  52. #define USER_EXTERN_C extern "C"
  53. #else
  54. #define USER_EXTERN_C
  55. #endif
  56. #ifdef CLALLSERIAL_EXPORTS
  57. #define CLALLSERIALEXPORT USER_EXTERN_C __declspec(dllexport)
  58. #else
  59. #define CLALLSERIALEXPORT USER_EXTERN_C __declspec(dllimport)
  60. #endif
  61. #ifndef CLALLSERIALCC
  62. // Note that using __stdcall changes the name decoration as compared with __cdecl
  63. // For details see http://www.willus.com/mingw/yongweiwu_stdcall.html
  64. #define CLALLSERIALCC __stdcall
  65. #endif
  66. //==============================================================================
  67. // Exported functions
  68. //==============================================================================
  69. ////////////////////////////////////////////////////////////////////////////////
  70. //
  71. // clFlushPort
  72. //
  73. // Description: Discards any bytes that are available in the input
  74. // buffer.
  75. //
  76. // Parameters:
  77. // serialRef input parameter - The value obtained by the clSerialInit function
  78. // that describes the port to be flushed.
  79. //
  80. // Return Value: CL_ERR_NO_ERR
  81. // CL_ERR_INVALID_REFERENCE
  82. //
  83. ////////////////////////////////////////////////////////////////////////////////
  84. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clFlushPort(hSerRef serialRef);
  85. ////////////////////////////////////////////////////////////////////////////////
  86. //
  87. // clGetErrorText
  88. //
  89. // Description:
  90. // Converts an error code to error text which you can
  91. // display in a dialog box or in the standard I/O window.
  92. // Note: This function first looks up the error code in clserial.dll to determine
  93. // whether it is a standard Camera Link error. If it is a non-standard error, this function
  94. // passes the error code to the manufacturer-specific DLL, which returns the
  95. // manufacturer-specific error code.
  96. //
  97. // Parameters:
  98. // manuName input parameter - The manufacturer name in a NULL-terminated
  99. // buffer. Manufacturer name is returned from clGetPortInfo.
  100. // errorCode input parameter - The error code used to look up the
  101. // appropriate error text. This code can be returned
  102. // from any function in this library.
  103. // errorText output parameter - A caller-allocated buffer which will contain
  104. // a NULL-terminated error description on return.
  105. // errorTextSize input/output parameter - As an input, this value is the size,
  106. // in bytes, of the errorText buffer that is passed in. On
  107. // success, this value is the number of bytes
  108. // that have been written into the buffer, including the NULL
  109. // termination character. On CL_ERR_BUFFER_TOO_SMALL error,
  110. // this value is the size of the buffer required to write
  111. // the data text.
  112. //
  113. // Return Value: CL_ERR_NO_ERR
  114. // CL_ERR_MANU_DOES_NOT_EXIST
  115. // CL_ERR_BUFFER_TOO_SMALL
  116. // CL_ERR_ERROR_NOT_FOUND
  117. //
  118. /////////////////////////////////////////////////////////////////////////////////
  119. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetErrorText(const CLINT8* manuName, CLINT32 errorCode, CLINT8* errorText, CLUINT32* errorTextSize);
  120. ////////////////////////////////////////////////////////////////////////////////
  121. //
  122. // clGetNumPorts
  123. //
  124. // Description: Returns the number of Camera Link serial ports in
  125. // this machine that are supported by clallserial.dll.
  126. //
  127. // Parameters:
  128. // numPorts output parameter - The number of Camera Link serial ports
  129. // in this machine supported by this DLL.
  130. //
  131. // Return Value: CL_ERR_NO_ERR
  132. //
  133. ////////////////////////////////////////////////////////////////////////////////
  134. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetNumPorts(CLUINT32* Ports);
  135. ////////////////////////////////////////////////////////////////////////////////
  136. //
  137. // clGetNumBytesAvail
  138. //
  139. // Description: Outputs the number of bytes that are received, but not yet read out, at
  140. // the port specified by serialRef.
  141. //
  142. // Parameters:
  143. // serialRef input - The value obtained by the clSerialInit function.
  144. // numBytes output - The number of bytes currently available to be
  145. // read from the port.
  146. //
  147. // Return Value: CL_ERR_NO_ERR
  148. // CL_ERR_INVALID_REFERENCE
  149. //
  150. ////////////////////////////////////////////////////////////////////////////////
  151. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetNumBytesAvail(hSerRef serialRef, CLUINT32* numBytes);
  152. ////////////////////////////////////////////////////////////////////////////////
  153. //
  154. // clGetPortInfo
  155. //
  156. // Description: This function provides information about the port specified by
  157. // the index.
  158. //
  159. // Parameters:
  160. // serialIndex input parameter - Zero-based index of the serial port you are
  161. // finding the name for. Use clGetNumSerialPorts to determine
  162. // the valid range of serialIndex. This range will be 0 to
  163. // numSerialPorts-1.
  164. // manufacturerName output parameter - Pointer to a user-allocated buffer into
  165. // which the function copies the manufacturer name. The returned
  166. // name is NULL-terminated. In the case that the DLL conforms to the
  167. // version 1.0 Camera Link Specification, this
  168. // parameter will contain the file name of the DLL rather than the
  169. // manufacturer name.
  170. // nameBytes input/output parameter - As an input parameter,
  171. // this value is the size of the name buffer, including
  172. // the NULL termination. As an output parameter, this value
  173. // is the number of bytes written into the name buffer.
  174. // If the provided name buffer is not large enough, this value
  175. // is the number of required bytes.
  176. // portID output parameter - The identifier for the port. For now, this
  177. // value is the interface name. In the future, there may be an
  178. // extension for multiple serial ports on one board.
  179. // IDBytes input/output parameter. As an input parameter, this value is
  180. // the size of the portID buffer, including
  181. // the NULL termination. As an output parameter, this value is
  182. // the number of bytes written into the portID buffer.
  183. // If the provided portID buffer is not large enough, this value is
  184. // the number of required bytes.
  185. // Version The version of the Camera Link specifications with which this frame
  186. // grabber software complies.
  187. //
  188. // Return Value: CL_ERR_NO_ERR
  189. // CL_ERR_BUFFER_TOO_SMALL
  190. // CL_ERR_INVALID_INDEX//
  191. ////////////////////////////////////////////////////////////////////////////////
  192. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetPortInfo(CLUINT32 serialIndex, CLINT8* manufacturerName, CLUINT32* nameBytes, CLINT8* portID, CLUINT32* IDBytes, CLUINT32* version);
  193. ////////////////////////////////////////////////////////////////////////////////
  194. //
  195. // clGetSupportedBaudRates
  196. //
  197. // Description: Returns the valid baud rates of the interface.
  198. //
  199. // Parameters:
  200. // serialRefPtr input parameter - The value obtained from
  201. // clSerialInit function.
  202. // baudRates output parameter - Indicates which baud
  203. // rates are supported by this serial interface. This
  204. // is represented as a bitfield. Refer to the CL_BAUDRATE_
  205. // constants above for the supported baud rates.
  206. //
  207. // Return Value: CL_ERR_NO_ERR
  208. // CL_ERR_INVALID_REFERENCE
  209. // CL_ERR_FUNCTION_NOT_FOUND
  210. //
  211. /////////////////////////////////////////////////////////////////////////////////
  212. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clGetSupportedBaudRates(hSerRef serialRef, CLUINT32* baudRates);
  213. //////////////////////////////////////////////////////////////////////////////////
  214. //
  215. // clSerialClose
  216. //
  217. // Description: Closes the serial device and cleans up resources associated
  218. // with serialRef. Upon return, serialRef is no longer usable.
  219. //
  220. // Parameters:
  221. // serialRef input parameter - The value obtained from clSerialInit
  222. // function to clean up.
  223. //
  224. ///////////////////////////////////////////////////////////////////////////////////
  225. CLALLSERIALEXPORT void CLALLSERIALCC clSerialClose(hSerRef serialRef);
  226. ////////////////////////////////////////////////////////////////////////////////
  227. //
  228. // clSerialInit
  229. //
  230. // Description:
  231. // Initializes the device referred to by serialIndex, and
  232. // returns a pointer to an internal serial reference structure.
  233. //
  234. // Parameters:
  235. // serialIndex input parameter - Zero-based index value. If there are n
  236. // serial devices in the system that is supported by this
  237. // library, the range of serialIndex is 0 to (n-1).
  238. // The order of the serial devices is vendor-specific. The
  239. // number of serial ports supported by this DLL is
  240. // output by the clGetNumSerialPorts function.
  241. // serialRefPtr output parameter - Upon a successful call, a pointer to the
  242. // vendor-specific reference to the current serial session
  243. // will be put into the value pointed to by serialRefPtr.
  244. //
  245. // Return Value: CL_ERR_NO_ERR
  246. // CL_ERR_PORT_IN_USE
  247. // CL_ERR_INVALID_INDEX
  248. // CL_ERR_UNABLE_TO_OPEN_PORT
  249. //
  250. ////////////////////////////////////////////////////////////////////////////////
  251. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clSerialInit(CLUINT32 serialIndex, hSerRef* serialRefPtr);
  252. ////////////////////////////////////////////////////////////////////////////////
  253. //
  254. // clSerialRead
  255. //
  256. // Description: Reads from the serial device referenced by serialRef.
  257. //
  258. // Parameters:
  259. // serialRef input parameter - The value obtained from clSerialInit function
  260. // buffer output parameter - Points to a user-allocated buffer.
  261. // Upon a successful call, contains the data
  262. // read from the serial device.
  263. // bufferSize input-output parameter - As an input parameter, bufferSize contains the
  264. // buffer size to indicate the maximum number of bytes that
  265. // the buffer can accommodate.
  266. // Upon a successful call, bufferSize is the
  267. // number of bytes that were read successfully from the
  268. // serial device.
  269. // serialTimeout input parameter - Indicates the timeout, in milliseconds
  270. //
  271. // Return value CL_ERR_NO_ERR
  272. // CL_ERR_TIMEOUT
  273. // CL_ERR_INVALID_REFERENCE
  274. //
  275. ////////////////////////////////////////////////////////////////////////////////
  276. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clSerialRead(hSerRef serialRef, CLINT8* buffer, CLUINT32* bufferSize, CLUINT32 serialTimeout);
  277. ////////////////////////////////////////////////////////////////////////////////
  278. //
  279. // clSerialWrite
  280. //
  281. // Description: This function writes data in buffer to the serial device
  282. // referenced by serialRef.
  283. //
  284. // Parameters:
  285. // serialRef input parameter - The value obtained from clSerialInit function
  286. // buffer input parameter - Contains data to write to the serial port
  287. // bufferSize input/output parameter - As an input parameter, bufferSize contains the
  288. // number of bytes of data in the buffer to write to the
  289. // serial device. Upon a successful call, bufferSize contains the
  290. // number of bytes that was written successfully to the
  291. // serial device.
  292. // serialTimeout input parameter - Indicates the timeout, in miliseconds
  293. //
  294. // Return value: CL_ERR_NO_ERR
  295. // CL_ERR_INVALID_REFERENCE
  296. // CL_ERR_TIMEOUT
  297. /////////////////////////////////////////////////////////////////////////////////
  298. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clSerialWrite(hSerRef serialRef, CLINT8* buffer, CLUINT32* bufferSize, CLUINT32 serialTimeout);
  299. ////////////////////////////////////////////////////////////////////////////////
  300. //
  301. // clSetBaudRate
  302. //
  303. // Description: Sets the Baud Rate for the serial port of the
  304. // selected port. Use clGetSupportedBaudRates to deterimine
  305. // supported baud rates.
  306. //
  307. // Parameters:
  308. // serialRef input parameter - The value obtained from
  309. // clSerialInit function.
  310. // baudRate input parameter - The baud rate you want to use. This
  311. // input expects the values represented by the CL_BAUDRATE
  312. // constants.
  313. //
  314. // Return Value: CL_ERR_NO_ERR
  315. // CL_ERR_INVALID_REFERENCE
  316. // CL_ERR_BAUD_RATE_NOT_SUPPORTED
  317. //
  318. ////////////////////////////////////////////////////////////////////////////////
  319. CLALLSERIALEXPORT CLINT32 CLALLSERIALCC clSetBaudRate(hSerRef serialRef, CLUINT32 baudRate);
  320. //==============================================================================
  321. // the endif
  322. //==============================================================================
  323. #endif // CLPROTOCOL_CLALLSERIAL_H