diff --git a/LICENSE b/LICENSE index 565e93b..8596fab 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ -Copyright (c) 2014, Cristian Maglie. +Copyright (c) 2014-2016, Cristian Maglie. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/doc.go b/doc.go index 0b4d396..fff8acf 100644 --- a/doc.go +++ b/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 // license that can be found in the LICENSE file. // diff --git a/example_getportlist_test.go b/example_getportlist_test.go new file mode 100644 index 0000000..be34e81 --- /dev/null +++ b/example_getportlist_test.go @@ -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) + } + } +} + diff --git a/example_serialport_test.go b/example_serialport_test.go new file mode 100644 index 0000000..2ee936c --- /dev/null +++ b/example_serialport_test.go @@ -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") +} + diff --git a/example_test.go b/example_test.go index 12bec45..c087746 100644 --- a/example_test.go +++ b/example_test.go @@ -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 // license that can be found in the LICENSE file. // @@ -10,38 +10,11 @@ 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) - } - } -} +// This example prints the list of serial ports and use the first one +// to send a string "10,20,30" and prints the response on the screen. +func Example_sendAndReceive() { -func ExampleSetMode() { - 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() { + // Retrieve the port list ports, err := serial.GetPortsList() if err != nil { log.Fatal(err) @@ -50,10 +23,12 @@ func ExampleFullCommunication() { log.Fatal("No serial ports found!") } + // Print the list of detected ports for _, port := range ports { fmt.Printf("Found port: %v\n", port) } + // Open the first serial port detected at 9600bps N81 mode := &serial.Mode{ BaudRate: 9600, Parity: serial.PARITY_NONE, @@ -64,12 +39,15 @@ func ExampleFullCommunication() { if err != nil { 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")) if err != nil { log.Fatal(err) } fmt.Printf("Sent %v bytes\n", n) + // Read and print the response buff := make([]byte, 100) for { // Reads up to 100 bytes @@ -86,4 +64,3 @@ func ExampleFullCommunication() { } } -// vi:ts=2 diff --git a/serial.go b/serial.go index c2b8de2..9cb1052 100644 --- a/serial.go +++ b/serial.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 // license that can be found in the LICENSE file. // @@ -73,4 +73,3 @@ func (e SerialPortError) Code() int { return e.code } -// vi:ts=2 diff --git a/serial_darwin.go b/serial_darwin.go index 747c541..52742c0 100644 --- a/serial_darwin.go +++ b/serial_darwin.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 // license that can be found in the LICENSE file. // diff --git a/serial_darwin_386.go b/serial_darwin_386.go index 69364a6..a88e554 100644 --- a/serial_darwin_386.go +++ b/serial_darwin_386.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 // license that can be found in the LICENSE file. // diff --git a/serial_darwin_amd64.go b/serial_darwin_amd64.go index 4d88c8e..377c614 100644 --- a/serial_darwin_amd64.go +++ b/serial_darwin_amd64.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 // license that can be found in the LICENSE file. // diff --git a/serial_linux.go b/serial_linux.go index 0afdc20..4376806 100644 --- a/serial_linux.go +++ b/serial_linux.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 // license that can be found in the LICENSE file. // diff --git a/serial_unix.go b/serial_unix.go index eddefc0..a58347c 100644 --- a/serial_unix.go +++ b/serial_unix.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 // license that can be found in the LICENSE file. // diff --git a/serial_windows.go b/serial_windows.go index 2c563d5..999c309 100644 --- a/serial_windows.go +++ b/serial_windows.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 // license that can be found in the LICENSE file. // @@ -268,4 +268,3 @@ func OpenPort(portName string, mode *Mode) (*SerialPort, error) { return port, nil } -// vi:ts=2 diff --git a/syscall_darwin.go b/syscall_darwin.go index 9ab2d96..f0b87e2 100644 --- a/syscall_darwin.go +++ b/syscall_darwin.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 // license that can be found in the LICENSE file. // diff --git a/syscall_linux.go b/syscall_linux.go index ece3ae9..79ff6d3 100644 --- a/syscall_linux.go +++ b/syscall_linux.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 // license that can be found in the LICENSE file. //