6个版本
新版本 0.1.5 | 2024年8月11日 |
---|---|
0.1.4 | 2024年8月10日 |
0.1.3 | 2024年7月10日 |
355 在 网络编程 中
每月 204 次下载
在 roboplc-io-iec60870-5 中使用
145KB
4K SLoC
IEC 60870-5 101/104 Rust协议实现

简介
IEC 60870-5 是一套电力系统遥信、遥测和关联电信的标准,在欧洲联盟、英国和其他地区广泛使用。
该包为 IEC 60870-5 101/104 电报和常见数据类型提供了一种完全 Rust 安全、传输无关的实现。该库包含了编写自己的客户端或服务器所需的几乎完整的类型和仪器,包括 Rust 和 IEC 60870-5 格式之间的时间转换。
该包不是免费用于任何商业或生产用途的。有关更多信息,请参阅 https://github.com/roboplc/iec60870-5/blob/main/LICENSE.md。
IEC 60870-5 Rust 库是 RoboPLC 项目的一部分。
MSRV: 1.68.0
示例
创建一个简单的数据传输启动 IEC 60870-5 104 电报
use iec60870_5::telegram104::Telegram104;
let telegram = Telegram104::new_start_dt();
// The telegram is ready to be sent in any way
let mut buffer = std::io::Cursor::new(Vec::new());
telegram.write(&mut buffer).unwrap();
创建一个 IEC 60870-5 104 命令电报
// A timestamp crate
use bma_ts::Timestamp;
use iec60870_5::types::datatype::{C_RC_TA_1, DataType, QU, RCO, RCS, SelectExecute};
use iec60870_5::types::COT;
use iec60870_5::telegram104::{ChatSequenceCounter, Telegram104, Telegram104_I};
// To communicate with the server, the client must have a chat sequence counter
let chat_sequence_counter = ChatSequenceCounter::new();
let mut telegram_i: Telegram104_I = Telegram104_I::new(
DataType::C_RC_TA_1, // Data type, regulating step command with CP56Time2a time tag
COT::Act, // Cause of transmission: activation
15 // ASDU address
);
telegram_i.append_iou(
11, // Information object address,
C_RC_TA_1 { // Regulating step command with CP56Time2a time tag
rco: RCO {
rcs: RCS::Increment,
se: SelectExecute::Execute,
qu: QU::Persistent,
},
time: Timestamp::now().try_into().unwrap(),
},
);
let mut telegram: Telegram104 = telegram_i.into();
telegram.chat_sequence_apply_outgoing(&chat_sequence_counter);
// The telegram is ready to be sent in any way
let mut buffer = std::io::Cursor::new(Vec::new());
telegram.write(&mut buffer).unwrap();
读取一个 IEC 60870-5 104 电报
// A timestamp crate
use bma_ts::Timestamp;
use iec60870_5::telegram104::{ChatSequenceCounter, Telegram104};
use iec60870_5::types::datatype::{DataType, M_EP_TA_1};
// For strict servers, the client must have a chat sequence counter
let chat_sequence_counter = ChatSequenceCounter::new();
// Consider that the buffer contains a valid telegram
let mut buffer = std::io::Cursor::new(Vec::new());
let telegram = Telegram104::read(&mut buffer).unwrap();
telegram.chat_sequence_validate_incoming(&chat_sequence_counter).unwrap();
if let Telegram104::I(i) = telegram {
// This is an I-frame
if i.data_type() == DataType::M_EP_TA_1 {
// This is a M_EP_TA_1 telegram
for iou in i.iou() {
// Decode MP_EP_TA_1 information object value from the raw IOU buffer
let val: M_EP_TA_1 = iou.value().into();
// Convert the time tag to a timestamp
let dt = Timestamp::try_from(val.time).unwrap();
// Output the event state and the timestamp
dbg!(val.sep.es, dt);
}
}
}
故障排除
-
由于 IEC 60870-5 是一个复杂的标准,第三方硬件/软件供应商通常不会完全实现它,一些功能可能需要额外的开发/解决方案。
-
该库已与 Beckhoff TwinCAT 3 TF6500 以及欧盟电网中使用的某些嵌入式实现完全测试。
-
最常见的问题是,大多数IEC 60870-5 104服务器需要保持活动帧。这可以通过使用IEC 60870-5 104 S帧或直接测试U帧来实现。
use iec60870_5::telegram104::Telegram104;
let telegram = Telegram104::new_test();
// Write the telegram to the target
关于作者
波希米亚自动化 / Altertech 是一家拥有15年以上企业自动化和工业物联网经验的公司集团。我们的系统包括发电厂、工厂和城市基础设施。其中最大的系统拥有超过100万传感器和控制设备,而且这个数字每天都在不断攀升。
依赖关系
~5–7MB
~129K SLoC