Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Autres questions


Index du Forum » Autres questions » Sending data over USB
Braaandon Hors ligne Membre Points: 9 Défis: 0 Message

Sending data over USB

Posté le 08/03/2025 21:42

Hi,

I am attempting to use the fxsdk/gint to engage in communication between my calculator and computer. I have attached the code I used on both ends to this post and I hope you can understand my logic from there. I only attempt to transmit a simple string, and whilst usb_fxlink_handle_messages is succesful, usb_read_sync blocks and usb_read_sync_timeout throws a timeout error. I suspect that the callback in fxlink_device_start_bulk_OUT isn't successful when sending my data, because if I call twice fxlink_device_start_bulk_OUT my usb_read_sync call just receives the header in place of my data.

When browsing the forum for any advice I did find someone with a similar issue , but sadly it never seemed to be resolved.

Fichier joint


Braaandon Hors ligne Membre Points: 9 Défis: 0 Message

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:

#include <iostream>

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;
}
Lephenixnoir En ligne Administrateur Points: 24909 Défis: 174 Message

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:

if (!fxlink_device_start_bulk_OUT(fdev, "calcbet", "msg", "hello", 5, false)) {
    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:

if (!fxlink_device_start_bulk_OUT(fdev, "calcbet", "msg", "hello", 5, false)) {
    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.

if (!fxlink_device_send_bulk_OUT(ctx, fdev, "calcbet", "msg", "hello", 5)) {
    std::cerr << "Couldn't send message" << std::endl;
}

This should make simple uses of the library a bit more straightforward.
Mon graphe (28 Janvier): (MPM ; serial gint ; (Rogue Life || HH2) ; PythonExtra ; ? ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

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