-
Notifications
You must be signed in to change notification settings - Fork 12
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
add rs485 support #29
Conversation
Thanks for the PR! I think I like the approach of making it part of the I prefer to avoid the dependency on the Ideally, we would also figure out how to do this on Windows. If not, we should probably put this under the |
I've been reading a bit more here: https://www.kernel.org/doc/html/v5.16/driver-api/serial/serial-rs485.html I think the only thing we need to implement now is the /edit: Actually, this one would be very nice to expose too: Maybe |
Its confusing as the PCIe card I am using only supports rs485 but without setting the flag to enable_rs485 it doesn't work. I've embedded the rs485 crate, as its pretty minimal, I am would end up rewriting it all anyway. Modified it to work with libc crate and the latest bitflags crate. |
yaaay :p
Sorry for the delay in review. I need to read up a bit to ensure we model this correctly. Sadly so far I can't find anything on how this is done on other platforms :( |
I've been working on an API that I think make sense. Sorry for the radio silence. This What I'm leaning towards now is an API to specifically configure RS-485 and RS-422, where things like the RTS signal state and bus termination is only available in RS-485 mode. I'm also limiting the exposed settings, since even the Linux kernel actually "sanitizes" the options silently. For example, if you set Also, the But one of them interprets But I intend to solve most of this with warnings in the documentation rather than hacks to detect device quirks. |
No worries about the radio silence, and thanks for continuing to work on it. Its a complicated problem, but your approach sounds good. Looking forward to seeing it. :) |
c7ce4d5
to
a199b30
Compare
8b7dbf8
to
c39b738
Compare
I've pushed some commits to adjust the API. For usage, you can check the I will still go over the changes again later, when I've had some time to let it sink :) |
This is nice, but also a lot of people simply emulate this stuff throygh the already available R232 features. Its nice to have, but maybe a comment about bitbanging it yourself over regular serial is also possible if stuff doesn't work. |
I confirmed this works for my setup today and the ergonomics seem nice to me. I noticed a couple of minor mistakes ill fix now. @DanielJoyce I'm not sure how you could emulate the switching of ioctls with bitbanging. Perhaps you could write the comment as you suggested with an example? |
src/serial_port.rs
Outdated
/// Please read all the warnings in the [`rs4xx`] module carefully. | ||
#[cfg(any(doc, all(feature = "rs4xx", target_os = "linux")))] | ||
#[cfg_attr(feature = "doc-cfg", doc(cfg(all(feature = "rs4xx", target_os = "linux"))))] | ||
pub fn set_rs4xx_mode(&self, mode: &rs4xx::TransceiverMode) -> std::io::Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be mode: impl Into<rs4xx::TransceiverMode>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could. Only downside is that it means copying the argument instead of passing it by reference. But I'm not too worries about that. So lets do that :)
👍 I'll wait for your fixes before merging.
I think they mean that you can switch the (Technically, |
RS485 is a two wire protocol as specd. Extra wires are not supported by everyone. What I mean by bit banging is if your rs485 port is exposing a dtr pin and Linux doing the twiddling for you isn't working, as long as Linux exposes that DTR you can twiddle it yourself |
Like how currently the crate exposes the pins for rs232 and we can set them high / low manually. |
whoops sorry I thought I had replied. Ready to merge @de-vri-es :) |
No problem! Released as |
Initial attempt with the
rs485
crate and adding the struct to the settings.I have tested with an rs485 board and it works. It will currently fail with a non rs485 device so need to add some checks to the
get_from_file
fn