top

Goserial is a simple go package to allow you to read and write from the serial port as a stream of bytes.

It aims to have the same API on all platforms, including windows. As an added bonus, the windows package does not use cgo, so you can cross compile for windows from another platform. Unfortunately goinstall does not currently let you cross compile so you will have to do it manually:

GOOS=windows make clean install

Currently there is very little in the way of configurability. You can set the baud rate. Then you can Read(), Write(), or Close() the connection. Read() will block until at least one byte is returned. Write is the same. There is currently no exposed way to set the timeouts, though patches are welcome.

Currently all ports are opened with 8 data bits, 1 stop bit, no parity, no hardware flow control, and no software flow control. This works fine for many real devices and many faux serial devices including usb-to-serial converters and bluetooth serial ports.

You may Read() and Write() simulantiously on the same connection (from different goroutines).

Example usage:

package main

import (
      "github.com/tarm/serial"
      "log"
)

func main() {
      c := &serial.Config{Name: "COM5", Baud: 115200}
      s, err := serial.OpenPort(c)
      if err != nil {
              log.Fatal(err)
      }

      n, err := s.Write([]byte("test"))
      if err != nil {
              log.Fatal(err)
      }

      buf := make([]byte, 128)
      n, err = s.Read(buf)
      if err != nil {
              log.Fatal(err)
      }
      log.Print("%q", buf[:n])
}

