![]() Send the content of the data byte array to the serial port. // The Read function blocks until (at least) one byte is received from // the serial port or an error occurs. The function returns the number of bytes read. SetMode sets all parameters of the serial port SetMode(mode * Mode) error // Stores data received from the serial port into the provided byte array // buffer. func (e PortError) EncodedErrorString() string.func (e PortError) Code() PortErrorCode.func Open(portName string, mode *Mode) (Port, error).Send the string "10,20,30\n\r" to the serial port Open the first serial port detected at 9600bps N81 To send a string "10,20,30" and prints the response on the screen. This example prints the list of serial ports and use the first one ![]() This means that if you need USB enumeration Unfortunately the USB enumeration package for darwin (MacOSX) requires cgo This library tries to avoid the use of the "C" package (and consequently the need Ports, err := enumerator.GetDetailedPortsList()įmt.Printf("Found port: %s\n", port.Name)įmt.Printf(" USB ID %s:%s\n", port.VID, port.PID)įmt.Printf(" USB serial %s\n", port.SerialNumber)įor details on USB port enumeration see the documentation of the specific package. GetDetailedPortsList function in the enumerator package: The USB metadata, like VID/PID or USB Serial Number, with the If a port is a virtual USB-CDC serial port (for example an USB-to-RS232Ĭable or a microcontroller development board) is possible to retrieve The usual Read, Write and Close functions to send and receive data from the The port object implements the io.ReadWriteCloser interface, so we can use The configuration can be changed at any time with the SetMode function: The following snippets shows how to declare a configuration for 57600_E71: In the example above only the speed is changed so the port is opened using 115200_N81. If not specified the default options are 9600_N81, The Open function needs a "mode" parameter that specifies the configuration ![]() Port, err := serial.Open("/dev/ttyUSB0", mode) The serial port can be opened with the Open function: It is possible to get the list of available serial ports with the The canonical import for this library is go.bug.st/serial.v1 so the import line Package serial is a cross-platform serial library for the go language. The software is release under a BSD 3-clause license If you come from the version v0 and want to see the full list of API changes, please check this pull request: ![]() There are some API improvements, in particular object naming is now more idiomatic, class names are less redundant (for example serial.SerialPort is now called serial.Port), some internal class fields, constants or enumerations are now private and some methods have been moved into the proper interface. If you want to contribute to the development of this library, you must clone this git repository directly into your src folder under src/go.bug.st/serial.v1 and checkout the branch v1. A cross-platform serial library for go-lang. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |