Go serial port package

3,930 views
Skip to first unread message

Aaron Jacobs

unread,
Oct 20, 2011, 9:59:14 PM10/20/11
to golang-nuts
Following an idea from Ostsol in an [earlier post] [1], I've created a package
for easily reading from and writing to serial ports in Go. You can find it
here:

https://github.com/jacobsa/go-serial

Currently it only works on OS X, but that's mostly just because I don't have
any Linux hardware to test on. I think making it work on Linux would be a
matter of updating some constants (and am happy to take pull requests). Even
so, it might be useful to somebody as-is. Let me know if you have any
feedback.

Aaron

[1]: http://groups.google.com/group/golang-nuts/browse_thread/thread/f28f5fc4f69e16ef

Tarmigan

unread,
Oct 21, 2011, 1:28:41 AM10/21/11
to Aaron Jacobs, golang-nuts
Nice!

I also made a serial port package here:
http://github.com/tarm/goserial

I think you and I arrived at about the same API! I some commits from
a couple months ago that add timeouts, parity, etc, but have not yet
needed those and so have not yet tested them and so have not yet
pushed them out to github.

The package I made uses cgo+termios.h instead of syscalls for OSX, and
it should also work on Linux, though I have not tested that either.
One thing you might think about since you're doing syscalls anyway is
using the IOSSIOSPEED ioctl which I think will let you set
non-standard baud rates on OSX.

One difference (for now) is my package also works on windows and you
can cross compile from OSX (or linux presumably) to windows, which can
be handy.

-Tarmigan

calist...@gmail.com

unread,
Feb 25, 2015, 2:52:59 AM2/25/15
to golan...@googlegroups.com
I am working on the Raspberry Pi

Do you have
1) any idea if linux sources can cross compiled on the Mac? c-go stuff cannot but I can't find any in your code
2) any demos for reading with it?

If you have even a simple reading demo - I can contribute a fuller version when I have finished...

Dave Cheney

unread,
Feb 25, 2015, 3:01:50 AM2/25/15
to golan...@googlegroups.com, calist...@gmail.com
Blatant plug, github.com/pkg/terminal. If you find some feature missing, tell me and I'll incorporate it.

drago....@gmail.com

unread,
Feb 25, 2015, 4:06:14 AM2/25/15
to golan...@googlegroups.com, calist...@gmail.com
You probably mean : github.com/pkg/term ?
Good package, but where is the timeout? Usually when reading from serial, timeout is needed.

Dave Cheney

unread,
Feb 25, 2015, 5:19:44 AM2/25/15
to golan...@googlegroups.com
Correct, it seems I don't know the name of my own package.

Timeout support would require integrating some kind of polling via select or similar.

maranatha

unread,
Jun 25, 2019, 2:11:15 AM6/25/19
to golang-nuts

I have been trying to use both Tarmigan's and Jacob's packages on Windows and Linux. For basic serial reading they both seem to work just fine. However, they both seem to break with higher baud rate and continues streaming of data. In my case I was streaming sensor data at baud rate 921600, that comes every few seconds. The expected byte size vary a bit depending on the sensor readings from the physical environment, so I have now added one extra character ("#") to be able to return the read out when this character arrives. But this does not seem to be supported in any of the available libraries that I have seen so far. Any idea how I could meet my goal?

arvinsa...@gmail.com

unread,
Sep 10, 2021, 12:36:36 PM9/10/21
to golang-nuts
Hello,

Can I ask for the  best Go package for AT commands to communicate with GSM modem. 

Arvin
Reply all
Reply to author
Forward
0 new messages