RS232
The RS232 interface provides serial communication capabilities with configurable baud rates from 300 to 1,000,000 bps.
As described in the introduction, industrial communication interfaces share GPIOs, meaning only one feature can be enabled at a given time: Either regular GPIOs, or one of the industrial communication interfaces.
Quick Start​
The RS232 bus operates similarly to RS485 (except it does not require termination resistors).
- NodeJS
- Python
import AT1000 from '@ikalogic/at1000';
let testers = await AT1000.findDevices(500); // Find the device with serial number 12345
let tester = testers[0]; // Target the first detected device
let rs232 = tester.com.rs232(1); // Access RS232_1 bus on AT1000
// Enable RS232_1 on AT1000
await rs232.configure({
baud_rate: 9600,
enabled: true,
parity: 'N',
stop_bits: 1
});
// Start receiving RS232 messages
await rs232.start_rx();
// Transmit a message over RS232
await rs232.tx([0x01,0x02,0x03,0x04,0x05]);
// Receive data (returns a string)
let data_rx = await rs232.rx();
// Print received message
console.log("RS232 Data Received:", data_rx);
// Disable RS232_1 bus
await rs232.stop_rx();
from ikalogic_at1000 import AT1000
testers = await AT1000.find_devices(500) # Find the device with serial number 12345
tester = testers[0] # Target the first detected device
rs232 = tester.com.rs232(1) # Access RS232_1 bus on AT1000
# Enable RS232_1 on AT1000
await rs232.configure({
'baud_rate': 9600,
'enabled': True,
'parity': 'N',
'stop_bits': 1
})
# Start receiving RS232 messages
await rs232.start_rx()
# Transmit a message over RS232
await rs232.tx([0x01,0x02,0x03,0x04,0x05])
# Receive data (returns a string)
data_rx = await rs232.rx()
# Print received message
print(f"RS232 Data Received: {data_rx}")
# Disable RS232_1 bus
await rs232.stop_rx()
API Reference​
Accessing RS232​
- NodeJS
- Python
const rs232 = tester.com.rs232(id);
rs232 = tester.com.rs232(id)
Parameters:
id(number): The RS232 interface identifier (0-based index)
Returns: Rs232 instance
Methods​
configure(config)​
Configures the RS232 interface parameters without changing the enabled state.
- NodeJS
- Python
await rs232.configure({ baud_rate: 115200 });
await rs232.configure({ 'baud_rate': 115200 })
Parameters:
config(Rs232ConfigPatch): Configuration object with optional properties:enabled(boolean, optional): Enable or disable the interfacebaud_rate(number, optional): Baud rate (300 to 1000000)
Returns: Promise<Rs232Config> - The updated configuration
Exceptions:
- Throws validation error if
baud_rateis outside the range [300, 1000000] - Throws validation error if parameters don't match expected types
enable([config])​
Enables the RS232 interface and optionally applies configuration.
- NodeJS
- Python
await rs232.enable({ baud_rate: 9600 });
await rs232.enable({ 'baud_rate': 9600 })
Parameters:
config(Rs232EnableConfig, optional): Optional configuration to apply:baud_rate(number, optional): Baud rate (300 to 1000000)
Returns: Promise<Rs232Config> - The updated configuration with enabled: true
Exceptions:
- Throws validation error if
baud_rateis outside the range [300, 1000000]
disable()​
Disables the RS232 interface.
- NodeJS
- Python
await rs232.disable();
await rs232.disable()
Returns: Promise<Rs232Config> - The updated configuration with enabled: false
tx(data)​
Transmits data over the RS232 interface.
- NodeJS
- Python
// Send string
await rs232.tx("Hello, World!");
// Send byte array
await rs232.tx([0x48, 0x65, 0x6C, 0x6C, 0x6F]);
# Send string
await rs232.tx("Hello, World!")
# Send byte array
await rs232.tx([0x48, 0x65, 0x6C, 0x6C, 0x6F])
Parameters:
data(SerialDataInput): Data to transmit, either:string: Text data (max 1024 characters)number[]: Byte array (each byte 0-255, max 1024 bytes)
Returns: Promise<SerialData> - The transmitted data as byte array (number[])
Exceptions:
- Throws validation error if string exceeds 1024 characters
- Throws validation error if array exceeds 1024 elements
- Throws validation error if any byte value is outside the range [0, 255]
start_rx()​
Starts buffering received data from the RS232 interface.
- NodeJS
- Python
await rs232.start_rx();
await rs232.start_rx()
Returns: Promise<void>
Note: Data received after calling this method will be buffered and can be retrieved using rx().
stop_rx()​
Stops buffering received data from the RS232 interface.
- NodeJS
- Python
await rs232.stop_rx();
await rs232.stop_rx()
Returns: Promise<void>
rx()​
Reads all buffered data received since start_rx() was called.
- NodeJS
- Python
const receivedData = await rs232.rx();
console.log(receivedData); // number[]
received_data = await rs232.rx()
print(received_data) # list of integers
Returns: Promise<SerialData> - Received data as byte array (number[])
Note: This method returns all data accumulated since the last start_rx() call and clears the buffer.
Types​
Rs232Config​
Complete configuration object returned by configuration methods.
{
enabled: boolean,
baud_rate: number // 300 to 1000000
}
Rs232ConfigPatch​
Partial configuration for the configure() method. All properties are optional.
{
enabled?: boolean,
baud_rate?: number // 300 to 1000000
}
Rs232EnableConfig​
Optional configuration for the enable() method.
{
baud_rate?: number // 300 to 1000000
}
SerialDataInput​
Input data type for transmission.
string | number[]
string: Maximum 1024 charactersnumber[]: Maximum 1024 elements, each byte in range [0, 255]
SerialData​
Output data type, always returned as a byte array.
number[] // Array of bytes (0-255)
Usage Example​
- NodeJS
- Python
import AT1000 from '@ikalogic/at1000';
// Find and connect to device
const devices = await AT1000.findDevices(500);
const tester = devices[0];
// Access RS232 interface 0
const rs232 = tester.com.rs232(0);
// Enable with 115200 baud rate
await rs232.enable({ baud_rate: 115200 });
// Start receiving data
await rs232.start_rx();
// Transmit data
await rs232.tx("AT\r\n");
// Wait for response
await new Promise(resolve => setTimeout(resolve, 100));
// Read received data
const response = await rs232.rx();
console.log("Received:", Buffer.from(response).toString());
// Stop receiving
await rs232.stop_rx();
// Disable interface
await rs232.disable();
from ikalogic_at1000 import AT1000
import asyncio
# Find and connect to device
devices = await AT1000.find_devices(500)
tester = devices[0]
# Access RS232 interface 0
rs232 = tester.com.rs232(0)
# Enable with 115200 baud rate
await rs232.enable({ 'baud_rate': 115200 })
# Start receiving data
await rs232.start_rx()
# Transmit data
await rs232.tx("AT\r\n")
# Wait for response
await asyncio.sleep(0.1)
# Read received data
response = await rs232.rx()
print(f"Received: {bytes(response).decode()}")
# Stop receiving
await rs232.stop_rx()
# Disable interface
await rs232.disable()
Common Patterns​
String Conversion​
- NodeJS
- Python
// Convert received byte array to string
const bytes = await rs232.rx();
const text = Buffer.from(bytes).toString('utf-8');
// Or using TextDecoder
const text = new TextDecoder().decode(new Uint8Array(bytes));
# Convert received byte array to string
byte_list = await rs232.rx()
text = bytes(byte_list).decode('utf-8')
Binary Protocol Communication​
- NodeJS
- Python
// Send binary command
await rs232.tx([0x02, 0x10, 0x00, 0xFF, 0x03]);
// Read binary response
const response = await rs232.rx();
# Send binary command
await rs232.tx([0x02, 0x10, 0x00, 0xFF, 0x03])
# Read binary response
response = await rs232.rx()
Continuous Monitoring​
- NodeJS
- Python
// Start continuous reception
await rs232.start_rx();
// Poll periodically
setInterval(async () => {
const data = await rs232.rx();
if (data.length > 0) {
console.log("Received:", data);
}
}, 100);
import asyncio
# Start continuous reception
await rs232.start_rx()
# Poll periodically
async def poll_rx():
while True:
data = await rs232.rx()
if len(data) > 0:
print(f"Received: {data}")
await asyncio.sleep(0.1)
asyncio.create_task(poll_rx())