goburrow / serial Goto Github PK
View Code? Open in Web Editor NEWGo (golang) serial library for modbus
Home Page: https://github.com/goburrow/modbus
License: MIT License
Go (golang) serial library for modbus
Home Page: https://github.com/goburrow/modbus
License: MIT License
github.com/goburrow/modbus
depends on this library, and when I try to run:
GOOS=windows GOARCH=amd64 go build -o hello.exe main.go
It says:
# github.com/goburrow/serial
/path/to/gopath/src/github.com/goburrow/serial/serial.go:43: undefined: New
So it's currently not possible to cross compile? (Linux host, Windows binary)
And a side question that doesn't really deserve another issue -- under Linux we can use /dev/ttyS0
as the address, what if in Windows? Just use COM1
?
Thanks a lot for your work!
Hi,
can we use the following uart application code if we are not using rs485 ? we are only using a usb drive and want to test this application using uart.
https://github.com/goburrow/serial/blob/v0.1.0/example/example.go
please let me know for any suggestions. Thanks in advance.
Are there any plans to support the RS485-specific ioctl's that Linux provides?
(See, for example, https://github.com/jacobsa/go-serial/blob/master/serial/open_linux.go#L172-L176)
My use case is to use goburrow/modbus library on a BeagleBone with a MikroElektronika RS485 transceiver. My understanding at this point is that I will need to control the direction of the transceiver with a GPIO pin and that the driver will do that for me, provided I enable RS485 support with an ioctl() call and I provide the appropriate device tree overlay)
on NetBSD (AMD64 at least, but from experience, this is architecture independend) Versions 9.x and later, the code using this compiles only when usind the openbsd implementation. I really don not have a clue if and when the os-specific files are pulled in, but currently the generic code is used and it fails.
I use vspd create COM1 and COM2 on Win10,
S -> like this:
func main() {
s, err := serial.Open(&serial.Config{
Address: "COM1",
BaudRate: 9600,
DataBits: 8,
StopBits: 1,
Parity: "N",
})
if err != nil {
log.Fatal(err)
}
//
defer s.Close()
buf := make([]byte, 128)
log.Println("begin")
n, err := s.Read(buf)
if err != nil {
log.Fatal(err)
}
log.Println("end")
log.Println(string(buf[:n]))
}
C-> like this:
func main() {
s, err := serial.Open(&serial.Config{
Address: "COM2",
BaudRate: 9600,
DataBits: 8,
StopBits: 1,
Parity: "N",
})
if err != nil {
log.Fatal(err)
}
//
n, err := s.Write([]byte("123"))
if err != nil {
log.Fatal(err)
}
//
log.Printf("write: %d\n", n)
//
defer s.Close()
buf := make([]byte, 128)
time.Sleep(1000 * time.Millisecond)
n, err = s.Read(buf)
if err != nil {
log.Fatal(err)
}
log.Println(string(buf[:n]))
}
first I run S then C I found S read nothing, I don't no why? can you help me?
In short: Config.Timeout = 0, Linux does not time out, Windows times out at 0.5 seconds in my case.
When Config.Timeout is left as default (0), the behavior on Windows and Linux is different. On Linux, it is infinite (implemented with null *timeval for select). But on Windows it skips SetCommTimeouts which according to https://msdn.microsoft.com/en-us/library/aa450505.aspx:
An application must always set communication timeouts using the COMMTIMEOUTS structure each time it opens a communication port.
If this structure is not configured, the port uses default timeouts supplied by the driver, or timeouts from a previous communication application.
By assuming specific timeout settings when the settings are actually different, an application can have read/write operations that never complete or complete too often.
In my test, a read with Config.Timeout = 0 on Windows returns after a timeout of 0.5 seconds. It should not timeout.
Since golang.org/x/sys/unix
was being updated regularly, the following error occurs when compiling under macOS:
zsyscall_darwin.go:16:27: undefined: unix.SYS_IOCTL
This is due to golang/sys@6fcdbc0 removing all the SYS_*
constants, the reason being that direct syscalls under Darwin are no longer supported.
Is there a fix for this?
EDIT: The temporary workaround for this problem is adding this line to the project's go.mod
to use an older version of golang.org/x/sys/unix
:
replace golang.org/x/sys => golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6
But this is not a long-term solution.
Hi, when I set RS485Config true on Mac, I get this error immediately: "SYS_IOCTL (RS485): inappropriate ioctl for device", does it support rs485 on Mac? Thanks.
Hello!
I use github.com/goburrow/modbus in my project and when I try to compile project to FreeBSD -
# github.com/goburrow/serial
../github.com/goburrow/serial/serial.go:43: undefined: New
Can you help me please?
Thank you for help!
$ go get -u -v github.com/goburrow/modbus
github.com/goburrow/modbus (download)
github.com/goburrow/serial (download)
github.com/goburrow/serial
..\github.com\goburrow\serial\serial_posix.go:13: undefined: syscall.Termios
..\github.com\goburrow\serial\serial_windows.go:8: port redeclared in this block
previous declaration at ..\github.com\goburrow\serial\serial_posix.go:11
..\github.com\goburrow\serial\serial_windows.go:13: New redeclared in this block
previous declaration at ..\github.com\goburrow\serial\serial_posix.go:19
..\github.com\goburrow\serial\serial_windows.go:20: (*port).Open redeclared in t his block
previous declaration at ..\github.com\goburrow\serial\serial_posix.go:24
..\github.com\goburrow\serial\serial_windows.go:45: (*port).Close redeclared in this block
previous declaration at ..\github.com\goburrow\serial\serial_posix.go:48
..\github.com\goburrow\serial\serial_windows.go:56: (*port).Read redeclared in t his block
previous declaration at ..\github.com\goburrow\serial\serial_posix.go:61
..\github.com\goburrow\serial\serial_windows.go:70: (*port).Write redeclared in this block
previous declaration at ..\github.com\goburrow\serial\serial_posix.go:92
This happens when compiling with goreleaser for darwin_386
:
⨯ release failed after 76.54s error=failed to build for darwin_386: # github.com/grid-x/serial
../go/pkg/mod/github.com/grid-x/[email protected]/serial_posix.go:168:12: cannot assign uint64 to flag (type uint32) in multiple assignment
../go/pkg/mod/github.com/grid-x/[email protected]/serial_posix.go:176:13: cannot use flag (type uint32) as type uint64 in argument to cfSetIspeed
../go/pkg/mod/github.com/grid-x/[email protected]/serial_posix.go:178:13: cannot use flag (type uint32) as type uint64 in argument to cfSetOspeed
../go/pkg/mod/github.com/grid-x/[email protected]/serial_posix.go:184:12: cannot assign uint64 to flag (type uint32) in multiple assignment
../go/pkg/mod/github.com/grid-x/[email protected]/termios_darwin.go:8:17: cannot use speed (type uint64) as type uint32 in assignment
../go/pkg/mod/github.com/grid-x/[email protected]/termios_darwin.go:12:17: cannot use speed (type uint64) as type uint32 in assignment
Hi, thank you for useful library!
I've found an issue. The select syscall has a limitations:
select() can monitor only file descriptors numbers that
are less than FD_SETSIZE (1024)—an unreasonably low limit for
many modern applications—and this limitation will not change.
All modern applications should instead use poll(2) or epoll(7),
which do not suffer this limitation.
https://man7.org/linux/man-pages/man2/select.2.html#DESCRIPTION
In practice it looks like, that fd is ready to read, but reads zero bytes.
I've made a PR to use poll (epoll is linux only syscall).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.