diff --git a/.doc/.$CSM-TCP-Router.drawio.bkp b/.doc/.$CSM-TCP-Router.drawio.bkp index 5bb6cc2..ead7f13 100644 --- a/.doc/.$CSM-TCP-Router.drawio.bkp +++ b/.doc/.$CSM-TCP-Router.drawio.bkp @@ -1,54 +1,87 @@ - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + + + + - - + + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + diff --git a/.doc/CSM-TCP-Router 1.svg b/.doc/CSM-TCP-Router 1.svg new file mode 100644 index 0000000..bd185c4 --- /dev/null +++ b/.doc/CSM-TCP-Router 1.svg @@ -0,0 +1,3 @@ + + +
Server Appication
as
TCP Server
TCP Layer( Reusable)
Code Based CSM Framework
(Based on the Requirements)
TCP Client
TCP Client
TCP Client

TCP Command

  1. | Length(4 Bytes) | CSM Command(Text) |
  2. All CSM command from your code is supported
  3. System command provided by TCP Layer is supported
    list/help/list api ...


\ No newline at end of file diff --git a/.doc/CSM-TCP-Router.drawio b/.doc/CSM-TCP-Router.drawio index 33aabe3..28cc0e5 100644 --- a/.doc/CSM-TCP-Router.drawio +++ b/.doc/CSM-TCP-Router.drawio @@ -1,54 +1,84 @@ - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + + + + - - + + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + diff --git a/.doc/Client.png b/.doc/Client.png new file mode 100644 index 0000000..e1998f3 Binary files /dev/null and b/.doc/Client.png differ diff --git a/.doc/image.png b/.doc/image.png new file mode 100644 index 0000000..a8cb74f Binary files /dev/null and b/.doc/image.png differ diff --git a/.gitignore b/.gitignore index 523644b..f2c8959 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.aliases *.lvlps /vip/*.vip +*.bkp \ No newline at end of file diff --git a/CSM-TCP-Router.vipb b/CSM-TCP-Router.vipb index 97ac64a..025a5af 100644 --- a/CSM-TCP-Router.vipb +++ b/CSM-TCP-Router.vipb @@ -1,16 +1,16 @@ - + NEVSTOP_lib_CSM_TCP_Router_Example - 2025.1.27.2 + 2025.2.0.2 false src vip NEVSTOP - + Apache-2.0 20.0 true - 00000D7E002800000C9A00000400000200020022002200080000000000FFFFFF00FF80000000FFFFFFFFFFFF0000FFFFFFFFCCCC0000FFFFFFFF99990000FFFFFFFF66660000FFFFFFFF33330000FFFFFFFF00000000FFFFCCCCFFFF0000FFFFCCCCCCCC0000FFFFCCCC99990000FFFFCCCC66660000FFFFCCCC33330000FFFFCCCC00000000FFFF9999FFFF0000FFFF9999CCCC0000FFFF999999990000FFFF999966660000FFFF999933330000FFFF999900000000FFFF6666FFFF0000FFFF6666CCCC0000FFFF666699990000FFFF666666660000FFFF666633330000FFFF666600000000FFFF3333FFFF0000FFFF3333CCCC0000FFFF333399990000FFFF333366660000FFFF333333330000FFFF333300000000FFFF0000FFFF0000FFFF0000CCCC0000FFFF000099990000FFFF000066660000FFFF000033330000FFFF000000000000CCCCFFFFFFFF0000CCCCFFFFCCCC0000CCCCFFFF99990000CCCCFFFF66660000CCCCFFFF33330000CCCCFFFF00000000CCCCCCCCFFFF0000CCCCCCCCCCCC0000CCCCCCCC99990000CCCCCCCC66660000CCCCCCCC33330000CCCCCCCC00000000CCCC9999FFFF0000CCCC9999CCCC0000CCCC999999990000CCCC999966660000CCCC999933330000CCCC999900000000CCCC6666FFFF0000CCCC6666CCCC0000CCCC666699990000CCCC666666660000CCCC666633330000CCCC666600000000CCCC3333FFFF0000CCCC3333CCCC0000CCCC333399990000CCCC333366660000CCCC333333330000CCCC333300000000CCCC0000FFFF0000CCCC0000CCCC0000CCCC000099990000CCCC000066660000CCCC000033330000CCCC0000000000009999FFFFFFFF00009999FFFFCCCC00009999FFFF999900009999FFFF666600009999FFFF333300009999FFFF000000009999CCCCFFFF00009999CCCCCCCC00009999CCCC999900009999CCCC666600009999CCCC333300009999CCCC0000000099999999FFFF000099999999CCCC0000999999999999000099999999666600009999999933330000999999990000000099996666FFFF000099996666CCCC0000999966669999000099996666666600009999666633330000999966660000000099993333FFFF000099993333CCCC0000999933339999000099993333666600009999333333330000999933330000000099990000FFFF000099990000CCCC000099990000999900009999000066660000999900003333000099990000000000006666FFFFFFFF00006666FFFFCCCC00006666FFFF999900006666FFFF666600006666FFFF333300006666FFFF000000006666CCCCFFFF00006666CCCCCCCC00006666CCCC999900006666CCCC666600006666CCCC333300006666CCCC0000000066669999FFFF000066669999CCCC0000666699999999000066669999666600006666999933330000666699990000000066666666FFFF000066666666CCCC0000666666669999000066666666666600006666666633330000666666660000000066663333FFFF000066663333CCCC0000666633339999000066663333666600006666333333330000666633330000000066660000FFFF000066660000CCCC000066660000999900006666000066660000666600003333000066660000000000003333FFFFFFFF00003333FFFFCCCC00003333FFFF999900003333FFFF666600003333FFFF333300003333FFFF000000003333CCCCFFFF00003333CCCCCCCC00003333CCCC999900003333CCCC666600003333CCCC333300003333CCCC0000000033339999FFFF000033339999CCCC0000333399999999000033339999666600003333999933330000333399990000000033336666FFFF000033336666CCCC0000333366669999000033336666666600003333666633330000333366660000000033333333FFFF000033333333CCCC0000333333339999000033333333666600003333333333330000333333330000000033330000FFFF000033330000CCCC000033330000999900003333000066660000333300003333000033330000000000000000FFFFFFFF00000000FFFFCCCC00000000FFFF999900000000FFFF666600000000FFFF333300000000FFFF000000000000CCCCFFFF00000000CCCCCCCC00000000CCCC999900000000CCCC666600000000CCCC333300000000CCCC0000000000009999FFFF000000009999CCCC0000000099999999000000009999666600000000999933330000000099990000000000006666FFFF000000006666CCCC0000000066669999000000006666666600000000666633330000000066660000000000003333FFFF000000003333CCCC0000000033339999000000003333666600000000333333330000000033330000000000000000FFFF000000000000CCCC0000000000009999000000000000666600000000000033330000EEEE000000000000DDDD000000000000BBBB000000000000AAAA0000000000008888000000000000777700000000000055550000000000004444000000000000222200000000000011110000000000000000EEEE000000000000DDDD000000000000BBBB000000000000AAAA0000000000008888000000000000777700000000000055550000000000004444000000000000222200000000000011110000000000000000EEEE000000000000DDDD000000000000BBBB000000000000AAAA0000000000008888000000000000777700000000000055550000000000004444000000000000222200000000000011110000EEEEEEEEEEEE0000DDDDDDDDDDDD0000BBBBBBBBBBBB0000AAAAAAAAAAAA000088888888888800007777777777770000555555555555000044444444444400002222222222220000111111111111000000000000000000F881818181818181818181818181818181818181818181818181818181F800F8817575757575757575757575757575757575757575757575757575757581F88100000000000000000000000000000000000000000000000000000000000081810000000000000000000000000000000000000000000000000000000000008181000000000000000000000000000000000000000000000000000000000000818100C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5000000000000000000000000818100C5C50000C5C5C5000000C500C5C5C500C5000000000000000000000000818100C500C5C500C500C5C5C5C50000C50000C5000000000000000000000000818100C500C5C5C5C5C50000C5C500C500C500C500000000C9C9C9C9C9000000818100C500C5C500C5C5C5C500C500C5C5C500C5000000C90000000000C90000818100C5C50000C5C5000000C5C500C5C5C500C50000C90000C9C9C90000C900818100C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C500000000C9000000C900C9008181000000002BFF2B2B2B0000002BFF2B2B2B0000000000C9000000C900C90081810000000000FF2B000000000000FF2B0000000000000000C90000C900C9008181000000FFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000C900C90000C9008181000000002B2B2B2B2BFF2B2B2B2B2B2B2B0000000000C900C90000C900008181000000000000000000FF2B0000000000000000000000C9C90000C9000000818100000000000000C9C9C9C9C900000000C90000000000000000C900000000818100000000000000C9C9C9C9C92B00000000C9000000C90000C90000000000818100000000000000C9C9C9C9C92BC9C9C9C9C9C90000C90000C90000000000818100000000000000C9C9C9C9C92B00000000C900000000C9C9000000000000818100000000000000C9C9C9C9C92B000000C900000000000000000000000000818100000000000000002B2B2B2B2B000000000000000000000000000000000081810000000000C9C9000000000000000000000000000000000000000000000081810000000000C900C9000000000000000000C900000000000000000000000081810000000000C9C90000C9C9C900C900C900C9C90000C90000C9C90000000081810000000000C900C900C900C900C900C900C90000C900C900C9000000000081810000000000C900C900C9C9C90000C9C90000C900C9C90000C9000000000081810000000000000000000000000000000000000000000000000000000000008181F600000000000000000000000000000000000000000000000000000000F681F881F60000000000000000000000000000000000000000000000000000F681F800F881818181818181818181818181818181818181818181818181818181F8007FFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFE002900000012000000020000000D01000000000100000000000A000000080000000000240024002900000012000000020000000D00FAFAFA00010000000000100000001000000002002300000000000000000023002900000012000000020000000D00FFFFFF00010000000000100000001000000002002200010001000100010022002900000012000000020000000D00FAFAFA00010000000000100000001000000002000000240024002400240000002900000012000000020000000D00F8F8F800010000000000100000001000000002000100230023002300230001 + 00000D7E002800000C9A00000400000200020022002200080000000000FFFFFF00FF80000000FFFFFFFFFFFF0000FFFFFFFFCCCC0000FFFFFFFF99990000FFFFFFFF66660000FFFFFFFF33330000FFFFFFFF00000000FFFFCCCCFFFF0000FFFFCCCCCCCC0000FFFFCCCC99990000FFFFCCCC66660000FFFFCCCC33330000FFFFCCCC00000000FFFF9999FFFF0000FFFF9999CCCC0000FFFF999999990000FFFF999966660000FFFF999933330000FFFF999900000000FFFF6666FFFF0000FFFF6666CCCC0000FFFF666699990000FFFF666666660000FFFF666633330000FFFF666600000000FFFF3333FFFF0000FFFF3333CCCC0000FFFF333399990000FFFF333366660000FFFF333333330000FFFF333300000000FFFF0000FFFF0000FFFF0000CCCC0000FFFF000099990000FFFF000066660000FFFF000033330000FFFF000000000000CCCCFFFFFFFF0000CCCCFFFFCCCC0000CCCCFFFF99990000CCCCFFFF66660000CCCCFFFF33330000CCCCFFFF00000000CCCCCCCCFFFF0000CCCCCCCCCCCC0000CCCCCCCC99990000CCCCCCCC66660000CCCCCCCC33330000CCCCCCCC00000000CCCC9999FFFF0000CCCC9999CCCC0000CCCC999999990000CCCC999966660000CCCC999933330000CCCC999900000000CCCC6666FFFF0000CCCC6666CCCC0000CCCC666699990000CCCC666666660000CCCC666633330000CCCC666600000000CCCC3333FFFF0000CCCC3333CCCC0000CCCC333399990000CCCC333366660000CCCC333333330000CCCC333300000000CCCC0000FFFF0000CCCC0000CCCC0000CCCC000099990000CCCC000066660000CCCC000033330000CCCC0000000000009999FFFFFFFF00009999FFFFCCCC00009999FFFF999900009999FFFF666600009999FFFF333300009999FFFF000000009999CCCCFFFF00009999CCCCCCCC00009999CCCC999900009999CCCC666600009999CCCC333300009999CCCC0000000099999999FFFF000099999999CCCC0000999999999999000099999999666600009999999933330000999999990000000099996666FFFF000099996666CCCC0000999966669999000099996666666600009999666633330000999966660000000099993333FFFF000099993333CCCC0000999933339999000099993333666600009999333333330000999933330000000099990000FFFF000099990000CCCC000099990000999900009999000066660000999900003333000099990000000000006666FFFFFFFF00006666FFFFCCCC00006666FFFF999900006666FFFF666600006666FFFF333300006666FFFF000000006666CCCCFFFF00006666CCCCCCCC00006666CCCC999900006666CCCC666600006666CCCC333300006666CCCC0000000066669999FFFF000066669999CCCC0000666699999999000066669999666600006666999933330000666699990000000066666666FFFF000066666666CCCC0000666666669999000066666666666600006666666633330000666666660000000066663333FFFF000066663333CCCC0000666633339999000066663333666600006666333333330000666633330000000066660000FFFF000066660000CCCC000066660000999900006666000066660000666600003333000066660000000000003333FFFFFFFF00003333FFFFCCCC00003333FFFF999900003333FFFF666600003333FFFF333300003333FFFF000000003333CCCCFFFF00003333CCCCCCCC00003333CCCC999900003333CCCC666600003333CCCC333300003333CCCC0000000033339999FFFF000033339999CCCC0000333399999999000033339999666600003333999933330000333399990000000033336666FFFF000033336666CCCC0000333366669999000033336666666600003333666633330000333366660000000033333333FFFF000033333333CCCC0000333333339999000033333333666600003333333333330000333333330000000033330000FFFF000033330000CCCC000033330000999900003333000066660000333300003333000033330000000000000000FFFFFFFF00000000FFFFCCCC00000000FFFF999900000000FFFF666600000000FFFF333300000000FFFF000000000000CCCCFFFF00000000CCCCCCCC00000000CCCC999900000000CCCC666600000000CCCC333300000000CCCC0000000000009999FFFF000000009999CCCC0000000099999999000000009999666600000000999933330000000099990000000000006666FFFF000000006666CCCC0000000066669999000000006666666600000000666633330000000066660000000000003333FFFF000000003333CCCC0000000033339999000000003333666600000000333333330000000033330000000000000000FFFF000000000000CCCC0000000000009999000000000000666600000000000033330000EEEE000000000000DDDD000000000000BBBB000000000000AAAA0000000000008888000000000000777700000000000055550000000000004444000000000000222200000000000011110000000000000000EEEE000000000000DDDD000000000000BBBB000000000000AAAA0000000000008888000000000000777700000000000055550000000000004444000000000000222200000000000011110000000000000000EEEE000000000000DDDD000000000000BBBB000000000000AAAA0000000000008888000000000000777700000000000055550000000000004444000000000000222200000000000011110000EEEEEEEEEEEE0000DDDDDDDDDDDD0000BBBBBBBBBBBB0000AAAAAAAAAAAA000088888888888800007777777777770000555555555555000044444444444400002222222222220000111111111111000000000000000000F881818181818181818181818181818181818181818181818181818181F800F8817575757575757575757575757575757575757575757575757575757581F88100000000000000000000000000000000000000000000000000000000000081810000000000000000000000000000000000000000000000000000000000008181000000000000000000000000000000000000000000000000000000000000818100C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5000000000000000000000000818100C5C50000C5C5C5000000C500C5C5C500C5000000000000000000000000818100C500C5C500C500C5C5C5C50000C50000C5000000000000000000000000818100C500C5C5C5C5C50000C5C500C500C500C5000000C9C9C9C9C900000000818100C500C5C500C5C5C5C500C500C5C5C500C50000C90000000000C9000000818100C5C50000C5C5000000C5C500C5C5C500C500C90000C9C9C90000C90000818100C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5000000C9000000C900C900008181000000002BFF2B2B2B0000002BFF2B2B2B00000000C9000000C900C9000081810000000000FF2B000000000000FF2B00000000000000C90000C900C900008181000000FFFFFFFFFFFFFFFFFFFFFFFFFF000000000000C900C90000C900008181000000002B2B2B2B2BFF2B2B2B2B2B2B2B00000000C900C90000C90000008181000000000000000000FF2B00000000000000000000C9C90000C900000000818100000000000000C9C9C9C9C900000000C900000000000000C90000000000818100000000000000C9C9C9C9C92B00000000C90000C90000C9000000000000818100000000000000C9C9C9C9C92BC9C9C9C9C9C900C90000C9000000000000818100000000000000C9C9C9C9C92B00000000C9000000C9C900000000000000818100000000000000C9C9C9C9C92B000000C900000000000000000000000000818100000000000000002B2B2B2B2B000000000000000000000000000000000081810000000000C9C9000000000000000000000000000000000000000000000081810000000000C900C9000000000000000000C900000000000000000000000081810000000000C9C90000C9C9C900C900C900C9C90000C90000C9C90000000081810000000000C900C900C900C900C900C900C90000C900C900C9000000000081810000000000C900C900C9C9C90000C9C90000C900C9C90000C9000000000081810000000000000000000000000000000000000000000000000000000000008181F600000000000000000000000000000000000000000000000000000000F681F881F60000000000000000000000000000000000000000000000000000F681F800F881818181818181818181818181818181818181818181818181818181F8007FFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFE002900000012000000020000000D01000000000100000000000A000000080000000000240024002900000012000000020000000D00FAFAFA00010000000000100000001000000002002300000000000000000023002900000012000000020000000D00FFFFFF00010000000000100000001000000002002200010001000100010022002900000012000000020000000D00FAFAFA00010000000000100000001000000002000000240024002400240000002900000012000000020000000D00F8F8F800010000000000100000001000000002000100230023002300230001 CSM TCP Router Example true LabVIEW @@ -18,9 +18,9 @@ jki_lib_tcp_server >=5.0.0.8 - nevstop_lib_communicable_state_machine >=2025.1.27.141432 + nevstop_lib_communicable_state_machine >=2025.2.28.95859 nevstop_lib_csm_api_string_arguments_support >=2025.1.27.145038 - nevstop_lib_csm_ini_static_variable_support >=2025.1.27.143156 + nevstop_lib_csm_ini_static_variable_support >=2025.2.28.100053 nevstop_lib_csm_massdata_parameter_support >=2024.12.31.84154 nevstop_lib_globalstop >=2022.12.12.102654 oglib_error >=4.2.0.23 @@ -37,17 +37,49 @@ CSM-TCP-Router.vipc Application Example to show how to setup a TCP Server and Client using CSM and JKI TCP Server. - Application Example to show how to setup a TCP Server and Client using CSM and JKI TCP Server. + 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. -How to test it: +## Features -1. Open Project in <LabVIEW>/examples\NEVSTOP\Communicable State Machine(CSM)\CSM TCP Router Application -2. Run Server VI: CSM-TCP-Router(Server).vi -3. Run Client Console VI: Client.vi and try it. +- 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. + +## Usage + +1. Install this tool and dependencies via VIPM +2. Open the example project CSM-TCP-Router.lvproj in the CSM examples +3. Start the CSM-TCP-Router(Server).vi in the code project +4. Start Client.vi, enter the server's IP address and port number, and click connect +5. Enter commands and click send to see the returned messages in the console +6. View the history of executed messages in the log interface of the Server program +7. Enter `Bye` in Client.vi to disconnect +8. Close the Server program + NEVSTOP https://github.com/NEVSTOP-LAB/CSM-TCP-Router-App - + [add] add IP address/Port input dialog for client. +[update] update connection information +[update] update server/client VI icon +[fix] type "bye", client will exit, as the connection will be closed from server side. +[fix] minor fix. #5 @@ -185,6 +217,7 @@ How to test it: false false false + false true diff --git a/README(zh-cn).md b/README(zh-cn).md new file mode 100644 index 0000000..ecf88e3 --- /dev/null +++ b/README(zh-cn).md @@ -0,0 +1,87 @@ +# CSM-TCP-Router + +[English](./README.md) | [中文](./README(zh-cn).md) + +本仓库演示如何通过创建一个可复用的TCP通讯层 (CSM-TCP-Router),将本地程序变成一个TCP服务器,实现远程控制。通过这个案例,展示CSM框架的隐形总线的优点。 + +## 功能介绍 + +![framework](.doc/CSM-TCP-Router%201.svg) + +- 本地所有可以发送的CSM消息,都可以使用CSM同步、异步消息格式,通过TCP连接发送给本地程序。 +- 基于JKI-TCP-Server库,支持多个TCP客户端同时连接。 +- [client] 提供一个标准的TCP客户端,可以连接到服务器,验证远程连接、消息发送等功能。 + +> [!IMPORTANT] +> `TCP数据包格式:` | 数据长度(4字节) | CSM命令字符串(纯文本) | + +> [!NOTE] +> 举例:假设本地程序存在名为DAQmx的CSM模块,具有一个接口为 "API: Start Sampling". +> 本地我们可以发送消息给这个模块,控制采集的启停: +> +> - API: Start Sampling -@ DAQmx // 同步消息 +> - API: Start Sampling -> DAQmx // 异步消息 +> - API: Start Sampling ->| DAQmx // 异步无返回消息 +> +> 现在只要通过TCP连接,发送同样的文本消息,就可以实现远程控制。 + +> [!WARNING] +> 目前CSM-TCP-Router只支持同步消息(-@)和无返回的异步消息(->|),异步消息(->)将被视为无返回的异步消息。 + +## 支持的指令集 + +![image](.doc/CSM-TCP-Router.drawio.png) + +### 1. CSM 消息指令集 + +由原有基于CSM开发的代码定义。由于CSM框架通过隐形的总线进行消息传递,所有的通讯可以不用侵入代码的方式实现。 + +例如,本程序中的AI CSM模块提供了: + +- `Channels`: 列出所有的通道 +- `Read`:读取指定通道的值 +- `read all`:读取所有通道的值 + +这些消息可以通过TCP连接发送给本地程序,实现远程控制。 + +### 2. CSM-TCP-Router 指令集 + +由TCP通讯层 (CSM-TCP-Router) 定义。CSM模块管理的功能,通过定义指令,可以实现远程控制。 + +- `List` - 列出所有的CSM模块 +- `List API`: 列出指定模块的所有API +- `List State`: 列出指定模块的所有CSM状态 +- `Help` - 显示模块的帮助文件,存储在CSM VI的Documentation字段 +- `Refresh lvcsm`: 刷新缓存文件 + +### [Client Only] 3. CSM-TCP-Router Client 指令集 + +代码中提供一个标准的CSM-TCP-Router Client。它也内置了一些指令,这些指令如果基于指令集进行开发,无法使用。 + +- `Bye`: 断开连接 +- `Switch`:切换模块,便于输入时省略模块名,不带参数时切换回默认模式 +- TAB键: 自动定位到输入对话框 + +![CSM-TCP-Router Client Console](.doc/Client.png) + +## 使用方法 + +1. 在VIPM中安装本工具及依赖 +2. 在CSM的范例中打开范例工程CSM-TCP-Router.lvproj +3. 启动代码工程中的CSM-TCP-Router(Server).vi +4. 启动Client.vi,输入服务器的IP地址和端口号,点击连接 +5. 输入指令,点击发送,可以在控制台看到返回的消息 +6. 在Server程序的界面log中,可以看到执行过的历史消息 +7. 在Client.vi中输入`Bye`断开连接 +8. 关闭Server程序 + +### 下载 + +通过VIPM搜索CSM TCP Router,即可下载安装。 + +### 依赖 + +- Communicable State Machine(CSM) - NEVSTOP +- JKI TCP Server - JKI +- Global Stop - NEVSTOP +- OpenG diff --git a/README.md b/README.md index f7b6162..248521e 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,87 @@ # CSM-TCP-Router -Application Example to show how to setup a TCP Server and Client using CSM and JKI TCP Server. +[English](./README.md) | [中文](./README(zh-cn).md) + +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. + +## Features + +![framework](.doc/CSM-TCP-Router%201.svg) + +- 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. + +## Supported Command Sets ![image](.doc/CSM-TCP-Router.drawio.png) -**CSM-TCP-Router Server** +### 1. CSM Message Command Set + +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 channels +- `Read`: Read the value of a specified channel +- `read all`: Read the values of all channels + +These messages can be sent to the local program via TCP connection for remote control. + +### 2. CSM-TCP-Router Command Set + +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 modules +- `List API`: List all APIs of a specified module +- `List State`: List all CSM states of a specified module +- `Help`: Display the help file of the module, stored in the Documentation field of the CSM VI +- `Refresh lvcsm`: Refresh the cache file + +### [Client Only] 3. CSM-TCP-Router Client Command Set + +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`: Disconnect +- `Switch`: 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 + +![CSM-TCP-Router Client Console](.doc/Client.png) + +## Usage -![CSM-TCP-Router Server BD](.doc/CSM-TCP-Router%20Sever%20BD.png) +1. Install this tool and dependencies via VIPM +2. Open the example project CSM-TCP-Router.lvproj in the CSM examples +3. Start the CSM-TCP-Router(Server).vi in the code project +4. Start Client.vi, enter the server's IP address and port number, and click connect +5. Enter commands and click send to see the returned messages in the console +6. View the history of executed messages in the log interface of the Server program +7. Enter `Bye` in Client.vi to disconnect +8. Close the Server program -**CSM-TCP-Router Client** +### Download -![CSM-TCP-Client-Console FP](.doc/CSM-TCP-Router%20Client%20Console%20FP.png) +Search for CSM TCP Router in VIPM to download and install. -Deps: +### Dependencies - - JKI TCP Server - JKI - - Communicable State Machine(CSM) - NEVSTOP - - Global Stop - NEVSTOP - - OpenG +- Communicable State Machine (CSM) - NEVSTOP +- JKI TCP Server - JKI +- Global Stop - NEVSTOP +- OpenG diff --git a/src/CSM-TCP-Router.lvcsm b/src/CSM-TCP-Router.lvcsm index 5e3139a..02c340d 100644 --- a/src/CSM-TCP-Router.lvcsm +++ b/src/CSM-TCP-Router.lvcsm @@ -1,18 +1,6 @@ -[CSMAPI.HAL-AI.vi] -Item 0 = "Channels" -Item 1 = "read" -Item 2 = "read all" - -[CSMAPI.HAL-DIO.vi] -Item 0 = "Turn On" -Item 1 = "Turn Off" -Item 2 = "Check" -Item 3 = "Check All" -Item 4 = "Reset All" - -[CSMAPI.MAL-TEST.vi] -Item 0 = "Sweep" -Item 1 = "Measure" +[CSMModule.AI] +VIName = "HAL-AI.vi" +Path = "/CSM_Modules/HAL-AI.vi" [CSMStates.HAL-AI.vi] Item 0 = "Idle" @@ -42,6 +30,18 @@ Item 23 = "read all" Item 24 = "DoSth: DoA" Item 25 = "DoSth: DoB" +[CSMAPI.HAL-AI.vi] +Item 0 = "Channels" +Item 1 = "read" +Item 2 = "read all" + +[CSMDoc.HAL-AI.vi] +doc = "AI Module with 4 Channels.%0AAPI:%0A1. Channels %2F%2F List all Channels %0A2. Read %3E%3E ChannelName%3BNum %2F%2FRead num of points from Channel specified.%0A3.read all %3E%3E Num %2F%2F Read num of points from all channels." + +[CSMModule.DIO] +VIName = "HAL-DIO.vi" +Path = "/CSM_Modules/HAL-DIO.vi" + [CSMStates.HAL-DIO.vi] Item 0 = "Idle" Item 1 = "CSM Documentation" @@ -72,6 +72,24 @@ Item 25 = "Reset All" Item 26 = "DoSth: DoA" Item 27 = "DoSth: DoB" +[CSMAPI.HAL-DIO.vi] +Item 0 = "Turn On" +Item 1 = "Turn Off" +Item 2 = "Check" +Item 3 = "Check All" +Item 4 = "Reset All" + +[CSMDoc.HAL-DIO.vi] +doc = "DIO Module with 8 Channels.%0AAPI:%0A1. TurnOn %3E%3E ChannelIndex %2F%2FSet Channel to ON.%0A2. TurnOff %3E%3E ChannelIndex %2F%2FSet Channel to OFF.%0A3. Check %3E%3E ChannelIndex %2F%2FCheck current status of Channel.%0A4. CheckAll %2F%2FCheck status of all channels%0A5. ResetAll %2F%2FReset All channels" + +[CSMModule.DIO2] +VIName = "HAL-DIO.vi" +Path = "/CSM_Modules/HAL-DIO.vi" + +[CSMModule.Measure] +VIName = "MAL-TEST.vi" +Path = "/CSM_Modules/MAL-TEST.vi" + [CSMStates.MAL-TEST.vi] Item 0 = "Idle" Item 1 = "CSM Documentation" @@ -99,6 +117,9 @@ Item 22 = "Measure" Item 23 = "DoSth: DoA" Item 24 = "DoSth: DoB" -[CSM Debug Console] -Response Timeout(s) = 30 -History Length = 50 \ No newline at end of file +[CSMAPI.MAL-TEST.vi] +Item 0 = "Sweep" +Item 1 = "Measure" + +[CSMDoc.MAL-TEST.vi] +doc = "Measurement Module.%0AAPI: %0A1. Sweep %3E%3E Start%3BStop%3BStep%3BInterval %2F%2F sweep current with specified parameters.%0A2. Measure %2F%2F Return voltage and current at the same time." \ No newline at end of file diff --git a/src/CSM-TCP-Router.lvproj b/src/CSM-TCP-Router.lvproj index 4be4a08..5f31a0d 100644 --- a/src/CSM-TCP-Router.lvproj +++ b/src/CSM-TCP-Router.lvproj @@ -31,18 +31,19 @@ - - - - - - + + + + + + + + - @@ -97,6 +98,7 @@ + @@ -121,6 +123,7 @@ + @@ -172,7 +175,7 @@ {F7A5A582-5BDE-4E17-B1F9-48DB4D83CB57} Container 0 - /My Computer/Client/Client.vi + TopLevel VI 2 @@ -213,7 +216,7 @@ {F7A5A582-5BDE-4E17-B1F9-48DB4D83CB57} Container 0 - /My Computer/Server/CSM-TCP-Router(Server).vi + TopLevel VI 0 @@ -231,15 +234,16 @@ - - RT PXI Target - 10.144.36.41 - TARGET_TYPE,RT;OS,PharLap;CPU,x86; + + NI-cRIO-9068 + 10.144.45.18 + TARGET_TYPE,RT;OS,Linux;CPU,ARM;DeviceCode,76D6; + 76D6 true 5000 1000 - 3 - 15 + 8 + 8 false 300 80 @@ -258,7 +262,7 @@ true +* false - /c/ni-rt/startup + /home/lvuser/natinst/bin true true +* @@ -324,17 +328,18 @@ AddOutputFilter chunkFilter - - - - - - + + + + + + + + - @@ -370,6 +375,7 @@ AddOutputFilter chunkFilter + @@ -389,6 +395,7 @@ AddOutputFilter chunkFilter + @@ -405,54 +412,6 @@ AddOutputFilter chunkFilter - - - true - {EA0251F0-A448-403C-A246-4A907D4EB333} - {F1EE95FA-4C24-4270-9C0C-06F9F8C4F8D5} - 8002 - 0 - true - {A422469F-7D6E-4219-9399-AB08AB6260EA} - Server - true - true - true - ../_Build/RT - relativeToProject - true - {038BB82D-815A-43A9-B677-8A0662710E2F} - /c/ni-rt/startup - 3 - 1 - startup.rtexe - /c/ni-rt/startup/startup.rtexe - <none> - true - App - Support Directory - /c/ni-rt/startup - <none> - 2 - {B40576F1-AD00-416B-82B1-748407E6E56F} - Container - 0 - /RT PXI Target/Server/CSM-TCP-Router(Server).vi - TopLevel - VI - 0 - /RT PXI Target/CSM-TCP-Router.lvcsm - Server.lvcsm - Include - 3 - Server - Server - Copyright ?2025 - Server - {309CFF2A-698F-4C3F-A807-E7C8A3DAA997} - startup.rtexe - true - - + diff --git a/src/CSM_Modules/HAL-AI.vi b/src/CSM_Modules/HAL-AI.vi index cc60095..7876696 100644 Binary files a/src/CSM_Modules/HAL-AI.vi and b/src/CSM_Modules/HAL-AI.vi differ diff --git a/src/CSM_Modules/HAL-DIO.vi b/src/CSM_Modules/HAL-DIO.vi index 97041af..66736d0 100644 Binary files a/src/CSM_Modules/HAL-DIO.vi and b/src/CSM_Modules/HAL-DIO.vi differ diff --git a/src/CSM_Modules/MAL-TEST.vi b/src/CSM_Modules/MAL-TEST.vi index d362b1a..60bc63c 100644 Binary files a/src/CSM_Modules/MAL-TEST.vi and b/src/CSM_Modules/MAL-TEST.vi differ diff --git a/src/Client/Client.vi b/src/Client/Client.vi index bba6b7c..52a4ca1 100644 Binary files a/src/Client/Client.vi and b/src/Client/Client.vi differ diff --git a/src/Client/Support/Connection Input Dialog.vi b/src/Client/Support/Connection Input Dialog.vi new file mode 100644 index 0000000..6a3a9bd Binary files /dev/null and b/src/Client/Support/Connection Input Dialog.vi differ diff --git a/src/Server/CSM-TCP-Router(Server).vi b/src/Server/CSM-TCP-Router(Server).vi index b08980f..7eef1ed 100644 Binary files a/src/Server/CSM-TCP-Router(Server).vi and b/src/Server/CSM-TCP-Router(Server).vi differ diff --git a/src/Server/Connection Handler VI.vi b/src/Server/Connection Handler VI.vi index 1c09551..8c381a5 100644 Binary files a/src/Server/Connection Handler VI.vi and b/src/Server/Connection Handler VI.vi differ diff --git a/src/Server/_support/CSM Router Module.vi b/src/Server/_support/CSM Router Module.vi new file mode 100644 index 0000000..4f4aec6 Binary files /dev/null and b/src/Server/_support/CSM Router Module.vi differ diff --git a/src/Server/_support/Read CSM Doc with lvcsm Support.vi b/src/Server/_support/Read CSM Doc with lvcsm Support.vi new file mode 100644 index 0000000..0321ca9 Binary files /dev/null and b/src/Server/_support/Read CSM Doc with lvcsm Support.vi differ diff --git a/src/Server/_support/TCP Send Receive.vi b/src/Server/_support/TCP Send Receive.vi index def1042..e2c2fff 100644 Binary files a/src/Server/_support/TCP Send Receive.vi and b/src/Server/_support/TCP Send Receive.vi differ diff --git a/src/csm-app.ini b/src/csm-app.ini index 2303a9e..7f76a87 100644 --- a/src/csm-app.ini +++ b/src/csm-app.ini @@ -9,6 +9,8 @@ WebServer.TcpAccess="c+*" WebServer.ViAccess="+*" DebugServerEnabled=False DebugServerWaitOnLaunch=False +IP Address = "localhost" +Port = "50007" [Server] Port = "50007"