提交 66c0aaa2 authored 作者: Serhij S's avatar Serhij S

0.1.28

上级 d1c3dc64
[package] [package]
name = "roboplc" name = "roboplc"
version = "0.1.27" version = "0.1.28"
edition = "2021" edition = "2021"
authors = ["Serhij S. <div@altertech.com>"] authors = ["Serhij S. <div@altertech.com>"]
license = "Apache-2.0" license = "Apache-2.0"
......
//!
//! [EAPI communication example](https://github.com/eva-ics/roboplc/blob/main/examples/eapi.rs)
use binrw::BinWrite; use binrw::BinWrite;
use busrt::rpc::{RpcError, RpcEvent, RpcHandlers, RpcResult}; use busrt::rpc::{RpcError, RpcEvent, RpcHandlers, RpcResult};
use busrt::{async_trait, QoS}; use busrt::{async_trait, QoS};
...@@ -61,6 +63,7 @@ impl DataDeliveryPolicy for PushPayload { ...@@ -61,6 +63,7 @@ impl DataDeliveryPolicy for PushPayload {
} }
} }
/// EAPI connection configuration
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EAPIConfig<D, V> pub struct EAPIConfig<D, V>
where where
...@@ -147,7 +150,9 @@ where ...@@ -147,7 +150,9 @@ where
} }
} }
/// Action handler functions type
pub type ActionHandlerFn<D, V> = fn(&mut Action, context: &Context<D, V>) -> ActionResult; pub type ActionHandlerFn<D, V> = fn(&mut Action, context: &Context<D, V>) -> ActionResult;
/// The result type of action handler functions
pub type ActionResult = std::result::Result<(), Box<dyn std::error::Error>>; pub type ActionResult = std::result::Result<(), Box<dyn std::error::Error>>;
type ActionHandlers<D, V> = Arc<BTreeMap<OID, ActionHandlerFn<D, V>>>; type ActionHandlers<D, V> = Arc<BTreeMap<OID, ActionHandlerFn<D, V>>>;
...@@ -276,6 +281,7 @@ where ...@@ -276,6 +281,7 @@ where
} }
} }
/// EAPI connector, requires to be run in a separate thread manually
pub struct EAPI<D, V> pub struct EAPI<D, V>
where where
D: DataDeliveryPolicy + Clone + Send + Sync + 'static, D: DataDeliveryPolicy + Clone + Send + Sync + 'static,
......
//!
//! The module provides mapping for various protocols. Structural mapping is built on top of
//! the [binrw](https://crates.io/search?q=binrw) crate.
pub use binrw; pub use binrw;
use binrw::{BinRead, BinWrite}; use binrw::{BinRead, BinWrite};
use crate::Result; use crate::Result;
#[cfg(feature = "eapi")] #[cfg(feature = "eapi")]
/// EVA ICS local bus API
pub mod eapi; pub mod eapi;
#[cfg(feature = "modbus")] #[cfg(feature = "modbus")]
/// Modbus communication
pub mod modbus; pub mod modbus;
/// Raw UDP communication
pub mod raw_udp; pub mod raw_udp;
#[allow(clippy::module_name_repetitions)] #[allow(clippy::module_name_repetitions)]
......
//!
//! Contains Modbus client/server implementations.
//!
//! Examples: [modbus
//! master(client)](https://github.com/eva-ics/roboplc/blob/main/examples/modbus-master.rs),
//! [modbus slave(server)](https://github.com/eva-ics/roboplc/blob/main/examples/modbus-slave.rs)
use std::io::Cursor; use std::io::Cursor;
use crate::comm::{Client, Protocol}; use crate::comm::{Client, Protocol};
...@@ -22,6 +28,7 @@ pub mod prelude { ...@@ -22,6 +28,7 @@ pub mod prelude {
}; };
} }
/// Swaps endianess of floating point numbers in case of non-standard IEEE 754 layout.
pub trait SwapModbusEndianess { pub trait SwapModbusEndianess {
fn to_swapped_modbus_endianness(&self) -> Self; fn to_swapped_modbus_endianness(&self) -> Self;
} }
...@@ -49,6 +56,7 @@ impl From<Protocol> for ModbusProto { ...@@ -49,6 +56,7 @@ impl From<Protocol> for ModbusProto {
} }
} }
/// Mapping options for Modbus client
#[allow(clippy::module_name_repetitions)] #[allow(clippy::module_name_repetitions)]
#[derive(Clone)] #[derive(Clone)]
pub struct ModbusMappingOptions { pub struct ModbusMappingOptions {
...@@ -71,6 +79,7 @@ impl Default for ModbusMappingOptions { ...@@ -71,6 +79,7 @@ impl Default for ModbusMappingOptions {
} }
} }
/// Mapping for Modbus client
#[allow(clippy::module_name_repetitions)] #[allow(clippy::module_name_repetitions)]
pub struct ModbusMapping { pub struct ModbusMapping {
client: Client, client: Client,
......
...@@ -2,6 +2,7 @@ use std::str::FromStr; ...@@ -2,6 +2,7 @@ use std::str::FromStr;
use crate::{Error, Result}; use crate::{Error, Result};
/// A Modbus register kind.
#[derive(Eq, PartialEq, Copy, Clone, Debug)] #[derive(Eq, PartialEq, Copy, Clone, Debug)]
pub enum Kind { pub enum Kind {
Coil, Coil,
...@@ -10,6 +11,7 @@ pub enum Kind { ...@@ -10,6 +11,7 @@ pub enum Kind {
Holding, Holding,
} }
/// A Modbus register type, contains the kind and the offset.
#[derive(Debug, Clone, Copy, Eq, PartialEq)] #[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct Register { pub struct Register {
pub kind: Kind, pub kind: Kind,
......
...@@ -65,6 +65,7 @@ fn handle_client< ...@@ -65,6 +65,7 @@ fn handle_client<
Ok(()) Ok(())
} }
/// Modbus server. Requires to be run in a separate thread manually.
#[allow(clippy::module_name_repetitions)] #[allow(clippy::module_name_repetitions)]
pub struct ModbusServer<const C: usize, const D: usize, const I: usize, const H: usize> { pub struct ModbusServer<const C: usize, const D: usize, const I: usize, const H: usize> {
storage: Arc<Mutex<ModbusStorage<C, D, I, H>>>, storage: Arc<Mutex<ModbusStorage<C, D, I, H>>>,
...@@ -145,6 +146,7 @@ fn prepare_tcp_stream(stream: &TcpStream, timeout: Duration) -> Result<()> { ...@@ -145,6 +146,7 @@ fn prepare_tcp_stream(stream: &TcpStream, timeout: Duration) -> Result<()> {
Ok(()) Ok(())
} }
/// Server storage context mapping.
pub struct ModbusServerMapping<const C: usize, const D: usize, const I: usize, const H: usize> { pub struct ModbusServerMapping<const C: usize, const D: usize, const I: usize, const H: usize> {
storage: Arc<Mutex<ModbusStorage<C, D, I, H>>>, storage: Arc<Mutex<ModbusStorage<C, D, I, H>>>,
register: ModbusRegister, register: ModbusRegister,
......
//!
//! Can be used to communicate between processes on different machines or with various 3rd party
//! devices and software, such as Matlab, LabView, etc.
//!
//! [Raw UDP example](https://github.com/eva-ics/roboplc/blob/main/examples/raw-udp.rs)
use binrw::{BinRead, BinWrite}; use binrw::{BinRead, BinWrite};
use std::{ use std::{
io::Cursor, io::Cursor,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论