Imported by 185 package(s) ΒΆ

  1. github.com/0bscur3/Arduino-LedStripe-IR/Golang/serial
  2. github.com/1995parham/AUT-CoDesign-Go/main
  3. github.com/1lann/sweep
  4. github.com/AdamSLevy/modbus
  5. github.com/Arteev/gold
  6. github.com/BlueMasters/asnl-go/message
  7. github.com/BlueMasters/asnl-go/test-arduino
  8. github.com/BulletTime/RN2483
  9. github.com/DexterLB/ir_remote
  10. github.com/FarmRadioHangar/fessboxconfig/device
  11. github.com/Grayda/go-phone
  12. github.com/IndoorPosSquad/dwm1000_driver
  13. github.com/JonathanLogan/smspager
  14. github.com/LDLN/serial-server
  15. github.com/Omegaice/FridgeController/fridgecontroller-canakit
  16. github.com/Omegaice/go-xmodem
  17. github.com/RoanBrand/SerialToTCPBridgeProtocol/protocol
  18. github.com/RoanBrand/SerialToTCPBridgeSimple
  19. github.com/SebastiaanKlippert/smartmeter
  20. github.com/SimulatedSimian/flotilla-go/flotilla
  21. github.com/SimulatedSimian/gamepadremote
  22. github.com/SimulatedSimian/gocmdutil/serialmon
  23. github.com/SlugCam/SCmesh
  24. github.com/SlugCam/SCnet
  25. github.com/Velovix/datagolf
  26. github.com/aadit/stratux/main
  27. github.com/abrander/gometer/kamstrup
  28. github.com/acd/infinitive
  29. github.com/acmacalister/edison
  30. github.com/alexgear/sms/modem
  31. github.com/apache/mynewt-newtmgr/nmxact/nmserial
  32. github.com/araobp/spielzeug/rpi/parts
  33. github.com/arcturusbiocloud/horus-v2
  34. github.com/argandas/go-firmata
  35. github.com/argandas/goduino
  36. github.com/arianitu/prison-break
  37. github.com/arteev/gold
  38. github.com/ashmckenzie/rpi-moteino-collector-go/app
  39. github.com/asig/build_watcher
  40. github.com/averrin/ravenor
  41. github.com/avesanen/buildlight
  42. github.com/b00lduck/raspberry-datalogger-serial
  43. github.com/bettercap/bettercap/modules
  44. github.com/binaryplease/led_strip_control
  45. github.com/binzume/avr-lis3dh
  46. github.com/binzume/gob3m/examples
  47. github.com/biribiribiri/estim
  48. github.com/brandonagr/gom2xlogger
  49. github.com/brianmay27/GOtLockedOut
  50. github.com/britannic/lgtv-remote
  51. github.com/britannic/lgtv-remote/internal/lgtv
  52. github.com/brockwood/govantage/vantagepro
  53. github.com/canghai908/gosms/modem
  54. github.com/caseymrm/flipdots/panel
  55. github.com/cesanta/gopro
  56. github.com/cescoferraro/power/lights
  57. github.com/cquinn/doombot
  58. github.com/cubicdaiya/fuji/device
  59. github.com/dabamos/openadms-legacy/module/serial/communication
  60. github.com/danhigham/canbustriple
  61. github.com/danhigham/canbustriple/test
  62. github.com/deadsy/slamx/lidar
  63. github.com/deepakkamesh/cm11
  64. github.com/deepakkamesh/sonny/controllercli/simplecli
  65. github.com/deepakkamesh/sonny/devices
  66. github.com/deepakkamesh/test
  67. github.com/deepakkamesh/viki/testers
  68. github.com/dfjones/solar/solar-client
  69. github.com/dgnorton/norobo/hayes
  70. github.com/dh1tw/remoteRotator/rotator/yaesu
  71. github.com/die-net/led-controller
  72. github.com/dogshoes/pokemon-snap-station-card-reader
  73. github.com/dustin/powerlab
  74. github.com/eastmane/goLLAP
  75. github.com/ebusto/xbee/examples
  76. github.com/efarres/GoIPbus
  77. github.com/ekanna/firmata
  78. github.com/ekoeppen/embello/tools/folie
  79. github.com/elopio/gobot/platforms/firmata/client/examples
  80. github.com/evilsocket/bettercap-ng/modules
  81. github.com/fasmide/joychair
  82. github.com/fasmide/joychair/cli
  83. github.com/fstanis/epaper
  84. github.com/galberti/dstarx/dv4mini
  85. github.com/gearmover/go-9df
  86. github.com/geoffholden/gowx/cmd
  87. github.com/gnur/prometheus-p1-exporter
  88. github.com/grayzone/devicemonitor/comm
  89. github.com/haxpax/gosms/modem
  90. github.com/htdvisser/rn2483
  91. github.com/hybridgroup/gobot/platforms/megapi
  92. github.com/ianmcmahon/stratux/main
  93. github.com/immesys/bw2-contrib/lib/tosserial
  94. github.com/ishuah/bifrost
  95. github.com/ivahaev/gosms/modem
  96. github.com/jBugman/go-xbee/demo
  97. github.com/jamesnetherton/go-telescope
  98. github.com/jeelabs/embello/tools/folie
  99. github.com/joernweissenborn/serialreactor
  100. github.com/johanhenriksson/ledriver/led
  101. github.com/jssvgs/oshiwasp
  102. github.com/kapitanov/go-cube
  103. github.com/kapitanov/go-firmata
  104. github.com/kevinjos/openbci-driver
  105. github.com/kf8a/fishy
  106. github.com/kf8a/li820
  107. github.com/kf8a/ohaus
  108. github.com/kf8a/qclreader
  109. github.com/kgbu/fuji/device
  110. github.com/koyachi/go-thermalprinter
  111. github.com/kpoppel/Continuous-Meter-Reader/go
  112. github.com/ktt-ol/go-insta
  113. github.com/lanyitin/asrms/src/web
  114. github.com/ldln/serial-server
  115. github.com/lindsaymarkward/sphere-go-led-controller/util
  116. github.com/linklayer/go-cantact
  117. github.com/lukescott/gozwave
  118. github.com/madhurjain/audio-fft/utility
  119. github.com/majest/go-serial-server
  120. github.com/martinhansdk/Continuous-Meter-Reader/go
  121. github.com/mdempsky/castle1724/upb
  122. github.com/mezzato/fuji/device
  123. github.com/mhe/dsmr4p1/examples
  124. github.com/mhe/p1mqtt
  125. github.com/mikehamer/ati-torque-force-logger
  126. github.com/murdinc/ELMFlash/j3
  127. github.com/murdinc/go-firmata
  128. github.com/mururu/fuji/device
  129. github.com/neilisaac/IRBridge
  130. github.com/npotts/arduino/WxShield2/wxproxy
  131. github.com/npotts/arduino/WxStation
  132. github.com/okushchenko/sms/modem
  133. github.com/ottonello/Arduino-RGB
  134. github.com/padster/eego
  135. github.com/paocalvi/soip
  136. github.com/pd0mz/go-dv/mmdvm
  137. github.com/peterjliu/goserial
  138. github.com/pocke/BDM4065UC11
  139. github.com/pplanel/gosms/modem
  140. github.com/pr8kerl/gosms/modem
  141. github.com/pr8kerl/smplsms
  142. github.com/qmsk/e2/hetec-dcp
  143. github.com/quchunguang/homemake/lightrelay
  144. github.com/quchunguang/homemake/logserial
  145. github.com/rakyll/firmata
  146. github.com/reactor10/hivemind/hivetool
  147. github.com/redkite1/zigbee-gw/src/xbee
  148. github.com/rustyoz/muesli
  149. github.com/rzetterberg/elmobd
  150. github.com/shiguredo/fuji/device
  151. github.com/shirou/fuji/device
  152. github.com/simulatedsimian/flotilla-go/flotilla
  153. github.com/simulatedsimian/flotilla/flotilla
  154. github.com/simulatedsimian/gamepadremote
  155. github.com/simulatedsimian/gocmdutil/serialmon
  156. github.com/simulatedsimian/yx5300
  157. github.com/spagettikod/gotracer
  158. github.com/stampzilla/gozwave/serialapi
  159. github.com/stampzilla/gozwave/serialrecorder
  160. github.com/suapapa/tools/hcc
  161. github.com/tejainece/modbus
  162. github.com/tejainece/modbus/comm
  163. github.com/tochka/smssender
  164. github.com/tomoya0x00/go-im920
  165. github.com/trestletech/gobd/examples
  166. github.com/u8slvn/raspigosms/gsm
  167. github.com/velovix/datagolf
  168. github.com/vgardner/jenkins-led-lights
  169. github.com/vikstrous/go-blinkytape
  170. github.com/wI2L/blinkygo
  171. github.com/waltzofpearls/hermes/raspberrypi
  172. github.com/warthog618/modem/serial
  173. github.com/yazver/gsmmodem
  174. github.com/ymotongpoo/irmagician
  175. github.com/ympons/gobot/platforms/megapi
  176. github.com/yne717/amp/serial
  177. github.com/yurigorokhov/go-megapi
  178. github.com/zankich/hal/firmata
  179. github.com/zdebeer99/zhome/pkg/hardware/zioboard
  180. github.com/zpeters/wmc
  181. gobot.io/x/gobot/platforms/firmata
  182. gobot.io/x/gobot/platforms/mavlink
  183. gobot.io/x/gobot/platforms/megapi
  184. gobot.io/x/gobot/platforms/neurosky
  185. gobot.io/x/gobot/platforms/sphero