Skip to main content

RS232

The RS232 interface provides serial communication capabilities with configurable baud rates from 300 to 1,000,000 bps.

TIP

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

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

API Reference​

Accessing RS232​

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

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

Parameters:

  • config (Rs232ConfigPatch): Configuration object with optional properties:
    • enabled (boolean, optional): Enable or disable the interface
    • baud_rate (number, optional): Baud rate (300 to 1000000)

Returns: Promise<Rs232Config> - The updated configuration

Exceptions:

  • Throws validation error if baud_rate is 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.

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_rate is outside the range [300, 1000000]

disable()​

Disables the RS232 interface.

await rs232.disable();

Returns: Promise<Rs232Config> - 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): 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.

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.

await rs232.stop_rx();

Returns: Promise<void>


rx()​

Reads all buffered data received since start_rx() was called.

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

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 characters
  • number[]: 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​

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

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