LibreVNA/Software/PC_Application/LibreVNA-GUI/Calibration/LibreCAL/usbdevice.h

41 lines
971 B
C
Raw Normal View History

2022-10-01 23:10:44 +08:00
#ifndef USBDEVICE_H
#define USBDEVICE_H
#include <libusb-1.0/libusb.h>
#include <QString>
#include <set>
2022-11-14 22:40:32 +08:00
#include <functional>
2022-10-01 23:10:44 +08:00
2022-11-14 22:40:32 +08:00
#include <QObject>
class USBDevice : public QObject
2022-10-01 23:10:44 +08:00
{
2022-11-14 22:40:32 +08:00
Q_OBJECT
2022-10-01 23:10:44 +08:00
public:
// connect to a CAL device. If serial is specified only connecting to this device, otherwise to the first one found
USBDevice(QString serial = QString());
~USBDevice();
bool Cmd(QString cmd);
QString Query(QString query);
QString serial() const;
// Returns serial numbers of all connected devices
static std::set<QString> GetDevices();
2022-11-14 22:40:32 +08:00
signals:
void communicationFailure();
2022-10-01 23:10:44 +08:00
private:
static void SearchDevices(std::function<bool (libusb_device_handle *, QString)> foundCallback, libusb_context *context, bool ignoreOpenError);
bool send(const QString &s);
bool receive(QString *s);
2022-11-14 22:40:32 +08:00
bool flushRX();
2022-10-01 23:10:44 +08:00
libusb_device_handle *m_handle;
libusb_context *m_context;
QString m_serial;
};
#endif // DEVICE_H