Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
Cahute 0.6
Logo
Cahute 0.6
  • Installation guides
    • Installing Cahute on Linux distributions
    • Installing Cahute on macOS / OS X
    • Installing Cahute on Microsoft Windows
    • Installing Cahute on AmigaOS
  • Build from source guides
    • Building Cahute for Linux distributions
    • Building Cahute for macOS / OS X
    • Building Cahute for Microsoft Windows
    • Building Cahute for AmigaOS
  • Contribution guides
    • Contributing to Cahute
    • Reporting a bug or vulnerability
    • Requesting a feature
    • Packaging Cahute
    • Creating a merge request
  • Command line user guides
    • Getting information regarding a calculator
    • Sending a file to a calculator’s storage memory
    • Getting a file from the calculator’s storage memory
    • Displaying the screen from a calculator
  • Developer guides
    • Building with the Cahute library
    • Using device detection
      • Listing calculators connected by USB
      • Listing available serial ports
    • Using links
      • Opening a link to a calculator connected by USB
      • Opening a generic link to a calculator connected by serial
    • Reading and writing files
      • Guessing the type of a file
    • Using text conversion utilities
      • Converting text from an encoding to another
  • Miscellaneous guides
    • Getting started with Cahute in Visual Studio
    • Capturing USB communications on Windows using Wireshark
  • Data formats
    • Number formats
    • Picture formats
    • Text encodings
    • File formats
      • fx-CG add-ins
      • fx-9860G add-ins
      • Calculator Text Format (CTF)
      • CASIOLINK archives
      • casrc configuration file
      • Catalog files (CAT)
      • e-Activity files
      • fx-CG f-key files
      • fx-9860G f-key files
      • FX Program (FXP)
      • GraphCard file format
      • fx-CG language files
      • fx-9860G language files
      • Main memory archives
      • fx-CG picture
      • fx-CP picture
  • Communication protocols
    • Rationales behind the communication protocols
    • Transport medium and protocols
    • USB detection for CASIO calculators
    • CASIOLINK protocols – Serial protocols used by pre fx-9860G calculators
    • CAS40 protocol – Serial protocol used by pre-1996 calculators
      • CAS40 packet format
      • CAS40 data types
      • CAS40 flows
    • CAS50 protocol – Serial protocol used by calculators from 1996 to 2004
      • CAS50 packet format
      • CAS50 data types
      • CAS50 flows
    • CAS100 protocol – Serial protocol used by AFX / Graph 100
      • CAS100 packet format
      • CAS100 data types
      • CAS100 flows
    • CAS300 – Serial and USB protocol used by Classpad 300 / 330 (+)
      • CAS300 packet format
      • CAS300 commands
      • CAS300 flows
    • Protocol 7.00 – Serial and USB protocol used by post fx-9860G calculators
      • Specific formats for Protocol 7.00
      • Protocol 7.00 packet format
      • Protocol 7.00 communication flows
      • Known Protocol 7.00 commands by CASIO
      • Known Protocol 7.00 command extensions in fxRemote
      • Protocol 7.00 use cases
      • Known hardware identifiers for Protocol 7.00
    • Protocol 7.00 Screenstreaming – fx-9860G and fx-CG screenstreaming
      • Protocol 7.00 Screenstreaming packet format
      • Protocol 7.00 Screenstreaming communication flows
    • USB Mass Storage (UMS)
  • Cahute features
    • System compatibility
    • Contexts
    • Links and mediums
    • Files
    • Main memory data
    • Logging facilities
  • Cahute internals
    • Internal compatibility utilities
    • Links and medium internals
    • File internals
    • Characters, encodings and conversions
  • Command line reference
    • CaS command-line reference
    • p7 command line reference
    • p7os command line reference
    • p7screen command line reference
    • xfer9860 command line reference
  • Header reference
    • <cahute.h> – Main header for Cahute
      • <cahute/cdefs.h> – Basic definitions for Cahute
      • <cahute/config.h> – Cahute configuration details
      • <cahute/context.h> – Context management for Cahute
      • <cahute/data.h> – Calculator data resource and methods for Cahute
      • <cahute/detection.h> – Device detection for Cahute
      • <cahute/error.h> – Error definitions for Cahute
      • <cahute/file.h> – File related utilities for Cahute
      • <cahute/link.h> – Calculator link resource and methods for Cahute
      • <cahute/logging.h> – Logging control for Cahute
      • <cahute/path.h> – Path related utilities for Cahute
      • <cahute/picture.h> – Picture format related utilities for Cahute
      • <cahute/text.h> – Text encoding related utilities for Cahute
  • CMake setting reference
  • Project management
    • Project governance
    • Git and release versioning
    • Community feedback
    • Contribution style
    • Coding style
