From 1236bcee420da713e373a4a6b8cec279749c3d74 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 1 Dec 2018 16:01:54 +0100 Subject: Connect with serial Signed-off-by: Szczepan Zalega --- device.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'device.cc') diff --git a/device.cc b/device.cc index 80e4b38..ef295e8 100644 --- a/device.cc +++ b/device.cc @@ -29,6 +29,7 @@ #include "libnitrokey/device.h" #include "libnitrokey/log.h" #include +#include #include "DeviceCommunicationExceptions.h" #include "device.h" @@ -96,7 +97,13 @@ bool Device::_connect() { // hid_init(); // done automatically on hid_open if (m_path.empty()){ - mp_devhandle = hid_open(m_vid, m_pid, nullptr); + const wchar_t* serial = nullptr; + if (!m_serial.empty()){ + std::wstring_convert> converter; + auto wstr = converter.from_bytes(m_serial.c_str()); + serial = wstr.c_str(); + } + mp_devhandle = hid_open(m_vid, m_pid, serial); } else { mp_devhandle = hid_open_path(m_path.c_str()); } @@ -105,6 +112,10 @@ bool Device::_connect() { return success; } +void Device::set_serial(const std::string serial){ + m_serial = serial; +} + void Device::set_path(const std::string path){ m_path = path; } -- cgit v1.2.3