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

Feature RS485 #170

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Feature RS485 #170

wants to merge 4 commits into from

Conversation

AndreRenaud
Copy link
Contributor

This is a simple rebasing of #79 (from the https://github.com/cbrake/go-serial-1/tree/feature-rs485) branch. Sorry, I wasn't sure what the best approach was - this isn't my code, but it does compile against the latest version of go-serial.

@cbrake cbrake mentioned this pull request Dec 26, 2023
@AndreRenaud
Copy link
Contributor Author

AndreRenaud commented Dec 26, 2023

If anyone has a windows machine that can try this on, I believe this is the Windows change required for support. Unfortunately I cannot test it, so I don't know if it's a good idea for me to add it to this patch:

diff --git a/serial_windows.go b/serial_windows.go
index 2e8a4cc..ff4e272 100644
--- a/serial_windows.go
+++ b/serial_windows.go
@@ -468,6 +468,10 @@ func nativeOpen(portName string, mode *Mode) (*windowsPort, error) {
 	params.XoffLim = 512
 	params.XonChar = 17  // DC1
 	params.XoffChar = 19 // C3
+
+	if mode.RS485.Enabled {
+		params.Flags |= dcbRTSControlToggle
+	}
 	if setCommState(port.handle, params) != nil {
 		port.Close()
 		return nil, &PortError{code: InvalidSerialPort}
@@ -479,12 +483,3 @@ func nativeOpen(portName string, mode *Mode) (*windowsPort, error) {
 	}
 	return port, nil
 }
-
-// enableRS485 enables RS485 functionality of driver via an ioctl if the config says so
-func (port *windowsPort) enableRS485(config *RS485Config) error {
-	if !config.Enabled {
-		return &PortError{code: NoPlatformSupportForRS485, causedBy: nil}
-	}
-
-	return nil
-}

@AndreRenaud AndreRenaud changed the title Freature RS485 Feature RS485 Dec 26, 2023
@cbrake
Copy link
Contributor

cbrake commented Mar 22, 2024

@cmaglie is there any chance you will consider merging this?

I hear the argument that it is not cross-platform, but realistically, the only platforms that need this are embedded Linux platforms with SOCs that have hardware support for RS485 direction control in the UART.

Is there a better way this can be implemented so it would be accepted?

@cbrake
Copy link
Contributor

cbrake commented Mar 22, 2024

Here are a few snippets from a i.MX6UL datasheet that illustrates what we are talking about:

image

image

Embedded processors from TI and others have similar features.

This is the relevant kernel API:

https://docs.kernel.org/driver-api/serial/serial-rs485.html?highlight=rs485

@bieli
Copy link

bieli commented May 27, 2024

@AndreRenaud Maybe you could fix one CI/CD bug and it will be possible to merge your PR to master? I think ;-)

@AndreRenaud
Copy link
Contributor Author

@AndreRenaud Maybe you could fix one CI/CD bug and it will be possible to merge your PR to master? I think ;-)

It's not obvious to me why that CI/CD issue is related to this PR to be honest. It is complaining about Error: enumerator/enumerator.go:31:9: undefined: nativeGetDetailedPortsList. But I haven't changed the enumerator code, or added/removed/altered the nativeGetDetailedPortsList function.

Also this PR has been sitting idle for a while - I don't think it's the CI/CD issue that is preventing it getting traction.

@AndreRenaud
Copy link
Contributor Author

The workflow failure does appear to be unrelated to this PR. On MacOS/Darwin, the build requires CGO, and thus will fail unless it is built with CGO_ENABLED=1. I'm not clear why this has only just cropped up on this PR as it seems unrelated to this work. I assume it relates to the architecture of the GitHub runner perhaps changing recently from AMD64 to ARM64 for macos?

See arduino/yun-go-updater#1 for some more discussion on it.

@AndreRenaud
Copy link
Contributor Author

I've investigated the workflow issue, and have submitted a separate PR to resolve it. #186

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.

3 participants