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 191 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/canghai908/gosms/modem
  57. github.com/caseymrm/flipdots/panel
  58. github.com/cesanta/gopro
  59. github.com/cescoferraro/power/lights
  60. github.com/cquinn/doombot
  61. github.com/cubicdaiya/fuji/device
  62. github.com/dabamos/openadms-legacy/module/serial/communication
  63. github.com/danhigham/canbustriple
  64. github.com/danhigham/canbustriple/test
  65. github.com/deadsy/slamx/lidar
  66. github.com/deepakkamesh/cm11
  67. github.com/deepakkamesh/sonny/controllercli/simplecli
  68. github.com/deepakkamesh/sonny/devices
  69. github.com/deepakkamesh/test
  70. github.com/deepakkamesh/viki/testers
  71. github.com/dfjones/solar/solar-client
  72. github.com/dgnorton/norobo/hayes
  73. github.com/dh1tw/remoteRotator/rotator/yaesu
  74. github.com/die-net/led-controller
  75. github.com/dogshoes/pokemon-snap-station-card-reader
  76. github.com/dustin/powerlab
  77. github.com/eastmane/goLLAP
  78. github.com/ebusto/xbee/examples
  79. github.com/efarres/GoIPbus
  80. github.com/ekanna/firmata
  81. github.com/ekoeppen/embello/tools/folie
  82. github.com/elopio/gobot/platforms/firmata/client/examples
  83. github.com/evilsocket/bettercap-ng/modules
  84. github.com/fasmide/joychair
  85. github.com/fasmide/joychair/cli
  86. github.com/fiam/msp-tool
  87. github.com/fstanis/epaper
  88. github.com/galberti/dstarx/dv4mini
  89. github.com/gearmover/go-9df
  90. github.com/geoffholden/gowx/cmd
  91. github.com/gnur/prometheus-p1-exporter
  92. github.com/grayzone/devicemonitor/comm
  93. github.com/gwwfps/volume-knob
  94. github.com/haxpax/gosms/modem
  95. github.com/htdvisser/rn2483
  96. github.com/hybridgroup/gobot/platforms/megapi
  97. github.com/ianmcmahon/stratux/main
  98. github.com/immesys/bw2-contrib/lib/tosserial
  99. github.com/ishuah/bifrost
  100. github.com/ivahaev/gosms/modem
  101. github.com/jBugman/go-xbee/demo
  102. github.com/jamesnetherton/go-telescope
  103. github.com/jeelabs/embello/tools/folie
  104. github.com/joernweissenborn/serialreactor
  105. github.com/johanhenriksson/ledriver/led
  106. github.com/jssvgs/oshiwasp
  107. github.com/kapitanov/go-cube
  108. github.com/kapitanov/go-firmata
  109. github.com/kevinjos/openbci-driver
  110. github.com/kf8a/fishy
  111. github.com/kf8a/li820
  112. github.com/kf8a/ohaus
  113. github.com/kf8a/qclreader
  114. github.com/kgbu/fuji/device
  115. github.com/koyachi/go-thermalprinter
  116. github.com/kpoppel/Continuous-Meter-Reader/go
  117. github.com/ktt-ol/go-insta
  118. github.com/lanyitin/asrms/src/web
  119. github.com/ldln/serial-server
  120. github.com/lindsaymarkward/sphere-go-led-controller/util
  121. github.com/linklayer/go-cantact
  122. github.com/lukescott/gozwave
  123. github.com/madhurjain/audio-fft/utility
  124. github.com/majest/go-serial-server
  125. github.com/martinhansdk/Continuous-Meter-Reader/go
  126. github.com/mdempsky/castle1724/upb
  127. github.com/mezzato/fuji/device
  128. github.com/mhe/dsmr4p1/examples
  129. github.com/mhe/p1mqtt
  130. github.com/mikehamer/ati-torque-force-logger
  131. github.com/murdinc/ELMFlash/j3
  132. github.com/murdinc/go-firmata
  133. github.com/mururu/fuji/device
  134. github.com/neilisaac/IRBridge
  135. github.com/npotts/arduino/WxShield2/wxproxy
  136. github.com/npotts/arduino/WxStation
  137. github.com/okushchenko/sms/modem
  138. github.com/ottonello/Arduino-RGB
  139. github.com/padster/eego
  140. github.com/paocalvi/soip
  141. github.com/pd0mz/go-dv/mmdvm
  142. github.com/peterjliu/goserial
  143. github.com/pocke/BDM4065UC11
  144. github.com/pplanel/gosms/modem
  145. github.com/pr8kerl/gosms/modem
  146. github.com/pr8kerl/smplsms
  147. github.com/qingtao/kongqi
  148. github.com/qmsk/e2/hetec-dcp
  149. github.com/quchunguang/homemake/lightrelay
  150. github.com/quchunguang/homemake/logserial
  151. github.com/rakyll/firmata
  152. github.com/reactor10/hivemind/hivetool
  153. github.com/redkite1/zigbee-gw/src/xbee
  154. github.com/rustyoz/muesli
  155. github.com/rzetterberg/elmobd
  156. github.com/shiguredo/fuji/device
  157. github.com/shirou/fuji/device
  158. github.com/simulatedsimian/flotilla-go/flotilla
  159. github.com/simulatedsimian/flotilla/flotilla
  160. github.com/simulatedsimian/gamepadremote
  161. github.com/simulatedsimian/gocmdutil/serialmon
  162. github.com/simulatedsimian/yx5300
  163. github.com/spagettikod/gotracer
  164. github.com/stampzilla/gozwave/serialapi
  165. github.com/stampzilla/gozwave/serialrecorder
  166. github.com/suapapa/tools/hcc
  167. github.com/tejainece/modbus
  168. github.com/tejainece/modbus/comm
  169. github.com/tochka/smssender
  170. github.com/tomoya0x00/go-im920
  171. github.com/trestletech/gobd/examples
  172. github.com/u8slvn/raspigosms/gsm
  173. github.com/velovix/datagolf
  174. github.com/vgardner/jenkins-led-lights
  175. github.com/vikstrous/go-blinkytape
  176. github.com/wI2L/blinkygo
  177. github.com/waltzofpearls/hermes/raspberrypi
  178. github.com/warthog618/modem/serial
  179. github.com/yazver/gsmmodem
  180. github.com/ymotongpoo/irmagician
  181. github.com/ympons/gobot/platforms/megapi
  182. github.com/yne717/amp/serial
  183. github.com/yurigorokhov/go-megapi
  184. github.com/zankich/hal/firmata
  185. github.com/zdebeer99/zhome/pkg/hardware/zioboard
  186. github.com/zpeters/wmc
  187. gobot.io/x/gobot/platforms/firmata
  188. gobot.io/x/gobot/platforms/mavlink
  189. gobot.io/x/gobot/platforms/megapi
  190. gobot.io/x/gobot/platforms/neurosky
  191. gobot.io/x/gobot/platforms/sphero