RS232
The RS232 interface provides serial communication capabilities with configurable baud rates from 50 to 1,000,000 bps.
As described in pin alternate functions, 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
- Rust
import { AT1000 } from '@ikalogic/at1000';
let devices = await AT1000.findDevices(); // Find devices (returns host strings)
let tester = await AT1000.open(devices[0]); // Open the first detected device
await tester.reset(); // Reset the device to a known state
let rs232 = tester.com.rs232(0); // Access RS232_0 bus on AT1000
// Enable RS232_0 on AT1000
await rs232.configure({
baud_rate: 9600,
enabled: true,
parity: 'none',
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
devices = AT1000.find_devices() # Find devices (returns host strings)
tester = AT1000.open(devices[0]) # Open the first detected device
tester.reset() # Reset the device to a known state
rs232 = tester.com.rs232(0) # Access RS232_0 bus on AT1000
# Enable RS232_0 on AT1000
rs232.configure(
baud_rate=9600,
enabled=True,
parity='none',
stop_bits='1'
)
# Start receiving RS232 messages
rs232.start_rx()
# Transmit a message over RS232
rs232.tx([0x01,0x02,0x03,0x04,0x05])
# Receive data (returns a string)
data_rx = rs232.rx()
# Print received message
print(f"RS232 Data Received: {data_rx}")
# Disable RS232_1 bus
rs232.stop_rx()
use ikalogic_at1000::{AT1000, Rs232ConfigPatch, SerialParity, SerialStopBits};
use std::time::Duration;
let devices = AT1000::find_devices(Duration::from_millis(500))?; // Find devices (returns host strings)
let tester = AT1000::open(&devices[0])?; // Open the first detected device
tester.reset()?; // Reset the device to a known state
let rs232 = tester.com.rs232(0)?; // Access RS232_0 bus on AT1000
// Enable RS232_0 on AT1000
rs232.configure(&Rs232ConfigPatch {
baud_rate: Some(9600),
enabled: Some(true),
parity: Some(SerialParity::None),
stop_bits: Some(SerialStopBits::One),
..Default::default()
})?;
// Start receiving RS232 messages
rs232.start_rx()?;
// Transmit a message over RS232
rs232.tx(&[0x01, 0x02, 0x03, 0x04, 0x05])?;
// Receive data (returns a byte vector)
let data_rx = rs232.rx()?;
// Print received message
println!("RS232 Data Received: {:?}", data_rx);
// Disable RS232_1 bus
rs232.stop_rx()?;
API Reference​
Accessing RS232​
- NodeJS
- Python
- Rust
const rs232 = tester.com.rs232(id);
rs232 = tester.com.rs232(id)
let id = 0;
let rs232 = tester.com.rs232(id)?;
Parameters:
id(number/int/u32): The RS232 interface identifier (0-based index)
Returns: Rs232 instance / Result<Rs232, At1000Error> in Rust
Methods​
configure(config)​
Configures the RS232 interface parameters without changing the enabled state.
- NodeJS
- Python
- Rust
await rs232.configure({ baud_rate: 115200 });
rs232.configure(baud_rate=115200)
use ikalogic_at1000::Rs232ConfigPatch;
let rs232 = tester.com.rs232(0)?;
rs232.configure(&Rs232ConfigPatch { baud_rate: Some(115_200), ..Default::default() })?;
Parameters:
config(Rs232ConfigPatch/&Rs232ConfigPatchin Rust): Configuration object with optional properties:enabled(boolean/bool/Option<bool>, optional): Enable or disable the interfacebaud_rate(number/int/Option<u32>, optional): Baud rate (50 to 1000000)data_bits(number/int/Option<u8>, optional): Data bits per character (7 or 8)parity(string/str/Option<SerialParity>, optional): Parity mode -'none','odd','even','mark', or'space'(SerialParity::{None, Odd, Even, Mark, Space}in Rust)stop_bits(string/str/Option<SerialStopBits>, optional): Stop bits -'1','1.5', or'2'(SerialStopBits::{One, OnePointFive, Two}in Rust)
Returns: Promise<Rs232Config> / Rs232Config / Result<Rs232Config, At1000Error> - The updated configuration
Exceptions:
- Throws validation error if
baud_rateis outside the range [50, 1000000] - Throws validation error if parameters don't match expected types
enable([config])​
Enables the RS232 interface and optionally applies configuration.
- NodeJS
- Python
- Rust
await rs232.enable({ baud_rate: 9600 });
rs232.enable(baud_rate=9600)
use ikalogic_at1000::Rs232EnableConfig;
let rs232 = tester.com.rs232(0)?;
rs232.enable(&Rs232EnableConfig { baud_rate: Some(9600), ..Default::default() })?;
Parameters:
config(Rs232EnableConfig/&Rs232EnableConfigin Rust, optional): Optional configuration to apply:baud_rate(number/int/Option<u32>, optional): Baud rate (50 to 1000000)data_bits(number/int/Option<u8>, optional): Data bits per character (7 or 8)parity(string/str/Option<SerialParity>, optional): Parity mode -'none','odd','even','mark', or'space'(SerialParity::{None, Odd, Even, Mark, Space}in Rust)stop_bits(string/str/Option<SerialStopBits>, optional): Stop bits -'1','1.5', or'2'(SerialStopBits::{One, OnePointFive, Two}in Rust)
Returns: Promise<Rs232Config> / Rs232Config / Result<Rs232Config, At1000Error> - The updated configuration with enabled: true
Exceptions:
- Throws validation error if
baud_rateis outside the range [50, 1000000]
disable()​
Disables the RS232 interface.
- NodeJS
- Python
- Rust
await rs232.disable();
rs232.disable()
let rs232 = tester.com.rs232(0)?;
rs232.disable()?;
Returns: Promise<Rs232Config> / Rs232Config / Result<Rs232Config, At1000Error> - The updated configuration with enabled: false
tx(data)​
Transmits data over the RS232 interface.
- NodeJS
- Python
- Rust
// Send string
await rs232.tx("Hello, World!");
// Send byte array
await rs232.tx([0x48, 0x65, 0x6C, 0x6C, 0x6F]);
# Send string
rs232.tx("Hello, World!")
# Send byte array
rs232.tx([0x48, 0x65, 0x6C, 0x6C, 0x6F])
let rs232 = tester.com.rs232(0)?;
// Send string
rs232.tx(b"Hello, World!")?;
// Send byte array
rs232.tx(&[0x48, 0x65, 0x6C, 0x6C, 0x6F])?;
Parameters:
data(SerialDataInput/SerialDataInput/&[u8]): Data to transmit, either:string: Text data (max 65536 characters)number[]: Byte array (each byte 0-255, max 65536 bytes)- Rust accepts bytes only:
b"text"for ASCII text,&[0x48, 0x65]for raw bytes (max 65536 bytes)
Returns: Promise<SerialData> / SerialData / Result<SerialData, At1000Error> - The transmitted data as byte array (number[])
Exceptions:
- Throws validation error if string exceeds 65536 characters
- Throws validation error if array exceeds 65536 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
- Rust
await rs232.start_rx();
rs232.start_rx()
let rs232 = tester.com.rs232(0)?;
rs232.start_rx()?;
Returns: Promise<void> / None / Result<(), At1000Error>
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
- Rust
await rs232.stop_rx();
rs232.stop_rx()
let rs232 = tester.com.rs232(0)?;
rs232.stop_rx()?;
Returns: Promise<void> / None / Result<(), At1000Error>
rx()​
Reads all buffered data received since start_rx() was called.
- NodeJS
- Python
- Rust
const receivedData = await rs232.rx();
console.log(receivedData); // number[]
received_data = rs232.rx()
print(received_data) # list of integers
let rs232 = tester.com.rs232(0)?;
let received_data = rs232.rx()?;
println!("{:?}", received_data); // Vec<u8>
Returns: Promise<SerialData> / SerialData / Result<SerialData, At1000Error> - Received data as byte array (number[]). The device buffers up to 65536 received bytes per interface.
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, // 50 to 1000000
data_bits: number, // 7 or 8
parity: 'none' | 'odd' | 'even' | 'mark' | 'space',
stop_bits: '1' | '1.5' | '2'
}
Rust: ikalogic_at1000::Rs232Config
pub struct Rs232Config {
pub enabled: bool,
pub baud_rate: u32,
pub data_bits: u8,
pub stop_bits: SerialStopBits,
pub parity: SerialParity,
}
Rs232ConfigPatch​
Partial configuration for the configure() method. All properties are optional.
{
enabled?: boolean,
baud_rate?: number, // 50 to 1000000
data_bits?: number, // 7 or 8
parity?: 'none' | 'odd' | 'even' | 'mark' | 'space',
stop_bits?: '1' | '1.5' | '2'
}
Rust: ikalogic_at1000::Rs232ConfigPatch (derives Default, so unset fields can be left to ..Default::default())
pub struct Rs232ConfigPatch {
pub enabled: Option<bool>,
pub baud_rate: Option<u32>,
pub data_bits: Option<u8>,
pub stop_bits: Option<SerialStopBits>,
pub parity: Option<SerialParity>,
}
Rs232EnableConfig​
Optional configuration for the enable() method.
{
baud_rate?: number, // 50 to 1000000
data_bits?: number, // 7 or 8
parity?: 'none' | 'odd' | 'even' | 'mark' | 'space',
stop_bits?: '1' | '1.5' | '2'
}
Rust: ikalogic_at1000::Rs232EnableConfig (derives Default)
pub struct Rs232EnableConfig {
pub baud_rate: Option<u32>,
pub data_bits: Option<u8>,
pub stop_bits: Option<SerialStopBits>,
pub parity: Option<SerialParity>,
}
Parity and stop bits are enums in Rust instead of strings:
pub enum SerialParity {
None,
Odd,
Even,
Mark,
Space,
}
pub enum SerialStopBits {
One,
OnePointFive,
Two,
}
SerialDataInput​
Input data type for transmission.
string | number[]
string: Maximum 65536 charactersnumber[]: Maximum 65536 elements, each byte in range [0, 255]
Rust: &[u8], with no string variant. Use b"text" for ASCII text and &[0x48, 0x65] for raw bytes.
SerialData​
Output data type, always returned as a byte array.
number[] // Array of bytes (0-255)
Rust: ikalogic_at1000::SerialData, a type alias for Vec<u8>.
Usage Example​
- NodeJS
- Python
- Rust
import { AT1000 } from '@ikalogic/at1000';
// Find and connect to device
const devices = await AT1000.findDevices();
const tester = await AT1000.open(devices[0]);
await tester.reset(); // Reset the device to a known state
// 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 time
# Find and connect to device
devices = AT1000.find_devices()
tester = AT1000.open(devices[0])
tester.reset() # Reset the device to a known state
# Access RS232 interface 0
rs232 = tester.com.rs232(0)
# Enable with 115200 baud rate
rs232.enable(baud_rate=115200)
# Start receiving data
rs232.start_rx()
# Transmit data
rs232.tx("AT\r\n")
# Wait for response
time.sleep(0.1)
# Read received data
response = rs232.rx()
print(f"Received: {bytes(response).decode()}")
# Stop receiving
rs232.stop_rx()
# Disable interface
rs232.disable()
use ikalogic_at1000::{AT1000, Rs232EnableConfig};
use std::thread::sleep;
use std::time::Duration;
// Find and connect to device
let devices = AT1000::find_devices(Duration::from_millis(500))?;
let tester = AT1000::open(&devices[0])?;
tester.reset()?; // Reset the device to a known state
// Access RS232 interface 0
let rs232 = tester.com.rs232(0)?;
// Enable with 115200 baud rate
rs232.enable(&Rs232EnableConfig { baud_rate: Some(115_200), ..Default::default() })?;
// Start receiving data
rs232.start_rx()?;
// Transmit data
rs232.tx(b"AT\r\n")?;
// Wait for response
sleep(Duration::from_millis(100));
// Read received data
let response = rs232.rx()?;
println!("Received: {}", String::from_utf8_lossy(&response));
// Stop receiving
rs232.stop_rx()?;
// Disable interface
rs232.disable()?;
Common Patterns​
String Conversion​
- NodeJS
- Python
- Rust
// 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 = rs232.rx()
text = bytes(byte_list).decode('utf-8')
let rs232 = tester.com.rs232(0)?;
// Convert received bytes to a string, replacing invalid sequences
let bytes = rs232.rx()?;
let text = String::from_utf8_lossy(&bytes);
// Or keep the UTF-8 error to handle it yourself
let text = std::str::from_utf8(&bytes);
Binary Protocol Communication​
- NodeJS
- Python
- Rust
// Send binary command
await rs232.tx([0x02, 0x10, 0x00, 0xFF, 0x03]);
// Read binary response
const response = await rs232.rx();
# Send binary command
rs232.tx([0x02, 0x10, 0x00, 0xFF, 0x03])
# Read binary response
response = rs232.rx()
let rs232 = tester.com.rs232(0)?;
// Send binary command
rs232.tx(&[0x02, 0x10, 0x00, 0xFF, 0x03])?;
// Read binary response
let response = rs232.rx()?;
Continuous Monitoring​
- NodeJS
- Python
- Rust
// 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 time
# Start continuous reception
rs232.start_rx()
# Poll periodically
def poll_rx():
while True:
data = rs232.rx()
if len(data) > 0:
print(f"Received: {data}")
time.sleep(0.1)
poll_rx()
use std::thread::sleep;
use std::time::Duration;
let rs232 = tester.com.rs232(0)?;
// Start continuous reception
rs232.start_rx()?;
// Poll periodically
loop {
let data = rs232.rx()?;
if !data.is_empty() {
println!("Received: {:?}", data);
}
sleep(Duration::from_millis(100));
}