* @brief Sends @p data to the device via a synchronous bulk OUT transfer. A mutable copy of * @p data is required because libusb takes a non-const buffer and may write into it. */
| 302 | * @p data is required because libusb takes a non-const buffer and may write into it. |
| 303 | */ |
| 304 | qint64 IO::Drivers::USB::write(const QByteArray& data) |
| 305 | { |
| 306 | Q_ASSERT(!data.isEmpty()); |
| 307 | Q_ASSERT(m_handle != nullptr); |
| 308 | |
| 309 | if (!isWritable()) |
| 310 | return -1; |
| 311 | |
| 312 | int transferred = 0; |
| 313 | QByteArray mutableData(data); |
| 314 | auto* buf = reinterpret_cast<unsigned char*>(mutableData.data()); |
| 315 | |
| 316 | const int rc = libusb_bulk_transfer( |
| 317 | m_handle, m_activeOutEp, buf, static_cast<int>(data.size()), &transferred, kBulkWriteTimeout); |
| 318 | if (rc < 0) |
| 319 | return -1; |
| 320 | |
| 321 | Q_EMIT dataSent(data.left(transferred)); |
| 322 | return static_cast<qint64>(transferred); |
| 323 | } |
| 324 | |
| 325 | //-------------------------------------------------------------------------------------------------- |
| 326 | // Property getters |
no test coverage detected