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 194 package(s) ΒΆ

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