pub enum PlcValue {
}Variants§
Bool(bool)
Boolean value (single bit)
Maps to CIP type 0x00C1. In CompactLogix PLCs, BOOL tags are stored as single bits but transmitted as bytes over the network.
Sint(i8)
8-bit signed integer (-128 to 127)
Maps to CIP type 0x00C2. Used for small numeric values, status codes, and compact data storage.
Int(i16)
16-bit signed integer (-32,768 to 32,767)
Maps to CIP type 0x00C3. Common for analog input/output values, counters, and medium-range numeric data.
Dint(i32)
32-bit signed integer (-2,147,483,648 to 2,147,483,647)
Maps to CIP type 0x00C4. This is the most common integer type in Allen-Bradley PLCs, used for counters, setpoints, and numeric values.
Lint(i64)
64-bit signed integer (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
Maps to CIP type 0x00C5. Used for large counters, timestamps, and high-precision calculations.
Usint(u8)
8-bit unsigned integer (0 to 255)
Maps to CIP type 0x00C6. Used for byte data, small counters, and status flags.
Uint(u16)
16-bit unsigned integer (0 to 65,535)
Maps to CIP type 0x00C7. Common for analog values, port numbers, and medium-range unsigned data.
Udint(u32)
32-bit unsigned integer (0 to 4,294,967,295)
Maps to CIP type 0x00C8. Used for large counters, memory addresses, and unsigned calculations.
Ulint(u64)
64-bit unsigned integer (0 to 18,446,744,073,709,551,615)
Maps to CIP type 0x00C9. Used for very large counters, timestamps, and high-precision unsigned calculations.
Real(f32)
32-bit IEEE 754 floating point number
Maps to CIP type 0x00CA. Used for analog values, calculations, and any data requiring decimal precision. Range: ±1.18 × 10^-38 to ±3.40 × 10^38
Lreal(f64)
64-bit IEEE 754 floating point number
Maps to CIP type 0x00CB. Used for high-precision calculations, scientific data, and extended-range floating point values. Range: ±2.23 × 10^-308 to ±1.80 × 10^308
String(String)
String value
Maps to CIP type 0x00DA. Variable-length string data commonly used for product names, status messages, and text data.
Udt(UdtData)
User Defined Type instance
Maps to CIP type 0x00A0. Structured data type containing multiple members of different types.
v0.6.0: Uses UdtData which stores the symbol_id (template instance ID)
and raw bytes. This generic format works for any UDT without requiring
knowledge of member names ahead of time. The raw bytes can be parsed
into member values when the UDT definition is available using UdtData::parse().
§Example
use rust_ethernet_ip::PlcValue;
let value = client.read_tag("MyUDT").await?;
if let PlcValue::Udt(udt_data) = value {
let udt_def = client.get_udt_definition("MyUDT").await?;
// Convert UdtDefinition to UserDefinedType
let mut user_def = rust_ethernet_ip::udt::UserDefinedType::new(udt_def.name.clone());
for member in &udt_def.members {
user_def.add_member(member.clone());
}
let members = udt_data.parse(&user_def)?;
// Access members via HashMap
}Implementations§
Source§impl PlcValue
impl PlcValue
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Converts the PLC value to its byte representation for network transmission
This function handles the little-endian byte encoding required by the EtherNet/IP protocol. Each data type has specific encoding rules:
- BOOL: Single byte (0x00 = false, 0xFF = true)
- SINT: Single signed byte
- INT: 2 bytes in little-endian format
- DINT: 4 bytes in little-endian format
- LINT: 8 bytes in little-endian format
- USINT: Single unsigned byte
- UINT: 2 bytes in little-endian format
- UDINT: 4 bytes in little-endian format
- ULINT: 8 bytes in little-endian format
- REAL: 4 bytes IEEE 754 little-endian format
- LREAL: 8 bytes IEEE 754 little-endian format
§Returns
A vector of bytes ready for transmission to the PLC
Sourcepub fn get_data_type(&self) -> u16
pub fn get_data_type(&self) -> u16
Returns the CIP data type code for this value
These codes are defined by the CIP specification and must match exactly what the PLC expects for each data type.
§Returns
The 16-bit CIP type code for this value type