Enum PlcValue

Source
pub enum PlcValue {
Show 13 variants Bool(bool), Sint(i8), Int(i16), Dint(i32), Lint(i64), Usint(u8), Uint(u16), Udint(u32), Ulint(u64), Real(f32), Lreal(f64), String(String), Udt(HashMap<String, 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

Source

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

Source

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

Trait Implementations§

Source§

impl Clone for PlcValue

Source§

fn clone(&self) -> PlcValue

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PlcValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for PlcValue

Source§

fn eq(&self, other: &PlcValue) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for PlcValue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,