pub struct S7Client<T: AsyncRead + AsyncWrite + Unpin + Send> { /* private fields */ }Implementations§
Source§impl<T: AsyncRead + AsyncWrite + Unpin + Send> S7Client<T>
impl<T: AsyncRead + AsyncWrite + Unpin + Send> S7Client<T>
pub async fn from_transport(transport: T, params: ConnectParams) -> Result<Self>
Sourcepub fn request_timeout(&self) -> Duration
pub fn request_timeout(&self) -> Duration
Return the current request timeout.
Sourcepub async fn set_request_timeout(&self, timeout: Duration)
pub async fn set_request_timeout(&self, timeout: Duration)
Update the request timeout at runtime.
This affects subsequent recv_s7 calls made by this client instance.
Sourcepub fn get_param(&self, name: &str) -> Result<Duration>
pub fn get_param(&self, name: &str) -> Result<Duration>
Read a client parameter by name.
Supported names: "request_timeout", "connect_timeout", "pdu_size".
Sourcepub fn set_param(&mut self, name: &str, value: Duration) -> Result<()>
pub fn set_param(&mut self, name: &str, value: Duration) -> Result<()>
Set a client parameter at runtime.
Supported names: "request_timeout" (Duration).
pub async fn db_read(&self, db: u16, start: u32, length: u16) -> Result<Bytes>
Sourcepub async fn read_multi_vars(
&self,
items: &[MultiReadItem],
) -> Result<Vec<Bytes>>
pub async fn read_multi_vars( &self, items: &[MultiReadItem], ) -> Result<Vec<Bytes>>
Read multiple PLC regions in one or more S7 PDU exchanges.
Automatically batches items when the item count would exceed the Siemens hard
limit of 20 per PDU, or when the encoded request or response would exceed the
negotiated PDU size. Returns one Bytes per item in input order.
Unlike db_read, this accepts any Area and TransportSize.
Sourcepub async fn write_multi_vars(&self, items: &[MultiWriteItem]) -> Result<()>
pub async fn write_multi_vars(&self, items: &[MultiWriteItem]) -> Result<()>
Write multiple PLC regions in one or more S7 PDU exchanges.
Automatically batches items when the count or encoded size would exceed the
negotiated PDU size or the Siemens hard limit of 20 items per PDU.
Returns Ok(()) only when all items are acknowledged with return code 0xFF.
pub async fn db_write(&self, db: u16, start: u32, data: &[u8]) -> Result<()>
Sourcepub async fn ab_read(
&self,
area: Area,
db_number: u16,
start: u32,
length: u16,
) -> Result<Bytes>
pub async fn ab_read( &self, area: Area, db_number: u16, start: u32, length: u16, ) -> Result<Bytes>
Read from any PLC area using absolute addressing.
A convenience wrapper around read_multi_vars
for a single area read.
Sourcepub async fn ab_write(
&self,
area: Area,
db_number: u16,
start: u32,
data: &[u8],
) -> Result<()>
pub async fn ab_write( &self, area: Area, db_number: u16, start: u32, data: &[u8], ) -> Result<()>
Write to any PLC area using absolute addressing.
A convenience wrapper around write_multi_vars
for a single area write.
pub async fn read_szl(&self, szl_id: u16, szl_index: u16) -> Result<SzlResponse>
pub async fn read_clock(&self) -> Result<PlcDateTime>
Sourcepub async fn copy_ram_to_rom(&self) -> Result<()>
pub async fn copy_ram_to_rom(&self) -> Result<()>
Copy RAM data to ROM (function 0x43).
Copies the CPU’s work memory to its load memory (retain on power-off).
Sourcepub async fn compress(&self) -> Result<()>
pub async fn compress(&self) -> Result<()>
Compress the PLC work memory (function 0x42).
Reorganises memory to eliminate fragmentation. The PLC must be in STOP mode before calling this.
Sourcepub async fn plc_stop(&self) -> Result<()>
pub async fn plc_stop(&self) -> Result<()>
Stop the PLC (S7 function code 0x29).
Sends a Job request with no additional data. Returns Ok(()) when the
PLC acknowledges the command, or an error if the PLC rejects it
(e.g., password-protected or CPU in a non-stoppable state).
Sourcepub async fn plc_hot_start(&self) -> Result<()>
pub async fn plc_hot_start(&self) -> Result<()>
Hot-start (warm restart) the PLC (S7 function code 0x28).
A warm restart retains the DB content and retentive memory.
Sourcepub async fn plc_cold_start(&self) -> Result<()>
pub async fn plc_cold_start(&self) -> Result<()>
Cold-start (full restart) the PLC (S7 function code 0x2A).
A cold start clears all DBs and non-retentive memory.
Sourcepub async fn get_plc_status(&self) -> Result<PlcStatus>
pub async fn get_plc_status(&self) -> Result<PlcStatus>
Read the current PLC status (S7 function code 0x31).
Returns one of [PlcStatus::Run], [PlcStatus::Stop], or
[PlcStatus::Unknown].
Sourcepub async fn get_order_code(&self) -> Result<OrderCode>
pub async fn get_order_code(&self) -> Result<OrderCode>
Read the PLC order code (SZL ID 0x0011).
The order code is a 20-character ASCII string (e.g. "6ES7 317-2EK14-0AB0").
Sourcepub async fn get_cpu_info(&self) -> Result<CpuInfo>
pub async fn get_cpu_info(&self) -> Result<CpuInfo>
Read detailed CPU information (SZL ID 0x001C).
Returns module type, serial number, plant identification, copyright and module name fields pre-parsed from the SZL response.
Sourcepub async fn get_cp_info(&self) -> Result<CpInfo>
pub async fn get_cp_info(&self) -> Result<CpInfo>
Read communication processor information (SZL ID 0x0131).
Returns maximum PDU length, connection count, and baud rates.
Sourcepub async fn read_module_list(&self) -> Result<Vec<ModuleEntry>>
pub async fn read_module_list(&self) -> Result<Vec<ModuleEntry>>
Read the rack module list (SZL ID 0x00A0).
Each entry is a 2-byte module type identifier.
Sourcepub async fn list_blocks(&self) -> Result<BlockList>
pub async fn list_blocks(&self) -> Result<BlockList>
List all blocks in the PLC grouped by type (SZL 0x0130).
Returns a [BlockList] with the total block count and per-type entries.
Sourcepub async fn get_ag_block_info(
&self,
block_type: u8,
block_number: u16,
) -> Result<BlockInfo>
pub async fn get_ag_block_info( &self, block_type: u8, block_number: u16, ) -> Result<BlockInfo>
Get detailed information about a block stored on the PLC.
block_type should be one of the BlockType
discriminant values (e.g. 0x41 for DB, 0x38 for OB).
Sourcepub async fn get_pg_block_info(
&self,
block_type: u8,
block_number: u16,
) -> Result<BlockInfo>
pub async fn get_pg_block_info( &self, block_type: u8, block_number: u16, ) -> Result<BlockInfo>
Get detailed block information from the PG perspective.
Same fields as get_ag_block_info but the
information is from the programming-device viewpoint.
Sourcepub async fn set_session_password(&self, password: &str) -> Result<()>
pub async fn set_session_password(&self, password: &str) -> Result<()>
Set a session password for protected PLC access.
The password is obfuscated using the S7 nibble-swap + XOR-0x55 algorithm and sent as a Job PDU with function code 0x12. Passwords longer than 8 bytes are truncated.
Sourcepub async fn clear_session_password(&self) -> Result<()>
pub async fn clear_session_password(&self) -> Result<()>
Clear the session password on the PLC (function code 0x11).
Sourcepub async fn get_protection(&self) -> Result<Protection>
pub async fn get_protection(&self) -> Result<Protection>
Read the current protection level (SZL ID 0x0032, index 0x0004).
Returns the protection scheme identifiers and level;
password_set is true when the PLC reports a non-empty password.
Sourcepub async fn delete_block(
&self,
block_type: u8,
block_number: u16,
) -> Result<()>
pub async fn delete_block( &self, block_type: u8, block_number: u16, ) -> Result<()>
Delete a block from the PLC (S7 function code 0x1F).
Sourcepub async fn upload(&self, block_type: u8, block_number: u16) -> Result<Vec<u8>>
pub async fn upload(&self, block_type: u8, block_number: u16) -> Result<Vec<u8>>
Upload a PLC block via S7 PI-Upload (function 0x1D).
Returns the raw block bytes in Diagra format (20-byte header + payload).
Use [BlockData::from_bytes] to parse the result.
Sourcepub async fn db_get(&self, db_number: u16) -> Result<Vec<u8>>
pub async fn db_get(&self, db_number: u16) -> Result<Vec<u8>>
Upload a DB block (convenience wrapper around upload).
Source§impl S7Client<TcpTransport>
impl S7Client<TcpTransport>
pub async fn connect(addr: SocketAddr, params: ConnectParams) -> Result<Self>
Source§impl S7Client<UdpTransport>
impl S7Client<UdpTransport>
Sourcepub async fn connect_udp(
addr: SocketAddr,
params: ConnectParams,
) -> Result<Self>
pub async fn connect_udp( addr: SocketAddr, params: ConnectParams, ) -> Result<Self>
Connect to a PLC using UDP transport.