NaoNaoMe/USBTMC-Host-Driver

Callbacks or Serial Number for OnReceived

Closed this issue · 2 comments

Hi there,

assuming a Setup with multiple TMC Devices, would it be possible in USBTMCAsync::OnReceived to know which Device (by SerialNumber?) the received Message is from?

further, would be possible to access received data from the Class?

Usbtmc.Run();
Usbtmc.Request("MEAS:VOLT:DC?");
// something like this?
Usbtmc.Receive(); // -> return value float 2.23 | e.g. Results in Volts from a Multimeter.

What i want to achieve is tracability or correlation from a specific request to it's response.

Thanks!

Hello,

Sorry to late response.
To specify the device you want to communicate with, you can use the VID and PID of the device, like so:

USBTMC Usbtmc(&Usb, &UsbtmcAsync, 0x0957, 0x0618);

You can replace 0x0957 and 0x0618 with the VID and PID of your device. To find the VID and PID of your device, you can use a tool like lsusb on Linux, or the Device Manager on Windows. And also you can find this example:ValidationExample

As for your second question, to receive a response to a command, you can use the USBTMC_HELPER class. Here's an example code snippet:

#include <USBTMC_HELPER.h>

USBTMC_HELPER worker(&Usb,&AsyncOper);
...
String command = F("ACQ:STATE?");
worker.write(command);
String response = worker.read(1000);
if(response == "") {
 // Timetout
}
else {
 // Success: you have received the response message
}

You can find this example, along with the USBTMC_HELPER class, in this GitHub repository:TekScopeWithIRremote

I hope this helps! Let me know if you have any further questions.

Yup, the USBTMC_HELPER was exactly what i needed. Thank you so much!