RS485
The RS485 interface provides differential serial communication with configurable baud rates from 300 to 20,000,000 bps. Supports optional termination resistors for proper bus termination.
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.
The CAN bus and RS485_0 share the same GPIO pins for communication. Therefore, only one of these interfaces can be enabled at a time.
When enabling either the CAN bus or RS485_0, the shared GPIO pins will be automatically configured for the selected interface.
Quick Start​
The RS485 bus supports enabling/disabling, termination resistance, transmitting, and receiving data.
- 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 rs485 = tester.com.rs485(1); // Access RS485_1 bus on AT1000
await rs485.configure({
baud_rate: 9600,
termination_resistors: true,
enabled: true
});
// Start receiving RS485 messages
await rs485.start_rx();
// Transmit a message over RS485
await rs485.tx([0xDE, 0xAD, 0xBE, 0xEF]);
// Receive data (returns an array of bytes)
let data_rx = await rs485.rx();
// Print received bytes
console.log("RS485 Data Received:", data_rx);
// Disable RS485_1 bus
await rs485.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
rs485 = tester.com.rs485(1) # Access RS485_1 bus on AT1000
rs485.configure(
baud_rate=9600,
termination_resistors=True,
enabled=True
)
# Start receiving RS485 messages
rs485.start_rx()
# Transmit a message over RS485
rs485.tx([0xDE, 0xAD, 0xBE, 0xEF])
# Receive data (returns an array of bytes)
data_rx = rs485.rx()
# Print received bytes
print(f"RS485 Data Received: {data_rx}")
# Disable RS485_1 bus
rs485.stop_rx()
use ikalogic_at1000::{AT1000, Rs485ConfigPatch};
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 rs485 = tester.com.rs485(1)?; // Access RS485_1 bus on AT1000
rs485.configure(&Rs485ConfigPatch {
baud_rate: Some(9600),
termination_resistors: Some(true),
enabled: Some(true),
..Default::default()
})?;
// Start receiving RS485 messages
rs485.start_rx()?;
// Transmit a message over RS485
rs485.tx(&[0xDE, 0xAD, 0xBE, 0xEF])?;
// Receive data (returns a vector of bytes)
let data_rx = rs485.rx()?;
// Print received bytes
println!("RS485 Data Received: {data_rx:?}");
// Disable RS485_1 bus
rs485.stop_rx()?;
API Reference​
Accessing RS485​
- NodeJS
- Python
- Rust
const rs485 = tester.com.rs485(id);
rs485 = tester.com.rs485(id)
let id = 0; // 0-based interface index
let rs485 = tester.com.rs485(id)?;
Parameters:
id(number/int/u32): The RS485 interface identifier (0-based index)
Returns: Rs485 instance / Result<Rs485, At1000Error> in Rust
Methods​
configure(config)​
Configures the RS485 interface parameters without changing the enabled state.
- NodeJS
- Python
- Rust
await rs485.configure({
baud_rate: 115200,
termination_resistors: true
});
rs485.configure(
baud_rate=115200,
termination_resistors=True
)
use ikalogic_at1000::Rs485ConfigPatch;
let rs485 = tester.com.rs485(0)?;
rs485.configure(&Rs485ConfigPatch {
baud_rate: Some(115200),
termination_resistors: Some(true),
..Default::default()
})?;
Parameters:
config(Rs485ConfigPatch/&Rs485ConfigPatchin 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 (300 to 20000000)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'stop_bits(string/str/Option<SerialStopBits>, optional): Stop bits -'1','1.5', or'2'termination_resistors(boolean/bool/Option<bool>, optional): Enable/disable 120Ω termination resistors
Returns: Promise<Rs485Config> / Rs485Config / Result<Rs485Config, At1000Error> - The updated configuration
Exceptions:
- Throws validation error if
baud_rateis outside the range [300, 20000000] - Throws validation error if parameters don't match expected types
enable([config])​
Enables the RS485 interface and optionally applies configuration.
- NodeJS
- Python
- Rust
await rs485.enable({
baud_rate: 9600,
termination_resistors: false
});
rs485.enable(
baud_rate=9600,
termination_resistors=False
)
use ikalogic_at1000::Rs485EnableConfig;
let rs485 = tester.com.rs485(0)?;
rs485.enable(&Rs485EnableConfig {
baud_rate: Some(9600),
termination_resistors: Some(false),
..Default::default()
})?;
Parameters:
config(Rs485EnableConfig, optional /&Rs485EnableConfigin Rust): Optional configuration to apply:baud_rate(number/int/Option<u32>, optional): Baud rate (300 to 20000000)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'stop_bits(string/str/Option<SerialStopBits>, optional): Stop bits -'1','1.5', or'2'termination_resistors(boolean/bool/Option<bool>, optional): Enable/disable termination resistors
Returns: Promise<Rs485Config> / Rs485Config / Result<Rs485Config, At1000Error> - The updated configuration with enabled: true
Exceptions:
- Throws validation error if
baud_rateis outside the range [300, 20000000]
disable()​
Disables the RS485 interface.
- NodeJS
- Python
- Rust
await rs485.disable();
rs485.disable()
let rs485 = tester.com.rs485(0)?;
rs485.disable()?;
Returns: Promise<Rs485Config> / Rs485Config / Result<Rs485Config, At1000Error> - The updated configuration with enabled: false
tx(data)​
Transmits data over the RS485 interface.
- NodeJS
- Python
- Rust
// Send string
await rs485.tx("Hello, World!");
// Send byte array
await rs485.tx([0x48, 0x65, 0x6C, 0x6C, 0x6F]);
# Send string
rs485.tx("Hello, World!")
# Send byte array
rs485.tx([0x48, 0x65, 0x6C, 0x6C, 0x6F])
let rs485 = tester.com.rs485(0)?;
// Send string
rs485.tx(b"Hello, World!")?;
// Send byte array
rs485.tx(&[0x48, 0x65, 0x6C, 0x6C, 0x6F])?;
Parameters:
data(SerialDataInput/&[u8]in Rust): Data to transmit, either:string: Text data (max 65536 characters)number[]: Byte array (each byte 0-255, max 65536 bytes)&[u8](Rust): byte slice - write text asb"..."ortext.as_bytes()
Returns: Promise<SerialData> / SerialData / Result<SerialData, At1000Error> - The transmitted data as byte array (number[], Vec<u8> in Rust)
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 RS485 interface.
- NodeJS
- Python
- Rust
await rs485.start_rx();
rs485.start_rx()
let rs485 = tester.com.rs485(0)?;
rs485.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 RS485 interface.
- NodeJS
- Python
- Rust
await rs485.stop_rx();
rs485.stop_rx()
let rs485 = tester.com.rs485(0)?;
rs485.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 rs485.rx();
console.log(receivedData); // number[]
received_data = rs485.rx()
print(received_data) # list of integers
let rs485 = tester.com.rs485(0)?;
let received_data = rs485.rx()?;
println!("{received_data:?}"); // Vec<u8>
Returns: Promise<SerialData> / SerialData / Result<SerialData, At1000Error> - Received data as byte array (number[], Vec<u8> in Rust). 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​
Rs485Config​
Complete configuration object returned by configuration methods.
{
enabled: boolean,
baud_rate: number, // 300 to 20000000
data_bits: number, // 7 or 8
parity: 'none' | 'odd' | 'even' | 'mark' | 'space',
stop_bits: '1' | '1.5' | '2',
termination_resistors: boolean
}
Rust: ikalogic_at1000::Rs485Config
pub struct Rs485Config {
pub enabled: bool,
pub baud_rate: u32,
pub data_bits: u8,
pub stop_bits: SerialStopBits,
pub parity: SerialParity,
pub termination_resistors: bool,
}
pub enum SerialStopBits { One, OnePointFive, Two }
pub enum SerialParity { None, Odd, Even, Mark, Space }
Rs485ConfigPatch​
Partial configuration for the configure() method. All properties are optional.
{
enabled?: boolean,
baud_rate?: number, // 300 to 20000000
data_bits?: number, // 7 or 8
parity?: 'none' | 'odd' | 'even' | 'mark' | 'space',
stop_bits?: '1' | '1.5' | '2',
termination_resistors?: boolean
}
Rust: ikalogic_at1000::Rs485ConfigPatch (derives Default, so unset fields stay None)
pub struct Rs485ConfigPatch {
pub enabled: Option<bool>,
pub baud_rate: Option<u32>,
pub data_bits: Option<u8>,
pub stop_bits: Option<SerialStopBits>,
pub parity: Option<SerialParity>,
pub termination_resistors: Option<bool>,
}
Rs485EnableConfig​
Optional configuration for the enable() method.
{
baud_rate?: number, // 300 to 20000000
data_bits?: number, // 7 or 8
parity?: 'none' | 'odd' | 'even' | 'mark' | 'space',
stop_bits?: '1' | '1.5' | '2',
termination_resistors?: boolean
}
Rust: ikalogic_at1000::Rs485EnableConfig (derives Default, so unset fields stay None)
pub struct Rs485EnableConfig {
pub baud_rate: Option<u32>,
pub data_bits: Option<u8>,
pub stop_bits: Option<SerialStopBits>,
pub parity: Option<SerialParity>,
pub termination_resistors: Option<bool>,
}
SerialDataInput​
Input data type for transmission.
string | number[]
string: Maximum 65536 charactersnumber[]: Maximum 65536 elements, each byte in range [0, 255]
Rust: &[u8] - the Rust SDK accepts bytes only. Write text as b"..." or text.as_bytes().
SerialData​
Output data type, always returned as a byte array.
number[] // Array of bytes (0-255)
Rust: ikalogic_at1000::SerialData
pub type SerialData = 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 RS485 interface 0
const rs485 = tester.com.rs485(0);
// Enable with 115200 baud rate and termination resistors
await rs485.enable({
baud_rate: 115200,
termination_resistors: true
});
// Start receiving data
await rs485.start_rx();
// Transmit data
await rs485.tx([0x01, 0x03, 0x00, 0x00, 0x00, 0x0A]);
// Wait for response
await new Promise(resolve => setTimeout(resolve, 100));
// Read received data
const response = await rs485.rx();
console.log("Received:", response);
// Stop receiving
await rs485.stop_rx();
// Disable interface
await rs485.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 RS485 interface 0
rs485 = tester.com.rs485(0)
# Enable with 115200 baud rate and termination resistors
rs485.enable(
baud_rate=115200,
termination_resistors=True
)
# Start receiving data
rs485.start_rx()
# Transmit data
rs485.tx([0x01, 0x03, 0x00, 0x00, 0x00, 0x0A])
# Wait for response
time.sleep(0.1)
# Read received data
response = rs485.rx()
print(f"Received: {response}")
# Stop receiving
rs485.stop_rx()
# Disable interface
rs485.disable()
use ikalogic_at1000::{AT1000, Rs485EnableConfig};
use std::{thread, 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 RS485 interface 0
let rs485 = tester.com.rs485(0)?;
// Enable with 115200 baud rate and termination resistors
rs485.enable(&Rs485EnableConfig {
baud_rate: Some(115200),
termination_resistors: Some(true),
..Default::default()
})?;
// Start receiving data
rs485.start_rx()?;
// Transmit data
rs485.tx(&[0x01, 0x03, 0x00, 0x00, 0x00, 0x0A])?;
// Wait for response
thread::sleep(Duration::from_millis(100));
// Read received data
let response = rs485.rx()?;
println!("Received: {response:?}");
// Stop receiving
rs485.stop_rx()?;
// Disable interface
rs485.disable()?;
Common Patterns​
Modbus RTU Communication​
- NodeJS
- Python
- Rust
// Configure for Modbus (typically 9600, 19200, or 115200)
await rs485.enable({
baud_rate: 9600,
termination_resistors: true
});
// Function to calculate CRC16 (Modbus)
function crc16(buffer) {
let crc = 0xFFFF;
for (let byte of buffer) {
crc ^= byte;
for (let i = 0; i < 8; i++) {
if (crc & 0x0001) {
crc = (crc >> 1) ^ 0xA001;
} else {
crc >>= 1;
}
}
}
return [crc & 0xFF, (crc >> 8) & 0xFF];
}
// Send Modbus request
const frame = [0x01, 0x03, 0x00, 0x00, 0x00, 0x0A];
const crc = crc16(frame);
await rs485.tx([...frame, ...crc]);
# Configure for Modbus (typically 9600, 19200, or 115200)
rs485.enable(
baud_rate=9600,
termination_resistors=True
)
# Function to calculate CRC16 (Modbus)
def crc16(buffer):
crc = 0xFFFF
for byte in buffer:
crc ^= byte
for _ in range(8):
if crc & 0x0001:
crc = (crc >> 1) ^ 0xA001
else:
crc >>= 1
return [crc & 0xFF, (crc >> 8) & 0xFF]
# Send Modbus request
frame = [0x01, 0x03, 0x00, 0x00, 0x00, 0x0A]
crc = crc16(frame)
rs485.tx(frame + crc)
use ikalogic_at1000::Rs485EnableConfig;
let rs485 = tester.com.rs485(0)?;
// Configure for Modbus (typically 9600, 19200, or 115200)
rs485.enable(&Rs485EnableConfig {
baud_rate: Some(9600),
termination_resistors: Some(true),
..Default::default()
})?;
// Function to calculate CRC16 (Modbus)
fn crc16(buffer: &[u8]) -> [u8; 2] {
let mut crc: u16 = 0xFFFF;
for byte in buffer {
crc ^= u16::from(*byte);
for _ in 0..8 {
if crc & 0x0001 != 0 {
crc = (crc >> 1) ^ 0xA001;
} else {
crc >>= 1;
}
}
}
[(crc & 0xFF) as u8, (crc >> 8) as u8]
}
// Send Modbus request
let frame: [u8; 6] = [0x01, 0x03, 0x00, 0x00, 0x00, 0x0A];
let crc = crc16(&frame);
let mut request = frame.to_vec();
request.extend_from_slice(&crc);
rs485.tx(&request)?;
Half-Duplex Communication​
- NodeJS
- Python
- Rust
// RS485 is half-duplex - send then receive
await rs485.start_rx();
// Send query
await rs485.tx("QUERY\r\n");
// Wait for device to respond
await new Promise(resolve => setTimeout(resolve, 50));
// Read response
const response = await rs485.rx();
await rs485.stop_rx();
import time
# RS485 is half-duplex - send then receive
rs485.start_rx()
# Send query
rs485.tx("QUERY\r\n")
# Wait for device to respond
time.sleep(0.05)
# Read response
response = rs485.rx()
rs485.stop_rx()
use std::{thread, time::Duration};
let rs485 = tester.com.rs485(0)?;
// RS485 is half-duplex - send then receive
rs485.start_rx()?;
// Send query
rs485.tx(b"QUERY\r\n")?;
// Wait for device to respond
thread::sleep(Duration::from_millis(50));
// Read response
let response = rs485.rx()?;
rs485.stop_rx()?;
Multi-Drop Network​
- NodeJS
- Python
- Rust
// Configure with termination resistors only on end nodes
const isEndNode = true;
await rs485.enable({
baud_rate: 115200,
termination_resistors: isEndNode
});
// Address specific devices on the bus
const deviceAddress = 0x05;
await rs485.tx([deviceAddress, 0x10, 0x00, 0x01]);
# Configure with termination resistors only on end nodes
is_end_node = True
rs485.enable(
baud_rate=115200,
termination_resistors=is_end_node
)
# Address specific devices on the bus
device_address = 0x05
rs485.tx([device_address, 0x10, 0x00, 0x01])
use ikalogic_at1000::Rs485EnableConfig;
let rs485 = tester.com.rs485(0)?;
// Configure with termination resistors only on end nodes
let is_end_node = true;
rs485.enable(&Rs485EnableConfig {
baud_rate: Some(115200),
termination_resistors: Some(is_end_node),
..Default::default()
})?;
// Address specific devices on the bus
let device_address: u8 = 0x05;
rs485.tx(&[device_address, 0x10, 0x00, 0x01])?;