CLProtocol 3.5.1
CLPort.h
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//-----------------------------------------------------------------------------
29#ifndef CLPROTOCOL_CLPORT_H
30#define CLPROTOCOL_CLPORT_H
31
32#include <Base/GCBase.h>
33#include <GenApi/PortImpl.h>
34#include <CLProtocol/CLException.h>
35#include <CLProtocol/CLAutoBuffer.h>
36#include <CLProtocol/CLProtocol.h>
37#include <CLProtocol/ISerial.h>
38#include <CLProtocol/ISerialAdapter.h>
39#include <CLProtocol/CLAllAdapter.h>
40#include <CLProtocol/DeviceID.h>
41#include <CLProtocol/CVersion.h>
42#include <CLProtocol/XMLID.h>
43#include <iostream>
44#include <fstream>
45#include <list>
46#include <algorithm>
47
48
49namespace CLProtocol
50{
51
53# define CLPORT_PERSISTENCE_MAGIC "{3DFD485D-0ADB-4d84-9956-C3766504A2DD}"
54
55
56#ifdef _MSC_VER
57# pragma warning (push )
58# pragma warning( disable:4275) // warning C4275: non dll-interface class 'GenApi::CPortImpl' used as base for dll-interface class 'CLProtocol::CCLPort'
59#endif
60
73 class CLPROTOCOL_DECL CCLPort : public GENAPI_NAMESPACE::CPortImpl, public ISerial
74 {
75 public:
76
79
83 static void GetPortIDs( GENAPI_NAMESPACE::StringList_t &PortIDs );
84
89 static ISerialAdapter *GetPort( const GENICAM_NAMESPACE::gcstring &PortID );
90
99 static void GetDeviceIDTemplates( GENICAM_NAMESPACE::gcstring_vector &DeviceIDTemplates );
100
112 static GENICAM_NAMESPACE::gcstring ProbeDevice(const GENICAM_NAMESPACE::gcstring &PortID, const GENICAM_NAMESPACE::gcstring &strDeviceIDTemplate, const CLUINT32 SerialTimeout = 500);
113
115 static void StopProbing(CLUINT32 toStop);
116
122 static GENICAM_NAMESPACE::gcstring RegisterSerial( const GENICAM_NAMESPACE::gcstring &PortName, ISerialAdapter *pSerialAdapter);
123
125 static void UnRegisterSerials( );
126
128 static void Terminate( );
129
133 static void UnRegisterSerial( const GENICAM_NAMESPACE::gcstring &PortID );
134
139 void Connect( const GENICAM_NAMESPACE::gcstring &PortID, const GENICAM_NAMESPACE::gcstring &strDeviceID );
140
147 bool Connect( const GENICAM_NAMESPACE::gcstring &PortID );
148
161 void GetXMLIDs( GENICAM_NAMESPACE::gcstring_vector &XMLIDs );
162
168 GENICAM_NAMESPACE::gcstring GetXML( GENICAM_NAMESPACE::gcstring XMLID, const bool UseMaxBaudrate = true );
169
177 void DeleteXMLDownload( GENICAM_NAMESPACE::gcstring XMLID );
178
183 GENICAM_NAMESPACE::gcstring GetXML( const bool UseMaxBaudrate = true );
184
191 GENICAM_NAMESPACE::gcstring MakeURLfromXMLID( GENICAM_NAMESPACE::gcstring &XMLID );
192
194
197
200
202 virtual ~CCLPort();
203
205
208 void SetSerialTimeOut(const CLUINT32 Timeout);
209
211 CLUINT32 GetSerialTimeOut() const;
212
214 GENICAM_NAMESPACE::gcstring GetDeviceID() const;
215
217 void SetProtocolLogLevel( const CLP_LOG_LEVEL_VALUE logLever);
218
220 void SetDeviceBauderate( const CLUINT32 baudrate);
221
224
227
229 static void SetDefaultLogLevel( const CLP_LOG_LEVEL_VALUE logLever);
230
232 static void StorePortIDDeviceIDPairs( GENICAM_NAMESPACE::gcstring_vector &PortIDs, GENICAM_NAMESPACE::gcstring_vector &DeviceIDs );
233
235 static void RetrievePortIDDeviceIDPairs( GENICAM_NAMESPACE::gcstring_vector &PortIDs, GENICAM_NAMESPACE::gcstring_vector &DeviceIDs );
236
238
240
241
243 virtual GENAPI_NAMESPACE::EAccessMode GetAccessMode() const;
244
246 virtual void Read(void * pBuffer, int64_t Address, int64_t Length);
247
249 virtual void Write(const void * pBuffer, int64_t Address, int64_t Length);
250
252 virtual GENAPI_NAMESPACE::EInterfaceType GetPrinicipalInterfaceType() const;
254
256 CLINT32 GetEvent(
257 void * buffer,
261 CLUINT32 * bufferSize
263 );
264
266
267
269 virtual CLINT32 CLPROTOCOL clSerialRead(
270 CLINT8* buffer,
274 CLUINT32* bufferSize,
275 CLUINT32 serialTimeOut
276 );
277
279 virtual CLINT32 CLPROTOCOL clSerialWrite(
280 CLINT8* buffer,
281 CLUINT32* bufferSize,
285 CLUINT32 serialTimeOut
286 );
287
289 virtual CLINT32 CLPROTOCOL clGetSupportedBaudRates(
290 CLUINT32 *baudRates
293 );
295
296 private:
298 static void InitPortIDs(void);
299
301 virtual CLINT32 CLPROTOCOL clSetBaudRate(
302 CLUINT32 baudRate
305 );
306
308 void CheckError( CLINT32 ErrorCode ) const;
309
311 static void CheckLastError();
312
314 void LoadProtocolDriver( const GENICAM_NAMESPACE::gcstring &PortDriverDLLPath );
315
317 void UnLoadProtocolDriver( );
318
320 void CreatePort( const GENICAM_NAMESPACE::gcstring &PortID, const GENICAM_NAMESPACE::gcstring &PortDriverDLLPath );
321
323 static void UpdateCache( const GENICAM_NAMESPACE::gcstring &PortID, const GENICAM_NAMESPACE::gcstring &DeviceID );
324
326 ISerialAdapter *m_pSerialAdapter;
327
329 static SerialPortMap *s_pSerialList;
330
332 static SerialPortMap *s_pPrivateSerialList;
333
335 static bool s_IsSerialListInitialized;
336
337
339 lib_handle_t m_hPortDriverDLL;
340
342 CLUINT32 m_SerialTimeOut;
343
345 GENICAM_NAMESPACE::gcstring m_DeviceID;
346
348 GENICAM_NAMESPACE::gcstring m_PortID;
349
351 CLUINT32 m_Cookie;
352
353 /*------------------------------------------------*/
354 // functions of the CL protocol DLL
355 /*------------------------------------------------*/
357 CLINT32 (__cdecl *m_clpInitLib)( clp_logger_t logger, CLP_LOG_LEVEL_VALUE logLevel);
358
360 CLINT32 (__cdecl *m_clpCloseLib)( void );
361
363 CLINT32 (__cdecl *m_clpGetShortDeviceIDTemplates) (CLINT8* pDeviceTemplates, CLUINT32* pBufferSize );
364
366 CLINT32 (__cdecl *m_clpProbeDevice) (ISerial *pSerial, const CLINT8* pDeviceIDTemplate, CLINT8* pDeviceID, CLUINT32 *pBufferSize, CLUINT32 *pCookie, const CLUINT32 TimeOut );
367
369 CLINT32 (__cdecl *m_clpGetXMLIDs) ( ISerial *pSerial, const CLUINT32 Cookie ,CLINT8* pXMLIDs, CLUINT32* pBufferSize, const CLUINT32 TimeOut );
370
372 CLINT32 (__cdecl *m_clpGetXMLDescription) (ISerial *pSerial, const CLUINT32 Cookie, const CLINT8* pDeviceID, CLINT8* pXMLBuffer, CLUINT32* pBufferSize, const CLUINT32 TimeOut );
373
375 CLINT32 (__cdecl *m_clpReadRegister) (ISerial *pSerial, const CLUINT32 Cookie, const CLINT64 Address, CLINT8* pBuffer, const CLINT64 BufferSize, const CLUINT32 TimeOut );
376
378 CLINT32 (__cdecl *m_clpWriteRegister) (ISerial *pSerial, const CLUINT32 Cookie, const CLINT64 Address, const CLINT8* pBuffer, const CLINT64 BufferSize, const CLUINT32 TimeOut );
379
381 CLINT32 (__cdecl *m_clpContinueWriteRegister) (ISerial *pSerial, const CLUINT32 Cookie, const BOOL8 ContinueWaiting, const CLUINT32 TimeOut );
382
384 CLINT32 (__cdecl *m_clpGetErrorText) (const CLINT32 errorCode, CLINT8* errorText, CLUINT32* errorTextSize, const CLUINT32 Cookie );
385
387 CLINT32 (__cdecl *m_clpDisconnect) (const CLUINT32 Cookie );
388
390 CLINT32 (__cdecl *m_clpGetCLProtocolVersion) (CLUINT32 *pVersionMajor, CLUINT32 *pVersionMinor );
391
393 CLINT32 (__cdecl *m_clpGetParam) (ISerial *pSerial, CLP_PARAMS param, const CLUINT32 Cookie, const CLINT8* pBuffer, const CLINT64 BufferSize, const CLUINT32 TimeOut);
394
396 CLINT32 (__cdecl *m_clpSetParam) (ISerial *pSerial, CLP_PARAMS param, const CLUINT32 Cookie, const CLINT8* pBuffer, const CLINT64 BufferSize, const CLUINT32 TimeOut);
397
399 CLINT32 (__cdecl *m_clpIsParamSupported) (CLP_PARAMS param);
400
402 CLINT32 (__cdecl *m_clpGetEventData) (const CLUINT32 Cookie, CLINT8* pBuffer, CLUINT32* pBufferSize);
403
404 // What 1.1 feature are supported by the device protocol?
406 bool m_protocolHasBaudratePrms;
407
409 bool m_protocolHasLogLevelPrm;
410
412 bool m_protocolHasLoggerPrm;
413
415 bool m_protocolHasStopProbeDevice;
416
418 static CLP_LOG_LEVEL_VALUE m_defaultloglevel;
419
421 static CLUINT32 m_stopProbing;
422 private:
424 CCLPort( CCLPort& );
425
427 CCLPort& operator=( CCLPort& );
428 };
429
430#ifdef _MSC_VER
431# pragma warning(pop)
432#endif
433
434}
435#endif // CLPROTOCOL_CLPORT_H
Wraps a CameraLink protocol DLL and implements the IPort and the ISerial interface.
Definition CLPort.h:74
virtual GENAPI_NAMESPACE::EAccessMode GetAccessMode() const
Get the access mode of the node.
static void Terminate()
Cleans up static variables.
static void RetrievePortIDDeviceIDPairs(GENICAM_NAMESPACE::gcstring_vector &PortIDs, GENICAM_NAMESPACE::gcstring_vector &DeviceIDs)
Retrieves a PortID/DeviceID pair.
CCLPort()
Public constructor.
void SetDeviceBauderate(const CLUINT32 baudrate)
Set device bauderate using one of the CL_BAUDRATE_XXXX value.
virtual GENAPI_NAMESPACE::EInterfaceType GetPrinicipalInterfaceType() const
We are an IPort interface.
static GENICAM_NAMESPACE::gcstring ProbeDevice(const GENICAM_NAMESPACE::gcstring &PortID, const GENICAM_NAMESPACE::gcstring &strDeviceIDTemplate, const CLUINT32 SerialTimeout=500)
Connects a camera and retrieves all information required for the DeviceID.
void SetSerialTimeOut(const CLUINT32 Timeout)
Sets the timeout for operations on the serial port.
virtual void Write(const void *pBuffer, int64_t Address, int64_t Length)
Writes a chunk of bytes to the port.
bool Connect(const GENICAM_NAMESPACE::gcstring &PortID)
Creates a port object for a given PortID taking the DeviceID from a internal cache.
void SetProtocolLogLevel(const CLP_LOG_LEVEL_VALUE logLever)
Set device protocol log lever.
CLUINT32 SupportedBaudrates()
Sed supported bauderates of the combined device and host interface.
GENICAM_NAMESPACE::gcstring MakeURLfromXMLID(GENICAM_NAMESPACE::gcstring &XMLID)
Creates a file URL for a given XML ID.
virtual ~CCLPort()
Public destructor.
static void GetPortIDs(GENAPI_NAMESPACE::StringList_t &PortIDs)
Retrieves a list of PortIDs which can be used to create a corresponding port object.
static GENICAM_NAMESPACE::gcstring RegisterSerial(const GENICAM_NAMESPACE::gcstring &PortName, ISerialAdapter *pSerialAdapter)
Register a custom serial port.
GENICAM_NAMESPACE::gcstring GetXML(GENICAM_NAMESPACE::gcstring XMLID, const bool UseMaxBaudrate=true)
Retrieves an GenApi XML description either from the DLL or the file system.
virtual CLINT32 CLPROTOCOL clSerialRead(CLINT8 *buffer, CLUINT32 *bufferSize, CLUINT32 serialTimeOut)
calls clSerialRead as defined by the camera link standard
CLUINT32 GetDeviceBauderate()
Returns the current device bauderate, using one of the CL_BAUDRATE_XXXX value.
void GetXMLIDs(GENICAM_NAMESPACE::gcstring_vector &XMLIDs)
Retrieves a list of XMLID strings.
CLINT32 GetEvent(void *buffer, CLUINT32 *bufferSize)
We can get event data.
virtual void Read(void *pBuffer, int64_t Address, int64_t Length)
Reads a chunk of bytes from the port.
CLUINT32 GetSerialTimeOut() const
Gets the timeout for operations on the serial port.
void DeleteXMLDownload(GENICAM_NAMESPACE::gcstring XMLID)
Delete the device xml file from the download folder if the file was downloaded for the camera.
virtual CLINT32 CLPROTOCOL clGetSupportedBaudRates(CLUINT32 *baudRates)
returns the valid baud rates of the current interface.
GENICAM_NAMESPACE::gcstring GetDeviceID() const
Returns the Device ID the object has been created with.
static void UnRegisterSerials()
Unregister all resource related to serial port.
void Connect(const GENICAM_NAMESPACE::gcstring &PortID, const GENICAM_NAMESPACE::gcstring &strDeviceID)
Creates a port object for a given PortID and DeviceID.
virtual CLINT32 CLPROTOCOL clSerialWrite(CLINT8 *buffer, CLUINT32 *bufferSize, CLUINT32 serialTimeOut)
calls clSerialWrite as defined by the camera link standard
static void StopProbing(CLUINT32 toStop)
Stop all running ProbeDevice.
static void SetDefaultLogLevel(const CLP_LOG_LEVEL_VALUE logLever)
Set log level that is assigned to the device protocol when the dll is loaded.
static ISerialAdapter * GetPort(const GENICAM_NAMESPACE::gcstring &PortID)
Gets a SerialAdapter port.
static void GetDeviceIDTemplates(GENICAM_NAMESPACE::gcstring_vector &DeviceIDTemplates)
Retrieves a list of DeviceID templates.
static void UnRegisterSerial(const GENICAM_NAMESPACE::gcstring &PortID)
Unregister serial serial port.
static void StorePortIDDeviceIDPairs(GENICAM_NAMESPACE::gcstring_vector &PortIDs, GENICAM_NAMESPACE::gcstring_vector &DeviceIDs)
Stores a PortID/DeviceID pair.
GENICAM_NAMESPACE::gcstring GetXML(const bool UseMaxBaudrate=true)
Retrieves the best matching GenApi XML description either from the DLL or the file system.
Abstract interface used by the CLProtocol driver to use a serial port.
Definition ISerial.h:43