Reading and sending data using UART via EVOK API

  • Hi,
    How i can retrieve/send data using UART via EVOK API?

    I've seen, but it is still unclear to me.


  • administrators

    Hello @mglowinski,

    the mentioned uart API is intended for serial lines configuration only.

    To send/receive data, you can use a standard Linux file-based approach. As you have not specified PLC series used, example for AXON units serial mapping can be found here:

  • Aha, ok:) Thx for a tip.

    Where can I find mapping for UniPi 1.1?

  • administrators

    Hello @mglowinski,

    mapping for all RPi based units is quite simple - just a single serial port, typically /dev/ttyAMA0 is available to the user.

  • Ok, that is what I thought.
    Is /dev/ttyAMA0 initiated by EVOK?

    I'm having issues using that with python pyserial and I wonder if this is caused by EVOK or RaspberryPi configuration.

    This is error, which I'm getting:

    Serial<id=0xb5c25ff0, open=True>(port='/dev/ttyAMA0', baudrate=38400, bytesize=8, parity='N', stopbits=1, timeout=60, xonxoff=False, rtscts=False, dsrdtr=False)
        def in_waiting(self):
            """Return the number of bytes currently in the input buffer."""
            #~ s = fcntl.ioctl(self.fd, termios.FIONREAD, TIOCM_zero_str)
    >       s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
    E       OSError: [Errno 25] Inappropriate ioctl for device

    Moreover, serial connection it is working properly with /dev/ttyUSB0 (USB to TTL converter CP2102 ). Once I move it to UniPi 1.1 UART RJ11 pinout, i can't start connection with pyserial anymore (upper error).

    Do you have any tip what can be wrong? Might it be related to UniPi 1.1 or rather RaspberryPi/Python configuration?

  • administrators

    Hello @mglowinski,

    what OS Image and Rasberry Pi generation do you have?

    You have to take into account that UART pins can be shared with Bluetooth and there are two types of UART
    available (full-featured and the limited one).
    More detail info about the Raspberry’s UARTs can be found here:

  • @martin_triska
    I'm running Buster from August 2020.

    cat /etc/os-release
    PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
    NAME="Raspbian GNU/Linux"
    VERSION="10 (buster)"

    I think that Bluetooth is running in my case (see below terminal result). I simply installed EVOK on fresh RaspberryOS Buster with default installation setting.

    sudo service bluetooth status
    bluetooth.service - Bluetooth service
       Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
       Active: active (running) since Mon 2021-02-08 12:27:17 CET; 3 days ago
         Docs: man:bluetoothd(8)
     Main PID: 819 (bluetoothd)
       Status: "Running"
        Tasks: 1 (limit: 4915)
       CGroup: /system.slice/bluetooth.service
               └─819 /usr/lib/bluetooth/bluetoothd
    Feb 08 12:27:17 PlugsTester systemd[1]: Starting Bluetooth service...
    Feb 08 12:27:17 PlugsTester bluetoothd[819]: Bluetooth daemon 5.50
    Feb 08 12:27:17 PlugsTester systemd[1]: Started Bluetooth service.
    Feb 08 12:27:17 PlugsTester bluetoothd[819]: Starting SDP server
    Feb 08 12:27:17 PlugsTester bluetoothd[819]: Bluetooth management interface 1.14 initialized
    Feb 08 12:27:17 PlugsTester bluetoothd[819]: Sap driver initialization failed.
    Feb 08 12:27:17 PlugsTester bluetoothd[819]: sap-server: Operation not permitted (1)
    Feb 08 12:27:18 PlugsTester bluetoothd[819]: Failed to set privacy: Rejected (0x0b)

    My question is if i need to do something to use UART connected to RJ11 on UniPi 1.1 board (the one from picture below) or it should work straight forward?
    To which RaspberryPi's UART is RJ11 interface on UniPi connected?


  • administrators

    Hello @mglowinski,

    Pins RXD0 a TXD0 (GPIO14/GPIO15, pins no. 8 and 10) -> primary UART are connected to the RJ connector.

    The most simple test is to install a terminal application ( e.g. minicom) and probe the UART in loopback mode.

    From RasberryOS, you can manipulate the UART using the raspi-config utility.

    Instruction how do disable BT or redirect it to Mini UART can be found on the link above.

  • I made it work.
    I enabled Serial in RaspberryPi Setting and and used /dev/serial0 and it worked.

    Thx @martin_triska for help!

Log in to reply