Skip to content

Wago minimal dio seperate#1284

Open
khalilbendhief wants to merge 9 commits intomasterfrom
wago-minimal-DIO-seperate
Open

Wago minimal dio seperate#1284
khalilbendhief wants to merge 9 commits intomasterfrom
wago-minimal-DIO-seperate

Conversation

@khalilbendhief
Copy link
Copy Markdown
Collaborator

Implements the wago_dio_separate machine, combining a WAGO 750-430
(8-channel DI) and 750-530 (8-channel DO) under a single EtherCAT
machine abstraction.

@TheBest6337 TheBest6337 requested a review from kraemr April 3, 2026 11:02
@TheBest6337
Copy link
Copy Markdown
Member

@khalilbendhief please explain why you needed to change the Bus Coupler code and whats different now. Please also fix the rust formating error. @kraemr please take a look.

Copy link
Copy Markdown
Collaborator

@kraemr kraemr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix Formatting Error, and Electron errors and remove your coupler logic changes for the Wago 750-354 unless they are absolutely necessary

Comment on lines 112 to 210
fn set_module(&mut self, module: Module) {
self.slots[self.module_count] = Some(module.clone());
self.module_count += 1;
}
}

impl EthercatDeviceUsed for Wago750_354 {
fn is_used(&self) -> bool {
self.is_used
}

fn set_used(&mut self, used: bool) {
self.is_used = used;
}
}

impl EthercatDeviceProcessing for Wago750_354 {}

impl NewEthercatDevice for Wago750_354 {
fn new() -> Self {
Self {
is_used: false,
slots: [const { None }; 64],
slot_devices: [const { None }; 64],
module_count: 0,
dev_count: 0,
tx_size: 0,
rx_size: 0,
rx_pdo_mappings: vec![],
tx_pdo_mappings: vec![],
}
}
}

impl std::fmt::Debug for Wago750_354 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Wago_750_354")
}
}

impl Wago750_354 {
pub fn calculate_module_index(pdo_mapping: u32, is_tx: bool) -> u32 {
let start_index = match is_tx {
true => 0x6000,
false => 0x7000,
};
let pdo_index = (pdo_mapping & 0xFFFF0000) >> 16;

if pdo_index < start_index {
// Treat as coupler/module 0
return 0;
}

let index_in_hex = pdo_index - start_index;

if index_in_hex < 16 {
0
} else {
index_in_hex / 16
}
}

pub async fn get_pdo_offsets<'a>(
&mut self,
device: &EthercrabSubDevicePreoperational<'a>,
get_tx: bool,
) -> Result<(), Error> {
let mut vec: Vec<ModulePdoMapping> = vec![];
let mut bit_offset = 0;
let start_subindex = 0x2;

let index = match get_tx {
true => (TX_MAPPING_INDEX.0, TX_MAPPING_INDEX.1),
false => (RX_MAPPING_INDEX.0, RX_MAPPING_INDEX.1),
};

let count_mappings = device.sdo_read::<u8>(index.0, index.1).await?;
let pdo_index = device.sdo_read::<u16>(index.0, 1).await?;
let pdo_map_count = device.sdo_read::<u8>(pdo_index, 0).await?;

for i in 0..pdo_map_count {
let pdo_mapping: u32 = device.sdo_read(pdo_index, 1 + i).await?;
let bit_length = (pdo_mapping & 0xFF) as u8;
bit_offset += bit_length as usize;
}

for i in start_subindex..=count_mappings {
let pdo_index = device.sdo_read(index.0, i).await?;
let pdo_map_count = device.sdo_read::<u8>(pdo_index, 0).await?;
for j in 0..pdo_map_count {
let pdo_mapping: u32 = device.sdo_read(pdo_index, 1 + j).await?;
let pdo_index_hi = (pdo_mapping & 0xFFFF0000) >> 16;
let bit_length = (pdo_mapping & 0xFF) as usize;

// Preserve the original coupler assignment order. Padding/alignment
// entries still consume bits, but must not be assigned to a module.
let start_index = if get_tx { 0x6000 } else { 0x7000 };
if pdo_index_hi >= start_index {
let module_i = Wago750_354::calculate_module_index(pdo_mapping, get_tx);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the logic in here ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khalilbendhief maybe just cherry-pick your new machine integration on top of current master since the coupler code is functional now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants