| Visioscan Set SDK Libraries 1.3.5 Visioscan Set SDK Help documentation file for C++ and C++/CLI |

Loading...
Searching...
No Matches
UsbCommunication.h
1#pragma once
2
3#pragma comment(lib, "Ws2_32.lib")
4#include "BaseCommunication.h"
5#include "UsbSettings.h"
6
7#include <thread>
8#include "UsbInformation.h"
9#include "ClockUtilities.h"
10
11#ifdef STARFLEETTOOLBOX_EXPORTS
12#define USBCOMM __declspec(dllexport)
13#else
14#define USBCOMM __declspec(dllimport)
15#endif
16
20 typedef struct UsbDevice {
21 struct libusb_transfer* transfer;
22 struct libusb_device_handle* device_handle;
23 unsigned char input_endpoint;
24 struct libusb_context* usbContext;
25
26 BaseDataExtractor* extractor; // a pointer to the communication extractor
27 HANDLE dataAvailableSemaphore; // semaphore to warn that Command ACK is available
28 HANDLE rawDataAvailableSemaphore; // semaphore to warn that RAW Data are available
29 HANDLE semReadyToConsume; // synchronisation for data consumed
30 string commandResult; // the command result
31 bool treat = false; // indicates if data treater is in treatment
32 vector<string> localVector; // temporary local vector
33 RawData extractedData; // the extracted raw data
34 bool interruptTransfer = true; // indicates a transfert interruption
35 CommunicationStatus commStatus; // the connection status
36 atomic<chrono::time_point<std::chrono::steady_clock>> lastUsbDataTime; // the last raw data sent
37 int* callbackConnectionStatus;
38};
39
43 class USBCOMM UsbCommunication :
44 public BaseCommunication
45{
46 public:
47 const int COMMAND_ACK_TIMEOUT = 20000;
48 const int MAX_SIZE_TO_READ = 40000;
49
53 UsbCommunication();
54 UsbCommunication(MONITORING_MODE monitoring);
58 UsbCommunication(UsbSettings* settings);
59 UsbCommunication(UsbSettings* settings, MONITORING_MODE monitoring);
63 ~UsbCommunication();
64
68 CommunicationStatus Connect();
72 CommunicationStatus Connect(bool reconnecting);
73
77 void Disconnect();
78
79
85 string SendCommand(string commandToSend);
86
93 string SendCommand(string commandToSend, int specificTimeout);
94
101 RawData WaitForRawData(int waitTimeout, unsigned long* semStatus);
102
108 static vector<UsbInformation> GetDeviceList();
109 protected:
114 CommunicationStatus GetConnectionStatus();
115 private:
116 atomic<chrono::time_point<std::chrono::steady_clock>> _lastUsbDataTime;
117
118 void Disconnect(bool reconnecting);
119 CommunicationStatus Reconnect();
120 std::atomic<bool> _stopHandle;
121 std::atomic<bool> _connected;
122
123 std::atomic<bool> _alreadydisconnected;
124 std::atomic<bool> _disconnectCalledByPeer;
125
126
127 std::atomic<int> _mainConnectionStatus; // useful for monitoring
128 int _callbackConnectionStatus = 0;
129
130 UsbDevice usbDevice;
131 thread _usbReceiveData;
132
133 HANDLE _mutexSendAvailable; // prevent the socket to be used from another process to send data
134
139 void UsbEventDataReceiverBusiness(void* param);
140
146 static void __stdcall callbackUSBReadTransferComplete(struct libusb_transfer* xfr);
147};
148
CommunicationStatus
Definition CommunicationStructures.h:24
RawData
The base class encapsulating sensor's RAW data.
Definition RawData.h:14
UsbDevice
A structure definition to handle USB callback event.
Definition UsbCommunication.h:20
UsbDevice::extractor
BaseDataExtractor * extractor
Definition UsbCommunication.h:26
UsbDevice::commandResult
string commandResult
Definition UsbCommunication.h:30
UsbDevice::transfer
struct libusb_transfer * transfer
Definition UsbCommunication.h:21
UsbDevice::extractedData
RawData extractedData
Definition UsbCommunication.h:33
UsbDevice::dataAvailableSemaphore
HANDLE dataAvailableSemaphore
Definition UsbCommunication.h:27
UsbDevice::device_handle
struct libusb_device_handle * device_handle
Definition UsbCommunication.h:22
UsbDevice::treat
bool treat
Definition UsbCommunication.h:31
UsbDevice::interruptTransfer
bool interruptTransfer
Definition UsbCommunication.h:34
UsbDevice::lastUsbDataTime
atomic< chrono::time_point< std::chrono::steady_clock > > lastUsbDataTime
Definition UsbCommunication.h:36
UsbDevice::callbackConnectionStatus
int * callbackConnectionStatus
Definition UsbCommunication.h:37
UsbDevice::localVector
vector< string > localVector
Definition UsbCommunication.h:32
UsbDevice::semReadyToConsume
HANDLE semReadyToConsume
Definition UsbCommunication.h:29
UsbDevice::input_endpoint
unsigned char input_endpoint
Definition UsbCommunication.h:23
UsbDevice::commStatus
CommunicationStatus commStatus
Definition UsbCommunication.h:35
UsbDevice::usbContext
struct libusb_context * usbContext
Definition UsbCommunication.h:24
UsbDevice::rawDataAvailableSemaphore
HANDLE rawDataAvailableSemaphore
Definition UsbCommunication.h:28
UsbCommunication
This class handles the USB communication.
Definition UsbCommunication.h:45
UsbSettings
The USB settings encapsulation for USB communication.
Definition UsbSettings.h:18