This repository demonstrates how to build a reusable TCP communication layer—CSM-TCP-Router—that turns a local program into a TCP server for remote control, showcasing the power of the CSM framework's invisible bus.
- Any CSM message that can be sent locally can also be transmitted to the local program over TCP, using CSM synchronous and asynchronous message formats.
- Based on the JKI-TCP-Server library, it supports multiple TCP clients connecting simultaneously.
- [client] Provides a standard TCP client that can connect to the server to verify remote connections and message sending.
The TCP packet format used in the CSM-TCP-Router is defined as follows:
| Data Length (4B) | Version (1B) | TYPE (1B) | FLAG1 (1B) | FLAG2 (1B) | Text Data |
╰───────────────────────────────── Header ──────────────────────────────╯╰─── Data Length Range ──╯
This field specifies the packet type as an enumerated value. Supported types are:
- Information Packet (
info) -0x00: Sent by the server when a client connects (welcome message) and when the connection is closed (goodbye message) - Error Packet (
error) -0x01 - Command Packet (
cmd) -0x02 - Command Response Packet (
cmd-resp) -0x03 - Synchronous Response Packet (
resp) -0x04 - Asynchronous Response Packet (
async-resp) -0x05 - Status Broadcast Packet (
status) -0x06 - Interrupt Broadcast Packet (
interrupt) -0x07
For detailed communication protocol definitions, see Protocol Design.
Defined by the existing CSM-based application code. Because the CSM framework uses an invisible bus for message passing, remote communication requires no intrusive changes to the existing code.
For example, the AI CSM module in this program provides:
Channels: List all channelsRead: Read the value of a specified channelread all: Read the values of all channels
These messages can be sent to the local program via TCP connection for remote control.
Defined by the CSM-TCP-Router layer. These commands expose the management functions of CSM modules for remote control.
List: List all CSM modulesList API: List all APIs of a specified moduleList State: List all CSM states of a specified moduleHelp: Display the help file of the module, stored in the Documentation field of the CSM VIRefresh lvcsm: Refresh the cache file
The bundled standard CSM-TCP-Router Client includes additional built-in commands that are not available when building on the command set API.
Bye: DisconnectSwitch: Switch the active module to omit the module name when entering commands; omit the parameter to switch back to the default mode- TAB key: Automatically focus on the input dialog box
- Install this tool and dependencies via VIPM
- Open the example project CSM-TCP-Router.lvproj in the CSM examples
- Start the CSM-TCP-Router(Server).vi in the code project
- Start Client.vi, enter the server's IP address and port number, and click connect
- Enter commands and click send to see the returned messages in the console
- View the history of executed messages in the log interface of the Server program
- Enter
Byein Client.vi to disconnect - Close the Server program
Search for CSM TCP Router in VIPM to download and install.
- Communicable State Machine (CSM) - NEVSTOP
- JKI TCP Server - JKI
- Global Stop - NEVSTOP
- OpenG

