Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reading/writing f32, f64 and bool #167

Merged
merged 4 commits into from
Feb 14, 2024

Conversation

jamwaffles
Copy link
Collaborator

Note that f64s cannot currently be passed to sdo_write as it only supports 4 byte expedited transfers currently.

Note that `f64`s cannot currently be passed to `sdo_write` as it only
supports 4 byte expedited transfers currently.
@jamwaffles jamwaffles changed the title Support reading/writing f32 and f64 Support reading/writing f32, f64 and bool Feb 13, 2024
@jubeor-gp
Copy link

jubeor-gp commented Feb 13, 2024

Caution!! This has been tested with the revision 73440a6

ethercrab = { git = "https://github.com/ethercrab-rs/ethercrab.git", rev = "73440a66eca1509e6c8dd8da1aa7b4966aebc6e1", features = [
    "serde",
] }

Testing reading and writing bool data:

let avg_mode_original = slave.sdo_read::<bool>(0x8000, 4).await?;
slave.sdo_write(0x8000, 4, false).await?;
let avg_mode_new = slave.sdo_read::<bool>(0x8000, 4).await?;
log::info!(
    "Avg Mode. Original {:?}, Updated {:?}",
    avg_mode_original,
    avg_mode_new
);

@jubeor-gp
Copy link

Testing f32

                    let nominal_original = slave.sdo_read::<f32>(0x8000, 0x23).await?;
                    slave.sdo_write(0x8000, 0x23, 4.0f32).await?;
                    let nominal_new = slave.sdo_read::<f32>(0x8000, 0x23).await?;
                    log::info!(
                        "Nominal. Original {:?}, Updated {:?}",
                        nominal_original,
                        nominal_new
                    );

Output:
[2024-02-13T23:27:05Z INFO testing::ethercat_master] Nominal. Original 2.0, Updated 4.0

@jubeor-gp
Copy link

Warning: This test belongs to the revision {25596d5} where bool is translated as false 0x00 true 0xff

ethercrab = { git = "https://github.com/ethercrab-rs/ethercrab.git", rev = "25596d55801b295d6a0afc20cd73532415e8fd0e", features = [
    "serde",
] }

Testing code:

                    let avg_mode_original = slave.sdo_read::<bool>(0x8000, 4).await?;
                    slave.sdo_write(0x8000, 4, false).await?;
                    let avg_mode_new = slave.sdo_read::<bool>(0x8000, 4).await?;
                    log::info!(
                        "Avg Mode. Original {:?}, Updated {:?}",
                        avg_mode_original,
                        avg_mode_new
                    );

Output:
[2024-02-13T23:33:30Z INFO testing::ethercat_master] Avg Mode. Original true, Updated false

@jamwaffles jamwaffles merged commit a3df8bc into 0.3-backports Feb 14, 2024
7 checks passed
@jamwaffles jamwaffles deleted the support-f32-f64-0.3 branch February 14, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants