TCP Transport
The TCP transport connects to the Tropic01 model server for development and testing purposes. This allows testing PyTropicSquare without physical hardware.
TCP Transport for libtropic Model/Simulator
This module provides a TCP transport implementation that communicates with the TROPIC01 model/simulator server using the libtropic tagged protocol.
The transport enables pytropicsquare to work with the same model/simulator infrastructure that libtropic uses, making it useful for:
Hardware-in-the-loop testing
Chip simulation and development
Cross-platform testing (CPython and MicroPython)
- Protocol Details:
The transport implements the libtropic TCP protocol with tagged messages:
Buffer format:
tag (1)
length (2 LE)
payload (0-256)
Request-response pattern with tag validation
Automatic retry logic for network operations
Example:
from tropicsquare import TropicSquare
from tropicsquare.transports.tcp import TcpTransport
# Connect to model server
transport = TcpTransport("127.0.0.1")
ts = TropicSquare(transport)
# Use chip normally
print(ts.chip_id)
- note:
Server must be running libtropic-compatible model/simulator from https://github.com/tropicsquare/ts-tvl/
- class tropicsquare.transports.tcp.TcpTransport(host, port=28992, timeout=5.0, connect_timeout=1.0)[source]
Bases:
L1TransportL1 transport for TCP connection to libtropic model/simulator.
Implements the libtropic tagged protocol for communicating with the TROPIC01 model/simulator server via TCP socket.
The transport maps L1 SPI operations to tagged TCP commands:
_cs_low()→ TAG_CSN_LOW (0x01)_cs_high()→ TAG_CSN_HIGH (0x02)_transfer()→ TAG_SPI_SEND (0x03)_read()→ TAG_SPI_SEND (0x03) with dummy bytes
- Parameters:
- Raises:
TropicSquareError – If connection fails
Example:
transport = TcpTransport("127.0.0.1") ts = TropicSquare(transport) print(ts.chip_id)
- TAG_CSN_LOW = 1
- TAG_CSN_HIGH = 2
- TAG_SPI_SEND = 3
- TAG_WAIT = 6
- TAG_INVALID = 253
- TAG_UNSUPPORTED = 254
- MAX_PAYLOAD_LEN = 256
- MAX_BUFFER_LEN = 259
- TX_ATTEMPTS = 3
- RX_ATTEMPTS = 3
- __init__(host, port=28992, timeout=5.0, connect_timeout=1.0)[source]
Initialize TCP transport.
- Parameters:
- Raises:
TropicSquareError – If connection fails
Model Server
The Tropic01 model server simulates chip behavior for:
Development without hardware
Automated testing
CI/CD integration
Platform Support
CPython: Full support
MicroPython: Supported with network connectivity
See Also
Network-SPI Transport - Network-SPI transport for real chips
SPI Transport - Direct hardware SPI transport