Code Monkey home page Code Monkey logo

serialports.jl's Introduction

SerialPorts

Build Status

SerialPorts.jl lets you work with devices over serial communication with Julia. It is designed to mimic regular file IO as in the Base Julia library.

This package requires PySerial, which is used through PyCall. Conda is used as a fallback so cross-platform installation is simple.

Check out LibSerialPort.jl if you want to avoid the Python dependency.

Quick Start

A SerialPort has a minimal API similar to IOStream in Julia.

A brief example:

using SerialPorts
s = SerialPort("/dev/ttyACM1", 250000)
write(s, "Hello World!\n")
close(s)

open, close, read, write, bytesavailable, readavailable, are all defined for SerialPort.

In order to see the attached serial devices, use list_serialports().

The Arduino submodule provides functionality for manipulating Arduinos over serial. SerialPorts.Arduino.reset(s::SerialPort) will reset an Arduino.

License

Available under the MIT License. See: LICENSE.md.

serialports.jl's People

Contributors

juliatagbot avatar ranocha avatar scls19fr avatar sjkelly avatar vezy avatar yakeworld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

serialports.jl's Issues

Flow Control

It would be nice to have a flow control system that can asynchronously handle a message queue. This would be the 1000th time someone wrote one of these...

use pyimport_conda

As of PyCall 1.5, you can now just do pyimport_conda("serial", "pyserial") to auto-install pyserial via Conda (if PyCall is using Conda) or print an informative error message, rather than duplicating that logic here. This will also let you remove the explicit Conda dependency.

Problems with Python 3.5 write calling to_bytes(data)

I tried writing data to an opened serial port. The problem is the Python side tries to convert the data into bytes, and that conversion fails.

julia> versioninfo()
Julia Version 0.4.0
Commit 0ff703b* (2015-10-08 06:20 UTC)
Platform Info:
  System: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
Python 3.5.0 |Anaconda 2.4.0 (64-bit)| (default, Oct 20 2015, 07:26:33) [MSC v.1900 64 bit (AMD64)] on win32
julia> Pkg.status("PyCall")
 - PyCall                        1.2.0

julia> Pkg.status("SerialPorts")
 - SerialPorts                   0.0.7
julia> using SerialPorts

