Skip to main content

RS232

The RS232 interface provides serial communication capabilities with the standard baud rates from 50 to 1,000,000 bps.

TIP

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).

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 byte array)
let data_rx = await rs232.rx();

// Print received message
console.log("RS232 Data Received:", data_rx);

// Stop receiving on RS232_0
await rs232.stop_rx();

API Reference​

Accessing RS232​

const rs232 = tester.com.rs232(id);

Parameters:

  • id (number / int / usize): 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.

await rs232.configure({ baud_rate: 115200 });

Parameters:

  • config (Rs232ConfigPatch): Configuration object with optional properties:
    • enabled (boolean / bool / Option<bool>, optional): Enable or disable the interface
    • baud_rate (number / int / Option<u32>, optional): Baud rate, one of the standard rates listed below (50 to 1000000)
    • data_bits (number / int / Option<DataBits>, optional): Data bits per character (7 or 8; DataBits::Seven or DataBits::Eight in Rust)
    • parity (string / str / Option<SerialParity>, optional): Parity mode - 'none', 'odd', or 'even' (SerialParity::{None, Odd, Even} in Rust). Mark and space parity are UART-only and rejected on RS232
    • stop_bits (string / str / Option<SerialStopBits>, optional): Stop bits - '1' or '2' (SerialStopBits::{One, Two} in Rust). 1.5 stop bits are UART-only and rejected on RS232

Valid baud rates: 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000

Default configuration (after tester.reset()): disabled, baud_rate 115200, 8 data bits, no parity, 1 stop bit (8N1).

Returns: Promise<Rs232Config> / Rs232Config / Result<Rs232Config, At1000Error> - The updated configuration

Exceptions:

  • Throws validation error if baud_rate is outside the range [50, 1000000]
  • Throws error 400 INVALID_VALUE if baud_rate is not one of the valid baud rates
  • Throws validation error if parameters don't match expected types

enable([config])​

Enables the RS232 interface and optionally applies configuration.

await rs232.enable({ baud_rate: 9600 });

Parameters:

  • config (Rs232EnableConfig, optional / Rs232ConfigPatch in Rust, required): Configuration to apply. In Rust, pass Rs232ConfigPatch::default() to keep the current settings; enable ignores the patch's enabled field and always enables the interface:
    • baud_rate (number / int / Option<u32>, optional): Baud rate, one of the standard rates listed above (50 to 1000000)
    • data_bits (number / int / Option<DataBits>, optional): Data bits per character (7 or 8; DataBits::Seven or DataBits::Eight in Rust)
    • parity (string / str / Option<SerialParity>, optional): Parity mode - 'none', 'odd', or 'even' (SerialParity::{None, Odd, Even} in Rust). Mark and space parity are UART-only and rejected on RS232
    • stop_bits (string / str / Option<SerialStopBits>, optional): Stop bits - '1' or '2' (SerialStopBits::{One, Two} in Rust). 1.5 stop bits are UART-only and rejected on RS232

Returns: Promise<Rs232Config> / Rs232Config / Result<Rs232Config, At1000Error> - The updated configuration with enabled: true

Exceptions:

  • Throws validation error if baud_rate is outside the range [50, 1000000]
  • Throws error 400 INVALID_VALUE if baud_rate is not one of the valid baud rates

disable()​

Disables the RS232 interface.

await rs232.disable();

Returns: Promise<Rs232Config> / Rs232Config / Result<Rs232Config, At1000Error> - The updated configuration with enabled: false


tx(data)​

Transmits data over the RS232 interface.

// Send string
await rs232.tx("Hello, World!");

// Send byte array
await 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<Vec<u8>, 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]
  • Throws error 400 INVALID_CONFIGURATION if the interface is disabled

start_rx()​

Starts buffering received data from the RS232 interface.

await rs232.start_rx();

Returns: Promise<void> / None / Result<(), At1000Error>

Note: start_rx() discards any data still pending on the port. 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.

await rs232.stop_rx();

Returns: Promise<void> / None / Result<(), At1000Error>


rx()​

Reads all buffered data received since the last start_rx() or rx() call.

const receivedData = await rs232.rx();
console.log(receivedData); // number[]

Returns: Promise<SerialData> / SerialData / Result<Vec<u8>, At1000Error> - Received data as byte array (number[]). The device buffers up to 65536 received bytes per interface; bytes received while the buffer is full are dropped until rx() empties it.

Note: This method returns all data accumulated since the last start_rx() or rx() call and clears the buffer. Unlike RS485, rx() also works without start_rx(): it then returns the bytes waiting on the port.

Exceptions:

  • Throws error 400 INVALID_CONFIGURATION if the interface is disabled

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',
stop_bits: '1' | '2'
}

Rust: ikalogic_at1000::Rs232Config

pub struct Rs232Config {
pub enabled: bool,
pub baud_rate: u32,
pub data_bits: DataBits,
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',
stop_bits?: '1' | '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<DataBits>,
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',
stop_bits?: '1' | '2'
}

Rust has no separate enable type: enable() takes a Rs232ConfigPatch and sets enabled: true itself.

Data bits, parity and stop bits are enums in Rust instead of numbers and strings:

pub enum DataBits {
Seven,
Eight,
}

#[non_exhaustive]
pub enum SerialParity {
None,
Odd,
Even,
Mark,
Space,
Unknown(String),
}

#[non_exhaustive]
pub enum SerialStopBits {
One,
OnePointFive,
Two,
Unknown(String),
}

Unknown(String) keeps a value reported by a newer firmware that this SDK version does not know, so a match on SerialParity or SerialStopBits needs a _ arm. The enums are shared with the UART: RS232 rejects Mark, Space and OnePointFive (InvalidInput in Rust, 400 INVALID_VALUE from the device).

SerialDataInput​

Input data type for transmission.

string | number[]
  • string: Maximum 65536 characters
  • number[]: 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: Vec<u8>.


Usage Example​

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();

Common Patterns​

String Conversion​

// 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));

Binary Protocol Communication​

// Send binary command
await rs232.tx([0x02, 0x10, 0x00, 0xFF, 0x03]);

// Read binary response
const response = await rs232.rx();

Continuous Monitoring​

// 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);