Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
s-celles opened this issue May 9, 2018 · 3 comments
Closed

Comments

@s-celles
Copy link
Contributor

s-celles commented May 9, 2018

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

@s-celles
Copy link
Contributor Author

s-celles commented May 9, 2018

With LibSerialPorts.jl from @andrewadare it works fine

using LibSerialPort

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 = open("/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()

@sjkelly
Copy link
Member

sjkelly commented Mar 27, 2019

@scls19fr should be fixed in 1c9710e

@sjkelly sjkelly closed this as completed Mar 27, 2019
@s-celles
Copy link
Contributor Author

Thanks @sjkelly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants