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