Skip to content

Commit 2dbeb5d

Browse files
authored
[Documentation] - Python Bridge docs (#2357)
1 parent ef06975 commit 2dbeb5d

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

docs.openc3.com/docs/guides/bridges.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Bridges are run using an configuration file named bridge.txt. This file is a sub
3636

3737
The following is the default bridge.txt that is generated by running `openc3cli bridgesetup`
3838

39+
<Tabs groupId="script-language">
40+
<TabItem value="ruby" label="Ruby Example">
41+
3942
```ruby
4043
# Write serial port name
4144
VARIABLE write_port_name COM1
@@ -80,6 +83,56 @@ ROUTER SERIAL_ROUTER tcpip_server_interface.rb <%= router_port %> <%= router_por
8083
OPTION LISTEN_ADDRESS <%= router_listen_address %>
8184
```
8285

86+
</TabItem>
87+
88+
<TabItem value="python" label="Python Example">
89+
90+
```ruby
91+
# Write serial port name
92+
VARIABLE write_port_name COM1
93+
94+
# Read serial port name
95+
VARIABLE read_port_name COM1
96+
97+
# Baud Rate
98+
VARIABLE baud_rate 115200
99+
100+
# Parity - NONE, ODD, or EVEN
101+
VARIABLE parity NONE
102+
103+
# Stop bits - 0, 1, or 2
104+
VARIABLE stop_bits 1
105+
106+
# Write Timeout
107+
VARIABLE write_timeout 10.0
108+
109+
# Read Timeout
110+
VARIABLE read_timeout nil
111+
112+
# Flow Control - NONE, or RTSCTS
113+
VARIABLE flow_control NONE
114+
115+
# Data bits per word - Typically 8
116+
VARIABLE data_bits 8
117+
118+
# Port to listen for connections from COSMOS - Plugin must match
119+
VARIABLE router_port 2950
120+
121+
# Port to listen on for connections from COSMOS. Defaults to localhost for security. Will need to be opened
122+
# if COSMOS is on another machine.
123+
VARIABLE router_listen_address 127.0.0.1
124+
125+
INTERFACE SERIAL_INT openc3/interfaces/serial_interface.py <%= write_port_name %> <%= read_port_name %> <%= baud_rate %> <%= parity %> <%= stop_bits %> <%= write_timeout %> <%= read_timeout %>
126+
OPTION FLOW_CONTROL <%= flow_control %>
127+
OPTION DATA_BITS <%= data_bits %>
128+
129+
ROUTER SERIAL_ROUTER openc3/interfaces/tcpip_server_interface.py <%= router_port %> <%= router_port %> 10.0 nil BURST
130+
ROUTE SERIAL_INT
131+
OPTION LISTEN_ADDRESS <%= router_listen_address %>
132+
```
133+
134+
</TabItem>
135+
</Tabs>
83136
VARIABLE provides default values to variables that can be changed when the bridge is started. This example shows an INTERFACE that is configured to use the serial_interface.rb class. It also includes a standard ROUTER using tcpip_server_interface.rb that COSMOS can connect to and get the data from the serial port. The LISTEN_ADDRESS is set to 127.0.0.1 in this example to prevent access from outside of the host system. Docker running on the same machine can access
84137
this server using the host.docker.internal hostname and the configured port (2950 in this example).
85138

@@ -97,6 +150,24 @@ Runs a bridge from a given configuration file. Defaults to bridge.txt in the cur
97150

98151
Runs a bridge using the bridge.txt provided in a bridge gem. Variables can also be passed into to override VARIABLE defaults.
99152

153+
## Python Bridge Commands: openc3pycli
154+
155+
To use the openc3pycli, first run
156+
157+
`python3 -m pip install -e .`
158+
159+
In the [cosmos/openc3/python/openc3/cli.py](https://github.com/OpenC3/cosmos/blob/main/openc3/python/openc3/cli.py) directory. A venv may be required to be activated prior to running the pip install. If so, run the following:
160+
161+
```bash
162+
python3 -m venv /path/to/your/venv
163+
source /path/to/your/venv/bin/activate
164+
python3 -m pip install -e .
165+
```
166+
167+
`openc3pycli bridge [filename] [variable1=value1] [variable2=value2]`
168+
169+
Runs a bridge from a given configuration file. Defaults to bridge.txt in the current directory. Variables can also be passed into to override VARIABLE defaults.
170+
100171
## Example Bridge Gems
101172

102173
- Serial Port: [openc3-cosmos-bridge-serial](https://github.com/OpenC3/openc3-cosmos-bridge-serial)

0 commit comments

Comments
 (0)