julia> s = SerialPort("COM9", 115200)
SerialPorts.SerialPort("COM9",115200,8,"N",1,nothing,false,false,false,PyObject
Serial<id=0x17539518, open=True>(port='COM9', baudrate=115200, bytesize=8, parit
y='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False))
julia> write(s,ASCIIString("G1X2"))
ERROR: PyError (:PyObject_Call) <class 'TypeError'>
TypeError("unicode strings are not supported, please encode to bytes: 'G1X2'",)
  File "C:\Users\Chris\Anaconda3\lib\site-packages\serial\serialwin32.py", line
301, in write
    data = to_bytes(data)
  File "C:\Users\Chris\Anaconda3\lib\site-packages\serial\serialutil.py", line 5
8, in to_bytes
    raise TypeError('unicode strings are not supported, please encode to bytes:
%r' % (seq,))

 [inlined code] from C:\Users\Chris\.julia\v0.4\PyCall\src\exception.jl:81
 in pycall at C:\Users\Chris\.julia\v0.4\PyCall\src\PyCall.jl:79
 in call at C:\Users\Chris\.julia\v0.4\PyCall\src\PyCall.jl:388
 in write at C:\Users\Chris\.julia\v0.4\SerialPorts\src\SerialPorts.jl:93

julia> write(s, UInt8(42))
ERROR: PyError (:PyObject_Call) <class 'TypeError'>
TypeError("'int' object is not iterable",)
  File "C:\Users\Chris\Anaconda3\lib\site-packages\serial\serialwin32.py", line
301, in write
    data = to_bytes(data)
  File "C:\Users\Chris\Anaconda3\lib\site-packages\serial\serialutil.py", line 6
1, in to_bytes
    for item in seq:

 [inlined code] from C:\Users\Chris\.julia\v0.4\PyCall\src\exception.jl:81
 in pycall at C:\Users\Chris\.julia\v0.4\PyCall\src\PyCall.jl:79
 in call at C:\Users\Chris\.julia\v0.4\PyCall\src\PyCall.jl:388
 in write at C:\Users\Chris\.julia\v0.4\SerialPorts\src\SerialPorts.jl:89

Make next tag 0.1.0

It looks like 0.0.3 and earlier supported Julia 0.3, but 0.0.4 and later don't. For future sanity in case an 0.3 bugfix is ever needed, would be good to get new 0.4-only releases on a separate minor package version. Thanks!

SerialPorts error when writing an UInt8

Hi guys!

I am new in julia, and right now I am trying to develop an algorithm to control an RC car from the PC. Thus far I have been able to receive UInt8 data from the vehicle. However, the only data format that is allowed to be from the PC is String, which is a waste of processing time when it comes to "real-time" control.

Is there any way I could send UInt8 data with SerialPorts.write function?

Thanks!

JuliaCIBot Fails

i need to investigate this further:

ERROR: Unsatisfiable requirements detected for package SerialPorts [5d0f9de7]:
SerialPorts [5d0f9de7] log:
├─possible versions are: [0.0.1-0.0.7, 0.1.0] or uninstalled
├─restricted to versions * by an explicit requirement, leaving only versions [0.0.1-0.0.7, 0.1.0]
└─restricted by julia compatibility requirements to versions: uninstalled — no versions left

https://s3.ap-south-1.amazonaws.com/juliarun-ci/ab051795e433383aea578c7b86a565160ffc2f20/SerialPorts_reverse_dependency_tests.html

Julia code using SerialPorts doesn't behave like Python code using serial

Hello,

I'm trying to communicate with a Nextion display from Julia thanks to a USB TTL converter.

The following Julia code:

using SerialPorts

function _end_of_command(ser)
    for i in 0:2
        write(ser, 0xff)
    end
end

function _execute_command(ser, cmd)
    println(cmd)
    write(ser, cmd)
    _end_of_command(ser)
end

function main()
    ser = SerialPort("/dev/ttyUSB0", 9600)
    _execute_command(ser, "page 0")
    sleep(2)
    _execute_command(ser, "page 1")
    sleep(2)
    _execute_command(ser, "t0.txt=\"Hello\"")
    close(ser)
end


main()

seems very close to this Python code:

import time
import serial


def _end_of_command(ser):
    for i in range(3):
        ser.write(chr(255))

def _execute_command(ser, cmd):
    print(cmd)
    ser.write(cmd)
    _end_of_command(ser)

def main():
    ser = serial.Serial("/dev/ttyUSB0", 9600)
    _execute_command(ser, "page 0")
    time.sleep(2)
    _execute_command(ser, "page 1")
    _end_of_command(ser)
    time.sleep(2)
    _execute_command(ser, "t0.txt=\"Hello\"")
    ser.close()


if __name__ == '__main__':
    main()

Although it seems very similar, the Julia code doesn't work (page doesn't change, txt property of text widget t0 doesn't change...) while Python code is doing exactly what it's expected to do.

Any idea what is going wrong?

Is it a problem on my side (ie my Julia code should be fixed) or is it a Julia library problem (ie SerialPorts should be fixed).

I wonder if #21 is not a possible problem.

Kind regards

Cannot run the Listener.jl example

Hi,

When I run the Listener.jl example (from Julia REPL using Atom/Juno), I got the following message: "usage: listener.jl --port --baud "
If I enter "listener.jl --port COM3 --baud 115200", I got the following error message: "ERROR: syntax: invalid operator "--".

How can I run correctly this example ?

Thank you !

libserialport Migration

This should help with performance and simplicity. The major question is whether the
Python backend should disappear. I'd like to keep it, but I don't want to sacrifice performance. My
current thought is to make it a build flag, something similar to how PyCall chooses
a python path or anaconda install.

pycall api updates

PyCall 1.90.0 is now released, which change o[:foo] and o["foo"] to o.foo and o."foo", respectively, for python objects o; see also JuliaPy/PyCall.jl#629.

The old getindex methods still work but are deprecated, so you'll want to put out a new release that uses the new methods and REQUIREs PyCall 1.90.0 to avoid having zillions of deprecation messages.

julia 0.7.0 is using code of `05compat` branch

Hi, I use this package for a while, but when I changed to julia 0.7.0, the write function stopped working with strings. After fighting with it for a few hours, I saw that the module used by 0.7.0 is the same as the branch 05compat. It made sense because there were still several deprecation warnings. I solved it by tracking the master manually with ]add SerialPorts#master but it took me a while to figure that out... Is probably the registered branch mistaken?

Thanks in advance!

SerialPort("/dev/ttyACM1", 9600) generates error on Julia 0.4.1

julia> versioninfo()
Julia Version 0.4.1
Commit cbe1bee (2015-11-08 10:33 UTC)
Platform Info:
System: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz
WORD_SIZE: 64
BLAS: libopenblas (NO_LAPACK NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: liblapack.so.3
LIBM: libopenlibm
LLVM: libLLVM-3.3

I don't know if other versions are affected.

s = SerialPort("/dev/ttyACM1", 9600)
ERROR: MethodError: convert has no method matching convert(::Type{SerialPorts.SerialPort}, ::ASCIIString, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::PyCall.PyObject)
This may have arisen from a call to the constructor SerialPorts.SerialPort(...),
since type constructors fall back to convert methods.
Closest candidates are:
SerialPorts.SerialPort(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)
SerialPorts.SerialPort(::ASCIIString, ::Int64, ::Int64, ::ASCIIString, ::Int64, ::Any, ::Bool, ::Bool, ::Bool, ::PyCall.PyObject)
SerialPorts.SerialPort(::Any, ::Any)
...
in call at essentials.jl:57
in call at /home/luther/.julia/v0.4/SerialPorts/src/SerialPorts.jl:59

write function seems to have some bug!

Hi,

All the other functions in the package work fine except the the write function. I'm trying:

using SerialPorts
s = SerialPort("/dev/ttyUSB0", 9600)
write(s, Vector{UInt8}("Hello\n"))

But I get:

510
bytes sent!

At the other end, I receive 510 bytes with all of them '\0'.

However, if I directly do the same in Python environment, I receive correctly all the bytes.

I'm using :

versioninfo()
Julia Version 0.6.1
Commit 0d7248e (2017-10-24 22:15 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i7-7820HK CPU @ 2.90GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT NO_AFFINITY HASWELL)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)

ERROR: PyError (:PyObject_Call) <type 'exceptions.OSError'>

I am using Julia 0.4.5 on Ubuntu 15.04
I get the following error when I try to open the Serial port with an Arduino.

julia> using SerialPorts

julia> k = SerialPort("/dev/ttyACM0",115200)
ERROR: PyError (:PyObject_Call) <type 'exceptions.OSError'>
OSError(2, 'No such file or directory')
File "/home/chandrashekhar/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/serial/serialutil.py", line 282, in init
self.open()
File "/home/chandrashekhar/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/serial/serialposix.py", line 289, in open
self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)
[inlined code] from /home/chandrashekhar/.julia/v0.4/PyCall/src/exception.jl:81
in pycall at /home/chandrashekhar/.julia/v0.4/PyCall/src/PyCall.jl:463
in call at /home/chandrashekhar/.julia/v0.4/PyCall/src/PyCall.jl:479
in call at /home/chandrashekhar/.julia/v0.4/SerialPorts/src/SerialPorts.jl:66

It worked fine the first time I tried it, but is showing this error ever since. How do I solve this?

IO subtyping

This might be good for showing formats and other functions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.