From adb01c1cf5595ba0847facf1369b5d8787ecaae8 Mon Sep 17 00:00:00 2001 From: Steve Kelly Date: Mon, 9 Jan 2017 18:33:02 -0500 Subject: [PATCH 1/2] add basic repl --- src/SerialPorts.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/SerialPorts.jl b/src/SerialPorts.jl index 5e00328..4b3fa1f 100644 --- a/src/SerialPorts.jl +++ b/src/SerialPorts.jl @@ -144,6 +144,23 @@ function in_dialout() end end +@doc """ +Initialize a REPL. Calling conventions are identical to `SerialPort` +""" -> +function REPL(args...) + s = SerialPort(args...) + @async begin + while true + print(String(readavailable(s))) + end + end + while true + print_with_color(:magenta, "\nserial> ") + c = readline() + !isspace(c) && write(s, c) + end +end + # Submodules include("Arduino.jl") From cd39bfa8b1cb81de1670bf498518fdf16893312d Mon Sep 17 00:00:00 2001 From: Steve Kelly Date: Tue, 10 Jan 2017 15:40:45 -0500 Subject: [PATCH 2/2] add alternative constructor for initialized SerialPort --- src/SerialPorts.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/SerialPorts.jl b/src/SerialPorts.jl index 4b3fa1f..a416e49 100644 --- a/src/SerialPorts.jl +++ b/src/SerialPorts.jl @@ -145,10 +145,9 @@ function in_dialout() end @doc """ -Initialize a REPL. Calling conventions are identical to `SerialPort` +Initialize a REPL. Calling conventions are identical to `SerialPort`. """ -> -function REPL(args...) - s = SerialPort(args...) +function REPL(s::SerialPort) @async begin while true print(String(readavailable(s))) @@ -157,10 +156,14 @@ function REPL(args...) while true print_with_color(:magenta, "\nserial> ") c = readline() - !isspace(c) && write(s, c) + !isspace(c) && write(s, c) # Don't send newlines end end +function REPL(args...) + REPL(SerialPort(args...)) +end + # Submodules include("Arduino.jl")