Posté le 08/03/2025 21:42
Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2025 | Il y a 39 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements
Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd
Citer : Posté le 08/03/2025 21:43 | #
I couldn't attach the code that runs on the computer to the post, it won't allow the C++ file extension, so here it is:
extern "C" {
#include <fxlink/devices.h>
}
int main() {
libusb_context *ctx = nullptr;
libusb_init(&ctx);
fxlink_filter filter{};
auto delay = delay_seconds(5);
auto fdev = fxlink_device_find_wait(ctx, &filter, &delay);
if (!fdev) {
std::cerr << "Can't find device" << std::endl;
return 1;
}
if (!fxlink_device_ready_to_connect(fdev)) {
std::cerr << "Can't connect to device" << std::endl;
return 1;
}
if (!fxlink_device_has_fxlink_interface(fdev)) {
std::cerr << "Can't find fxlink interface" << std::endl;
return 1;
}
if (!fxlink_device_claim_fxlink(fdev)) {
std::cerr << "Can't claim fxlink" << std::endl;
return 1;
}
if (!fxlink_device_start_bulk_OUT(fdev, "calcbet", "msg", "hello", 5, false)) {
std::cerr << "Can't start bulk out" << std::endl;
}
return 0;
}
Citer : Posté le 08/03/2025 23:24 | #
Hi! The issue is that the computer side just leaves before the transfer is complete. start_OUT(), as the name clumsily suggests, just starts the transfer asynchronously. You need to wait before returning:
std::cerr << "Can't start bulk out" << std::endl;
}
while(fdev->comm->ftransfer_OUT)
libusb_handle_events(ctx);
Now because the fxlink library was developed alongside the TUI, which leans heavily on async functions (good async was the whole reason this got made), I never got around to writing an actual easy-to-use synchronous API, which is how this wait was not mentioned in the header and you somehow need to access the structure directly to check if a transfer exists.
I just pushed a few functions to help with that. One checks if a there is a transfer ongoing. The second one provides this wait feature:
std::cerr << "Can't start bulk out" << std::endl;
}
fxlink_device_wait_bulk_OUT(ctx, fdev);
The last one allows you to perform a synchronous transfer.
std::cerr << "Couldn't send message" << std::endl;
}
This should make simple uses of the library a bit more straightforward.