1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

relay writeall ff\n\r does not work from pyserial and relay readall is not reliable

Discussion in 'Relay Modules' started by rlegault, Jan 8, 2017.

  1. rlegault

    rlegault New Member

    Joined:
    Jan 8, 2017
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Waterloo Canda
    relay on 1\n\r
    relay off 1\n\r
    reset\n\r
    relay readall\n\r

    these all work from within pyserial.
    however
    relay writeall ff\n\r
    does not.
    relay writeall does work from minicom but not via the serial.write() command.
    Here is a script I wrote that shows the problem
    I tried using different speeds, 2400, 9600 115200 but it did not make a difference.

    The firmware version is 8.


    ==== PYTHON CODE EXAMPLE showing problem =====

    import serial
    import time

    s=serial.Serial('/dev/ttyACM0', 15200, timeout=1)
    s.write('ver\n\r')
    time.sleep(1)
    print s.read(25)

    s.write('reset\n\r')
    time.sleep(1)
    print s.read(25)

    s.write('relay readall\n\r')
    time.sleep(1)
    print s.read(25)

    s.write('relay on 0')
    time.sleep(1)
    print s.read(25)

    s.write('relay readall\n\r')
    time.sleep(1)
    print s.read(25)

    s.write('relay on 2')
    time.sleep(1)
    print s.read(25)

    s.write('relay readall\n\r')
    time.sleep(1)
    print s.read(25)

    s.write('relay writeall cc\n\r')
    time.sleep(1)
    print s.read(25)
    s.write('relay readall\n\r')
    time.sleep(1)
    print s.read(25)


    ======= HERE IS OUT PUT from the script =====
    >>> import serial
    >>> import time
    >>>
    >>> s=serial.Serial('/dev/ttyACM0', 15200, timeout=1)
    >>> s.write('ver\n\r')
    5
    >>> time.sleep(1)
    >>> print s.read(25)
    ver

    00000008
    >
    >>>
    >>> s.write('reset\n\r')
    7
    >>> time.sleep(1)
    >>> print s.read(25)
    reset

    >
    >>>
    >>> s.write('relay readall\n\r')
    15
    >>> time.sleep(1)
    >>> print s.read(25)
    relay readall

    00
    >
    >>>
    >>> s.write('relay on 0')
    10
    >>> time.sleep(1)
    >>> print s.read(25)
    relay on 0
    >>>
    >>> s.write('relay readall\n\r')
    15
    >>> time.sleep(1)
    >>> print s.read(25)
    aelay reada
    >
    >>>
    >>> s.write('relay on 2')
    10
    >>> time.sleep(1)
    >>> print s.read(25)
    relay on 2
    >>>
    >>> s.write('relay readall\n\r')
    15
    >>> time.sleep(1)
    >>> print s.read(25)
    aelay reada
    >
    >>>
    >>> s.write('relay writeall cc\n\r')
    19
    >>> time.sleep(1)
    >>> print s.read(25)
    relay writeall cc

    >
    >>> s.write('relay readall\n\r')
    15
    >>> time.sleep(1)
    >>> print s.read(25)
    relay readall

    05
    >
    >>>


    ========
    As you can see the readall reports that only relay 2 and 0 are on. when it should have been relay 7,6 and 3,2
    You can also see that the readall command response was corrupted for some reason in earlier calls.

    Please let me know if you have a solution to the writeall, it would be nice to have for the python library I am creating.
     
  2. admin

    admin Administrator Staff Member

    Joined:
    Jan 23, 2015
    Messages:
    169
    Likes Received:
    10
    Trophy Points:
    18
    Hello @rlegault,

    There were a couple of minor issues with the script (No \r after relay on/off commands and \r did not work as expected with Python 2.7 ). I have fixed those and the code is working fine now (please see screenshot below on Windows with Python 2.7). Also the corrected code is attached.

    upload_2017-2-27_10-58-51.png

    Thanks,
    Tom
    Numato Lab
     

    Attached Files:

Share This Page