pub enum PlcValue {
}
Expand description
Represents the different data types supported by Allen-Bradley PLCs
These correspond to the CIP data type codes used in EtherNet/IP communication. Each variant maps to a specific 16-bit type identifier that the PLC uses to describe tag data.
§Supported Data Types
§Integer Types
- SINT: 8-bit signed integer (-128 to 127)
- INT: 16-bit signed integer (-32,768 to 32,767)
- DINT: 32-bit signed integer (-2,147,483,648 to 2,147,483,647)
- LINT: 64-bit signed integer (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
§Unsigned Integer Types
- USINT: 8-bit unsigned integer (0 to 255)
- UINT: 16-bit unsigned integer (0 to 65,535)
- UDINT: 32-bit unsigned integer (0 to 4,294,967,295)
- ULINT: 64-bit unsigned integer (0 to 18,446,744,073,709,551,615)
§Floating Point Types
- REAL: 32-bit IEEE 754 float (±1.18 × 10^-38 to ±3.40 × 10^38)
- LREAL: 64-bit IEEE 754 double (±2.23 × 10^-308 to ±1.80 × 10^308)
§Other Types
- BOOL: Boolean value (true/false)
- STRING: Variable-length string
- UDT: User Defined Type (structured data)
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(HashMap<String, PlcValue>)
User Defined Type instance
Maps to CIP type 0x00A0. Structured data type containing multiple members of different types.
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