Compare commits

...
1 Commits
Author SHA1 Message Date
JalleliAchraf db4ae4521e first working wago blink example 2025-12-19 20:30:12 +01:00
5 changed files with 239 additions and 21 deletions

No files matched your search

+1 -1
View File
@@ -7,4 +7,4 @@ build.sh
shell.nix
node_modules/
runtime_metrics.csv
compile_metrics.csv
compile_metrics.csv
+10
View File
@@ -8,6 +8,7 @@ use crate::{
DynamicEthercatDevice, Module,
wago_modules::{
wago_750_501::{WAGO_750_501_MODULE_IDENT, WAGO_750_501_PRODUCT_ID},
wago_750_530::{WAGO_750_530_MODULE_IDENT, WAGO_750_530_PRODUCT_ID},
wago_750_652::{WAGO_750_652_MODULE_IDENT, WAGO_750_652_PRODUCT_ID},
wago_750_1506::{WAGO_750_1506_MODULE_IDENT, WAGO_750_1506_PRODUCT_ID},
},
@@ -235,6 +236,12 @@ impl Wago750_354 {
module.has_tx = true;
module.has_rx = true;
}
WAGO_750_530_PRODUCT_ID => {
print!("Wago750_354 id={} -> WAGO 750-530", ident_iom);
module.has_tx = false;
module.has_rx = true;
}
_ => println!(
"Wago-750-354 found Unknown/Unimplemented Module: {}",
ident_iom
@@ -276,6 +283,9 @@ impl Wago750_354 {
WAGO_750_652_MODULE_IDENT => {
Arc::new(RwLock::new(wago_750_652::Wago750_652::new()))
}
WAGO_750_530_MODULE_IDENT => {
Arc::new(RwLock::new(wago_750_530::Wago750_530::new()))
}
_ => {
println!(
"{} Missing Implementation for Module Identification: vendor_id: {:?}, module ident: {:?} !",
@@ -1,3 +1,4 @@
pub mod wago_750_1506;
pub mod wago_750_501;
pub mod wago_750_652;
pub mod wago_750_530;
@@ -0,0 +1,205 @@
use crate::devices::{
DynamicEthercatDevice, EthercatDevice, EthercatDeviceProcessing, EthercatDeviceUsed,
EthercatDynamicPDO, Module, NewEthercatDevice, SubDeviceProductTuple,
};
use crate::io::digital_output::{DigitalOutputDevice, DigitalOutputOutput};
#[derive(Debug, Clone)]
pub enum Wago750_530Port {
DO1,
DO2,
DO3,
DO4,
DO5,
DO6,
DO7,
DO8,
}
impl From<Wago750_530Port> for usize {
fn from(value: Wago750_530Port) -> Self {
match value {
Wago750_530Port::DO1 => 0,
Wago750_530Port::DO2 => 1,
Wago750_530Port::DO3 => 2,
Wago750_530Port::DO4 => 3,
Wago750_530Port::DO5 => 4,
Wago750_530Port::DO6 => 5,
Wago750_530Port::DO7 => 6,
Wago750_530Port::DO8 => 7,
}
}
}
#[derive(Clone, Default)]
pub struct Wago750_530RxPdo {
pub port1: bool,
pub port2: bool,
pub port3: bool,
pub port4: bool,
pub port5: bool,
pub port6: bool,
pub port7: bool,
pub port8: bool,
}
#[derive(Clone)]
pub struct Wago750_530 {
is_used: bool,
tx_bit_offset: usize,
rx_bit_offset: usize,
rxpdo: Wago750_530RxPdo,
module: Option<Module>,
}
impl DynamicEthercatDevice for Wago750_530 {}
impl EthercatDeviceUsed for Wago750_530 {
fn is_used(&self) -> bool {
self.is_used
}
fn set_used(&mut self, used: bool) {
self.is_used = used;
}
}
impl EthercatDynamicPDO for Wago750_530 {
fn get_tx_offset(&self) -> usize {
self.tx_bit_offset
}
fn get_rx_offset(&self) -> usize {
self.rx_bit_offset
}
fn set_tx_offset(&mut self, offset: usize) {
self.tx_bit_offset = offset
}
fn set_rx_offset(&mut self, offset: usize) {
self.rx_bit_offset = offset
}
}
impl DigitalOutputDevice<Wago750_530Port> for Wago750_530 {
fn set_output(&mut self, port: Wago750_530Port, value: DigitalOutputOutput) {
let v: bool = value.into();
match port {
Wago750_530Port::DO1 => self.rxpdo.port1 = v,
Wago750_530Port::DO2 => self.rxpdo.port2 = v,
Wago750_530Port::DO3 => self.rxpdo.port3 = v,
Wago750_530Port::DO4 => self.rxpdo.port4 = v,
Wago750_530Port::DO5 => self.rxpdo.port5 = v,
Wago750_530Port::DO6 => self.rxpdo.port6 = v,
Wago750_530Port::DO7 => self.rxpdo.port7 = v,
Wago750_530Port::DO8 => self.rxpdo.port8 = v,
}
}
fn get_output(&self, port: Wago750_530Port) -> DigitalOutputOutput {
DigitalOutputOutput(match port {
Wago750_530Port::DO1 => self.rxpdo.port1,
Wago750_530Port::DO2 => self.rxpdo.port2,
Wago750_530Port::DO3 => self.rxpdo.port3,
Wago750_530Port::DO4 => self.rxpdo.port4,
Wago750_530Port::DO5 => self.rxpdo.port5,
Wago750_530Port::DO6 => self.rxpdo.port6,
Wago750_530Port::DO7 => self.rxpdo.port7,
Wago750_530Port::DO8 => self.rxpdo.port8,
})
}
}
impl EthercatDevice for Wago750_530 {
fn input(
&mut self,
_input: &bitvec::prelude::BitSlice<u8, bitvec::prelude::Lsb0>,
) -> Result<(), anyhow::Error> {
Ok(())
}
fn input_len(&self) -> usize {
0
}
fn output(
&self,
output: &mut bitvec::prelude::BitSlice<u8, bitvec::prelude::Lsb0>,
) -> Result<(), anyhow::Error> {
output.set(self.rx_bit_offset + 0, self.rxpdo.port1);
output.set(self.rx_bit_offset + 1, self.rxpdo.port2);
output.set(self.rx_bit_offset + 2, self.rxpdo.port3);
output.set(self.rx_bit_offset + 3, self.rxpdo.port4);
output.set(self.rx_bit_offset + 4, self.rxpdo.port5);
output.set(self.rx_bit_offset + 5, self.rxpdo.port6);
output.set(self.rx_bit_offset + 6, self.rxpdo.port7);
output.set(self.rx_bit_offset + 7, self.rxpdo.port8);
Ok(())
}
fn output_len(&self) -> usize {
8
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
fn is_module(&self) -> bool {
true
}
fn input_checked(
&mut self,
_input: &bitvec::prelude::BitSlice<u8, bitvec::prelude::Lsb0>,
) -> Result<(), anyhow::Error> {
Ok(())
}
fn output_checked(
&self,
_output: &mut bitvec::prelude::BitSlice<u8, bitvec::prelude::Lsb0>,
) -> Result<(), anyhow::Error> {
Ok(())
}
fn get_module(&self) -> Option<Module> {
self.module.clone()
}
fn set_module(&mut self, module: Module) {
self.tx_bit_offset = module.tx_offset;
self.rx_bit_offset = module.rx_offset;
self.module = Some(module);
}
}
impl EthercatDeviceProcessing for Wago750_530 {}
impl NewEthercatDevice for Wago750_530 {
fn new() -> Self {
Self {
is_used: false,
tx_bit_offset: 0,
rx_bit_offset: 0,
rxpdo: Wago750_530RxPdo::default(),
module: None,
}
}
}
impl std::fmt::Debug for Wago750_530 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Wago750_530")
}
}
pub const WAGO_750_530_VENDOR_ID: u32 = 0x00000021;
pub const WAGO_750_530_PRODUCT_ID: u32 = 2147483778;
pub const WAGO_750_530_MODULE_IDENT: SubDeviceProductTuple =
(WAGO_750_530_VENDOR_ID, WAGO_750_530_PRODUCT_ID);
+22 -20
View File
@@ -13,12 +13,13 @@ use ethercat_hal::devices::el2004::{EL2004, EL2004_IDENTITY_A, EL2004Port};
use ethercat_hal::io::digital_output::DigitalOutput;
//Imports For Wago
/*
use ethercat_hal::devices::wago_750_354::{WAGO_750_354_IDENTITY_A, Wago750_354};
use ethercat_hal::devices::wago_modules::wago_750_530::{Wago750_530,Wago750_530Port};
use ethercat_hal::devices::{EthercatDevice, downcast_device};
use smol::lock::RwLock;
use std::sync::Arc;
*/
impl MachineNewTrait for TestMachine {
fn new<'maindevice>(params: &MachineNewParams) -> Result<Self, Error> {
@@ -41,7 +42,7 @@ impl MachineNewTrait for TestMachine {
}
};
block_on(async {
/*
// Example usage of a Wago Coupler and a 750-1506 in the first slot, where the Output Port 1,2,3,4 is used
let _wago_750_354 = get_ethercat_device::<Wago750_354>(
hardware,
@@ -60,24 +61,24 @@ impl MachineNewTrait for TestMachine {
}
coupler.init_slot_modules(_wago_750_354.1);
let dev = coupler.slot_devices.get(1).unwrap().clone().unwrap();
let wago750_1506: Arc<RwLock<Wago750_1506>> =
downcast_device::<Wago750_1506>(dev).await?;
let do1 = DigitalOutput::new(wago750_1506.clone(), Wago750_1506OutputPort::DO1);
let do2 = DigitalOutput::new(wago750_1506.clone(), Wago750_1506OutputPort::DO2);
let do3 = DigitalOutput::new(wago750_1506.clone(), Wago750_1506OutputPort::DO3);
let do4 = DigitalOutput::new(wago750_1506.clone(), Wago750_1506OutputPort::DO4);
let dev = coupler.slot_devices.get(0).unwrap().clone().unwrap();
let wago750_530: Arc<RwLock<Wago750_530>> =
downcast_device::<Wago750_530>(dev).await?;
let do1 = DigitalOutput::new(wago750_530.clone(), Wago750_530Port::DO1);
let do2 = DigitalOutput::new(wago750_530.clone(), Wago750_530Port::DO2);
let do3 = DigitalOutput::new(wago750_530.clone(), Wago750_530Port::DO3);
let do4 = DigitalOutput::new(wago750_530.clone(), Wago750_530Port::DO4);
drop(coupler);
*/
let el2004 =
get_ethercat_device::<EL2004>(hardware, params, 1, [EL2004_IDENTITY_A].to_vec())
.await?
.0;
let do1 = DigitalOutput::new(el2004.clone(), EL2004Port::DO1);
let do2 = DigitalOutput::new(el2004.clone(), EL2004Port::DO2);
let do3 = DigitalOutput::new(el2004.clone(), EL2004Port::DO3);
let do4 = DigitalOutput::new(el2004.clone(), EL2004Port::DO4);
// let el2004 =
// get_ethercat_device::<EL2004>(hardware, params, 1, [EL2004_IDENTITY_A].to_vec())
// .await?
// .0;
// let do1 = DigitalOutput::new(el2004.clone(), EL2004Port::DO1);
// let do2 = DigitalOutput::new(el2004.clone(), EL2004Port::DO2);
// let do3 = DigitalOutput::new(el2004.clone(), EL2004Port::DO3);
// let do4 = DigitalOutput::new(el2004.clone(), EL2004Port::DO4);
let (sender, receiver) = smol::channel::unbounded();
let mut my_test = Self {
@@ -88,11 +89,12 @@ impl MachineNewTrait for TestMachine {
namespace: params.namespace.clone(),
},
last_state_emit: Instant::now(),
led_on: [false; 4],
led_on: [true; 4],
main_sender: params.main_thread_channel.clone(),
douts: [do1, do2, do3, do4],
};
my_test.emit_state();
println!("TestMachine::new called, Wago750_530 created!");
Ok(my_test)
})
}