Skip to content

How to use

Ushakov Michael (Ушаков Михаил) edited this page Jun 25, 2018 · 5 revisions

Interface of EasyUsb is a quite simple with 2 methods: Read and Write, open occur at constructing of object of UsbTransciever and close at destructing.

  1. Open - UsbTransceiver In constructor you are pass:
    • vid (device vendor id)
    • pid (device product id)
    • interfaces (list of interfaces)
    • configuration - number of configuration of usb device descriptor
    • timeout (number of ms 4 waiting transfer operation to complete), this parameter has default value, in case of this (0) UsbTransceiver use 2000 ms.
    • isAsync (type of libusb API that is used for interact with usb device). Unfortunately in this version there is no calback for waiting transaction to complete, everything process internally. In some casess async API of libusb works better than sync.

Example: std::vector<unsigned char> interfaces = {0, 1, 2, 3, 4}; std::shared_ptr<EasySoftUsb::UsbTransceiver> transceiver = std::shared_ptr<EasySoftUsb::UsbTransceiver> (new EasySoftUsb::UsbTransceiver(0x2500, 0x0022, interfaces, 1); // timeout will be 2000ms, operation are async

  1. Close ~UsbTransceiver

nothing to comment, but in case of use std::shared_ptr this could be done as : transceiver.reset();

  1. Write operation

`

std::vector<EasySoftUsb::TransferPacket> firmware = EasyUsrp::ImageLoader::GetFirmwareLoader().Load(firmareFile);

    for(std::vector<EasySoftUsb::TransferPacket>::iterator it = firmware.begin(); it != firmware.end(); it++)
        _transceiver->Write(*it);

`

  1. Read operation

`

int bytesRead = 0;
EasySoftUsb::TransferPacket packet = EepromHelper::GetReadRequest();
_transceiver->Read(packet, bytesRead);
return packet._data;

`

Clone this wiki locally