Back to top

Opening a generic link to a calculator connected by serial¶

Opening a generic link can be useful if you want to implement your own custom protocol for your CASIO calculator, and do not want to deal with system-specific complexities Cahute has already implemented.

In order to open a link to a calculator plugged in over serial in order to use the link medium access functions, the steps are the following:

  1. Create a context using cahute_create_context().

  2. Open the link using cahute_open_serial_link() with the CAHUTE_SERIAL_PROTOCOL_NONE flag.

  3. Profit!

  4. Call cahute_close_link() to close the link.

  5. Call cahute_destroy_context() to destroy the context.

The functions you can use with generic links are described in Link medium access related function declarations.

An example program that uses generic links to read two characters, then write two characters, is the following:

/* Compile using: gcc use-generic-serial-link.c `pkg-config cahute --cflags --libs`. */

#include <stdio.h>
#include <cahute.h>

int main(void) {
    cahute_context *context;
    cahute_link *link = NULL;
    cahute_u8 buf[2];
    int err, ret = 1;

    err = cahute_create_context(&context);
    if (err) {
        fprintf(
            stderr,
            "cahute_create_context() has returned error %s.\n",
            cahute_get_error_name(err)
        );
        return 1;
    }

    err = cahute_open_serial_link(
        context,
        &link,
        CAHUTE_SERIAL_PROTOCOL_NONE,
        "/dev/ttyUSB0",
        0
    );
    if (err) {
        fprintf(
            stderr,
            "cahute_open_serial_link() has returned %s.\n",
            cahute_get_error_name(err)
        );
        goto fail;
    }

    buf[0] = 'A';
    buf[1] = 'B';

    err = cahute_send_on_link(link, buf, 2);
    if (err) {
        fprintf(
            stderr,
            "cahute_send_on_link() has returned %s.\n",
            cahute_get_error_name(err)
        );
        goto fail;
    }

    err = cahute_receive_on_link(link, buf, 2, 0, 0);
    if (err) {
        fprintf(
            stderr,
            "cahute_receive_on_link() has returned %s.\n",
            cahute_get_error_name(err)
        );
        goto fail;
    }

    printf("Received characters are the following: %c%c\n", buf[0], buf[1]);

    ret = 0;

fail:
    if (link)
        cahute_close_link(link);

    cahute_destroy_context(context);
    return 0;
}

In order to test this, you will need a USB/serial cable and an add-in such as Serial monitor. Once the cable plugged into both the computer and the calculator[1], if you run the program:

  1. You will see the two characters AB appear on your calculator.

  2. You can type in two other characters, e.g. CD, on your calculator.

  3. The two characters you typed on the calculator will appear on the host.

An example output of the program is the following:

[2024-09-01 01:42:12    cahute info] set_serial_params_to_link_medium: Setting serial parameters to 9600N1.
[2024-09-01 01:42:12    cahute info] open_link_from_medium: Using Generic (serial) over Serial (POSIX).
[2024-09-01 01:42:12    cahute info] open_link_from_medium: Playing the role of sender / active side.
[2024-09-01 01:42:16    cahute info] receive_on_link_medium: Read 2 bytes in 383ms (after waiting 2746ms).
Received characters are the following: CD
[2024-09-01 01:42:16    cahute info] close_link: Closing the link.
[1]

You may need to adapt the path from the program to match the one present on your host system, such as /dev/ttyUSB1 or /dev/cu.something.

Next
Reading and writing files
Previous
Opening a link to a calculator connected by USB
Copyright © 2024, Thomas Touhey
Made with Sphinx and @pradyunsg's Furo