Skip to content

JuliaIO/LibSerialPort.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LibSerialPort.jl

libserialport is a small, well-documented C library for general-purpose serial port communication. This is a julia wrapper for the library.

Apart from a very few non-essential functions, the entire library API (about 75 functions) is wrapped using ccall. In addition, a higher-level interface is also provided that follows Julia's IO stream interface.

Installation

pkg> add LibSerialPort

Usage

Try

julia> using LibSerialPort
julia> list_ports()  # or get_port_list() for an array of names

The examples/ directory contains a simple serial console for the command line. This may serve as a useful starting point for your application. The serial_example.ino sketch can be flashed to a microcontroller supported by the Arduino environment.

using LibSerialPort

# Modify these as needed
portname = "/dev/ttyS0"
baudrate = 115200

# Snippet from examples/mwe.jl
LibSerialPort.open(portname, baudrate) do sp
	sleep(2)

	if bytesavailable(sp) > 0
    	println(String(read(sp)))
	end

    write(sp, "hello\n")
    sleep(0.1)
    println(readline(sp))
end

The tests are also worth looking at for demonstration of i/o and configuration. They can be run via julia test/runtests.jl <address> <baudrate>. Unless the address of your device matches that in runtests.jl, doing pkg> test LibSerialPort will fail. This problem would be addressed by support for args in the Pkg REPL.

Note that on Windows, returning an OS-level port handle is not yet supported.