This repository demonstrates how to create a reusable TCP communication layer (CSM-TCP-Router) to turn a local program into a TCP server for remote control. This example showcases the advantages of the CSM framework's invisible bus.
- All CSM messages that can be sent locally can be transmitted to the local program via TCP connection 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.
Important
TCP Packet Format:
| Data Length (4 bytes) | CSM Command String (plain text) |
Note
Example: Suppose there is a CSM module named DAQmx locally with an interface "API: Start Sampling". Locally, we can send messages to this module to control the start and stop of sampling:
- API: Start Sampling -@ DAQmx // Synchronous message
- API: Start Sampling -> DAQmx // Asynchronous message
- API: Start Sampling ->| DAQmx // Asynchronous message without return
Now, by sending the same text message via TCP connection, remote control can be achieved.
Warning
Currently, CSM-TCP-Router only supports synchronous messages (-@) and asynchronous messages without return (->|). Asynchronous messages (->) will be treated as asynchronous messages without return.
Defined by the original code developed based on CSM. Since the CSM framework transmits messages through an invisible bus, all communication can be implemented without intrusive code changes.
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 TCP communication layer (CSM-TCP-Router). The functions managed by the CSM module can be remotely controlled by defining commands.
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
A standard CSM-TCP-Router Client is provided in the code. It also has some built-in commands that cannot be used if developed based on the command set.
Bye
: DisconnectSwitch
: Switch modules to omit the module name when inputting commands; switches back to default mode if no parameter is provided- 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
Bye
in 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