Serial to Socket Transmitter

Principle

The MicroEJ Serial to Socket Transmitter is a tool which transfers all bytes from a serial port to a TCP client or TCP server.

It is typically used to transfer the output traces of a testsuite executed on a device.

Use

To start transferring data from the COM0 serial port to the port 5555, execute the serialToSocket task as follows:

./gradlew serialToSocket

After the execution of the task, you should see a message similar to the following one:

INFO: Now listening on Serial Port COM0
INFO: Redirecting to localhost:5555.

To customize the serial port, baudrate, socket port or socket address, you can provide the corresponding properties (see Options).

Options

The Serial to Socket Transmitter is configured in the serialToSocket block of the microej extension, in the build.gradle.kts file of your project:

microej {
    serialToSocket {
        serialPort = "COM0"
        socketPort = 5555
        baudRate = 115200
        dataBits = 8
        stopBits = 1
        parity = "none"
    }
}

Tip

The serial port usually differs from one developer to another, so it is better not to commit it. Rather than hardcoding serialPort, read it from the microej.serialPort Gradle property:

microej {
    serialToSocket {
        serialPort = providers.gradleProperty("microej.serialPort").getOrElse("COM0")
    }
}

Each developer can then define the port in a file that is not tracked by Git, typically their global ~/.gradle/gradle.properties file:

microej.serialPort=COM12

Because ~/.gradle/gradle.properties is global, this value is shared by every testsuite, so the port is configured once for all of them. To avoid repeating the serialToSocket block itself in each testsuite, define it in a build script shared by your testsuites (for example validation/build.gradle.kts). A ready-to-use commented example is available in the vee-port/validation/net/build.gradle.kts file of the VEE Port project template.

  • serialPort: Defines the COM port.

    • Default value: COM0

      • Windows: COM1, COM2, , COM*n*

      • Linux: /dev/ttyS0, /dev/ttyUSB0, , /dev/ttyS*n*, /dev/ttyUSB*n*

  • socketPort: Defines the TCP server port.

    • Default value: 5555

  • socketAddress: Defines the TCP server address.

    • This option has no default value, if not set, the transmitter will act as a TCP server (hosting on localhost), otherwise it will act as a TCP client connecting to the specified address.

  • baudRate: Defines the COM baud rate.

    • Default value: 115200

    • Available values:
      • 9600

      • 38400

      • 57600

      • 115200

  • dataBits: Defines the number of data bits transmitted in each serial frame.

    • Default value: 8

  • stopBits: Defines the number of stop bits used to signal the end of a serial frame.

    • Default value: 1

  • parity: Defines the parity checking method.

    • Default value: none

    • Available values:
      • none

      • even

      • odd