Updates to documentation
This commit is contained in:
2
LICENSE
2
LICENSE
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Copyright (c) 2014, Cristian Maglie.
|
Copyright (c) 2014-2016, Cristian Maglie.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
2
doc.go
2
doc.go
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
|
|||||||
26
example_getportlist_test.go
Normal file
26
example_getportlist_test.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
//
|
||||||
|
|
||||||
|
package serial_test
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
import "log"
|
||||||
|
import "go.bug.st/serial"
|
||||||
|
|
||||||
|
func ExampleGetPortsList() {
|
||||||
|
ports, err := serial.GetPortsList()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(ports) == 0 {
|
||||||
|
fmt.Println("No serial ports found!")
|
||||||
|
} else {
|
||||||
|
for _, port := range ports {
|
||||||
|
fmt.Printf("Found port: %v\n", port)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
29
example_serialport_test.go
Normal file
29
example_serialport_test.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
//
|
||||||
|
|
||||||
|
package serial_test
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
import "log"
|
||||||
|
import "go.bug.st/serial"
|
||||||
|
|
||||||
|
func ExampleSerialPort_SetMode() {
|
||||||
|
port, err := serial.OpenPort("/dev/ttyACM0", &serial.Mode{})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
mode := &serial.Mode{
|
||||||
|
BaudRate: 9600,
|
||||||
|
Parity: serial.PARITY_NONE,
|
||||||
|
DataBits: 8,
|
||||||
|
StopBits: serial.STOPBITS_ONE,
|
||||||
|
}
|
||||||
|
if err := port.SetMode(mode); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Println("Port set to 9600 N81")
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2015 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
@@ -10,38 +10,11 @@ import "fmt"
|
|||||||
import "log"
|
import "log"
|
||||||
import "go.bug.st/serial"
|
import "go.bug.st/serial"
|
||||||
|
|
||||||
func ExampleGetPortsList() {
|
// This example prints the list of serial ports and use the first one
|
||||||
ports, err := serial.GetPortsList()
|
// to send a string "10,20,30" and prints the response on the screen.
|
||||||
if err != nil {
|
func Example_sendAndReceive() {
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if len(ports) == 0 {
|
|
||||||
fmt.Println("No serial ports found!")
|
|
||||||
} else {
|
|
||||||
for _, port := range ports {
|
|
||||||
fmt.Printf("Found port: %v\n", port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleSetMode() {
|
// Retrieve the port list
|
||||||
port, err := serial.OpenPort("/dev/ttyACM0", &serial.Mode{})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
mode := &serial.Mode{
|
|
||||||
BaudRate: 9600,
|
|
||||||
Parity: serial.PARITY_NONE,
|
|
||||||
DataBits: 8,
|
|
||||||
StopBits: serial.STOPBITS_ONE,
|
|
||||||
}
|
|
||||||
if err := port.SetMode(mode); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fmt.Println("Port set to 9600 N81")
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleFullCommunication() {
|
|
||||||
ports, err := serial.GetPortsList()
|
ports, err := serial.GetPortsList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -50,10 +23,12 @@ func ExampleFullCommunication() {
|
|||||||
log.Fatal("No serial ports found!")
|
log.Fatal("No serial ports found!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print the list of detected ports
|
||||||
for _, port := range ports {
|
for _, port := range ports {
|
||||||
fmt.Printf("Found port: %v\n", port)
|
fmt.Printf("Found port: %v\n", port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open the first serial port detected at 9600bps N81
|
||||||
mode := &serial.Mode{
|
mode := &serial.Mode{
|
||||||
BaudRate: 9600,
|
BaudRate: 9600,
|
||||||
Parity: serial.PARITY_NONE,
|
Parity: serial.PARITY_NONE,
|
||||||
@@ -64,12 +39,15 @@ func ExampleFullCommunication() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send the string "10,20,30\n\r" to the serial port
|
||||||
n, err := port.Write([]byte("10,20,30\n\r"))
|
n, err := port.Write([]byte("10,20,30\n\r"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Sent %v bytes\n", n)
|
fmt.Printf("Sent %v bytes\n", n)
|
||||||
|
|
||||||
|
// Read and print the response
|
||||||
buff := make([]byte, 100)
|
buff := make([]byte, 100)
|
||||||
for {
|
for {
|
||||||
// Reads up to 100 bytes
|
// Reads up to 100 bytes
|
||||||
@@ -86,4 +64,3 @@ func ExampleFullCommunication() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// vi:ts=2
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
@@ -73,4 +73,3 @@ func (e SerialPortError) Code() int {
|
|||||||
return e.code
|
return e.code
|
||||||
}
|
}
|
||||||
|
|
||||||
// vi:ts=2
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
@@ -268,4 +268,3 @@ func OpenPort(portName string, mode *Mode) (*SerialPort, error) {
|
|||||||
return port, nil
|
return port, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// vi:ts=2
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Cristian Maglie. All rights reserved.
|
// Copyright 2014-2016 Cristian Maglie. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user