How to connect serial devices ?

Runtime
PLC
2014-04-02
2020-04-15
<< < 1 2 3 4 5 > >> (Page 4 of 5)
  • ekmekci

    ekmekci - 2017-04-20

    HTejada hat geschrieben:
    if 2 usb are the same manufacture, you can change udiport:=2 for second device. You can create news string i/o for the second device.
    Lucky!
    BR
    Hector.

    Thank you for your help. But what if i use 2 usb devices which different manufacture ?
    What i need to do.

    Also, what is the mean "same manufacture" ? Could you please give example ?

     
  • eschwellinger

    eschwellinger - 2017-04-20

    Hi,
    set symbolic links in Linux

    Example:
    /dev/ttyUSB0 -> /dev/USBCDS0
    /dev/ttyAMA0 -> /dev/USBCDS1

    and then in /etc/CODESYSControl.cfg only this line will be needed:

    [SysCom]
    Linux.Devicefile=/dev/USBCDS

    BR
    Edwin

     
  • ekmekci

    ekmekci - 2017-04-21

    Edwin Schwellinger hat geschrieben:
    Hi,
    set symbolic links in Linux
    Example:
    /dev/ttyUSB0 -> /dev/USBCDS0
    /dev/ttyAMA0 -> /dev/USBCDS1
    and then in /etc/CODESYSControl.cfg only this line will be needed:
    [SysCom]
    Linux.Devicefile=/dev/USBCDS
    BR
    Edwin

    Thank you Edwin,

    I will try and i will let you know,

     
  • ekmekci

    ekmekci - 2017-04-25

    Edwin Schwellinger hat geschrieben:
    Hi,
    set symbolic links in Linux
    Example:
    /dev/ttyUSB0 -> /dev/USBCDS0
    /dev/ttyAMA0 -> /dev/USBCDS1
    and then in /etc/CODESYSControl.cfg only this line will be needed:
    [SysCom]
    Linux.Devicefile=/dev/USBCDS
    BR
    Edwin

    Dear Edwin,

    I did what you said.
    Everything works perfect now.

    But i have one question about serial com structure.

    For example, i have GPS receiver. When i power up the receiver, gps datas comes regularly every one second.
    I wonder, it is possible to understand there is data which coming or not.
    I mean, according to your example we alwasys try to reading comport every 250ms randomly. If there is data we can get the data if there isnot data we still read comport every 250ms.

    Is there any indicator which tell us data is coming or data has come.

    I hope i explained well.

     
  • DagHansa

    DagHansa - 2017-05-23

    Changes in Raspberry Pi 3 related to using the on-board UART:

    On PI3, ttyAMA0 is now connected to Bluetooth.
    In latest Jessie version /dev/serial0 is the on-board UART (serial).
    So, in /etc/codesys.cfg, you must add the line

    Linux.Devicefile = /dev/serial

    Also, it seems that sometimes the UART is disabled in Kernel.
    To enable it, edit /boot/config.txt and set enable_uart=1

    Finally, remember to disable the Linux console mode (the serial port is default used by Linux console)

     
  • Kampfwurst

    Kampfwurst - 2017-05-25

    Hi

    I would like to connect the internal UART from my Raspberry over a MAX485 RS-485 Module from eb.. to an arduino so that i can send data over modbus rtu.
    I have done the change in the CODESYSControl.cfg

    [SysCom]
    Linux.Devicefile=/dev/ttyAMA
    portnum := COM.SysCom.SYS_COMPORT1;

    Now i have the problem that i dont know how to connect the module to the raspberry
    I tried it like on this page. LINK

    Without success

    I have a Modbus COM PORT in my Projekt with a green symbol.
    The modbus Master is also green.
    But the Modbus Slave is changing between red and orange

    Maybe someone can help

    Chris

     
  • Anonymous - 2018-02-02

    Originally created by: dosnova

    Hi,

    We are trying to connect a serial device via FTDI to Serial USB cable. Communication works fine with minicom but, after following all the steps to link the serial port to Codesys, nothing happens. An Error 5004 (unknown error) is showed. We are trying with the sample project SerialcomwithVisu provided in the Codesys store.

    The serial port is identified as "ttyUSB0" and I've added the following lines to CODESYSControl.cfg:

    [SysCom]
    Linux.Devicefile=/dev/ttyUSB
    portnum := COM.SysCom.SYS_COMPORT1;

    Speed, parity, and all the serial parameters have been introduced correctly.

    Raspberry version is 3.5.12.0, working with Cedesys 3.5 SP12 x64

    We apprecciate your suggestions.

     
  • eschwellinger

    eschwellinger - 2018-02-03

    Hi,
    Check if the entry is maybe dublicated or different in CODESYSControl.cfg and CODESYSControl_User.cfg
    In the /etc
    /
    BR
    Edwin

     
  • Anonymous - 2018-02-03

    Originally created by: dosnova

    Thanks Edwin, I've removed the entry from CODESYSControl.cfg and added it to CODESYSControl_User.cfg and now its working fine.

     
  • Brewgold2

    Brewgold2 - 2018-02-19

    Hi:

    I want to connect two USB slave devices for MODBUS,
    The first is a speed variator with a USB / RS485 converter
    usb 1-1.5: ch341-uart converter now atachmend to tty USB0
    Is Ok.
    The second one would be an ARDUINO ONE
    cdm-acm 1-1.3: 1.0: ttyACM0: USB ACM device.
    Is a ttyUSB1 possible?

    Thank you

    Fernando

     
  • eschwellinger

    eschwellinger - 2018-02-19

    Hi,
    you need to google for "udev rules" or
    "serial-symlinks.rules"

    for CODESYS you need a configuration like:

    ch341-uart converter is attachmend to ttyUSB0
    and your USBAMA0 should then attached to ttyUSB1

    BR
    Edwin

     
  • Indi

    Indi - 2018-08-07

    Hi All,

    please I need help
    I want to control via Raspi (USB to Serial) a Relais Modul. It already worked at my computer (WIN7) and on the Raspi using the console. But using CodeSys I get no acces to the relais. Attached i have summarized the details.
    Hoping for Feedback!

    Indi

    HELP.pdf [117.89 KiB]

     
  • eschwellinger

    eschwellinger - 2018-08-10

    Hi,

    please move your added SYScom section: [SysCom]
    from /etc/CODESYSControl.cfg to /etc/CODESYSControl_User.cfg

    means remove it from /etc/CODESYSControl.cfg and Change the existing in /etc/CODESYSControl_User.cfg to

    [SysCom]
    Linux.Devicefile=/dev/ttyACM

    BR
    Edwin

     
  • Indi

    Indi - 2018-08-14

    Thanks a lot. Now it works.

     
  • tiguitomds

    tiguitomds - 2018-09-20

    Hello All!

    Since I'm new to Linux and Codesys, I was hoping that somebody here could help me
    I'm using an Apalis Module, with Angstrom version of Linux, and I'm trying to use its serial port with codesys.

    The Apalis Module has 4 uart ports(/dev/ttymxc0, 1 ,3 and 4) and I've tested all of them by short-circuiting Rx and Tx Pins and sending an echo command or with minicom. All those tests came out ok. But when I try to use it with Codesys, it doesn't work

    I am using this code to open the serial port.
    Basically it is the Serial Com example with SysCom Library, the only change was the serial port 4 selected and it is only the code to open it:

    VAR
       bOpenCom: BOOL := TRUE;
       hCom: RTS_IEC_HANDLE := RTS_INVALID_HANDLE;
       Result: RTS_IEC_RESULT;
       csComSettings: COM_Settings;
       bWriteCom: BOOL := TRUE;
       dwWritten: UDINT;
       dwOffset: UDINT;
       str : STRING := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890$R$N';
       abyWriteData: array[0..4095] of BYTE;
       i: INT;
       bReadCom: BOOL := TRUE;
       dwRead: UDINT;
       strRead: STRING;
       dwWrittenLog : ARRAY[0..49] OF DWORD;
       dwZeroWrittenCount : DWORD;
       iCurWrittenLog : INT;
    END_VAR
    IF bOpenCom THEN
       bOpenCom := FALSE;
       // Prepare test data
       FOR i:=0 TO 4095 DO
          abyWriteData[i] := str[i MOD 64];
       END_FOR
       // Open COM port 4
       hCom := SysComOpen(sPort:= SYS_COMPORT4 , pResult:= ADR(Result));
       IF hCom <> RTS_INVALID_HANDLE THEN
          // Configure the connection
          csComSettings.byParity := SYS_NOPARITY;
          csComSettings.byStopBits := SYS_ONESTOPBIT;
          csComSettings.sPort := SYS_COMPORT4;
          csComSettings.ulBaudrate := SYS_BR_9600;
          csComSettings.ulBufferSize := 0;
          csComSettings.ulTimeout := 10;
          Result := SysComSetSettings(hCom:= hCom, pSettings:= ADR(csComSettings) , _:= 0);
       END_IF
    END_IF
    

    and here is the CODESYSControl text:

    Is there any other configuration that I should do? like in the device description of the apalis module?
    I hope there is enough information and that somebody knows what is the issue

    Thanks for your time and have a nice day!

    edit:
    I found out that i was missing a ; in

    [SysCom]
    Linux.Devicefile=/dev/ttymxc4
    portnum := COM.SysCom.SYS_COMPORT4;

    but it still doesn't work.

    now i tried removing the number from "/dev/ttymxc", and i don't get the "unknown error" anymore. it returns me a number like 0x12,0x13,0x14,... (i think it's related to some other serial port)
    and any of the /dev/ttymxc0, /dev/ttymxc1, /dev/ttymxc3 or /dev/ttymxc4 seems to be opened

    edit 2 (solution):
    since i was able to open the serial port using these configurations

    [SysCom]
    Linux.Devicefile=/dev/ttymxc

    I figured out what the problem was
    apalis uses 4 serial ports, but its names have a gap between uart 2 and uart 3, so should the COM port number be called with this gap
    uart1 -> /dev/ttymxc0 -> COM1
    uart2 -> /dev/ttymxc1 -> COM2
    uart3 -> /dev/ttymxc3 -> COM4
    uart4 -> /dev/ttymxc4 -> COM5

    so... i was opening 1 port, but instead, was testing another

    CODESYSControl.pdf [228.23 KiB]

     
  • CanBohr

    CanBohr - 2018-09-25

    Hi to all,

    I am trying to read the data from a GPS Neo Modul into Codesys.

    The Modul is connected to the internal pins GND, 3,3V, RS and TX of a Rasperry 3B.
    RX and TX are crossed, that means the RX pin of the GPS modul is connected to the TX pin of the Raspi and the TX pin of the GPS is connected to the RX pin of the Raspi.

    I have added /etc/CODESYSControl_User.cfg
    [SysCom]
    Linux.Devicefile=/dev/ttyAMA
    portnum := COM.SysCom.SYS_COMPORT1;

    In /etc/CODESYSControl.cfg I have tried before and deleted the lines now.

    In /boot/cmdline.txt I deleted the section "console=ttyAMA0,115200" and the section "kgdboc=ttyAMA0,115000".

    If I paste cat /dev/ttyAMA0 | od tx1 in the console I get 0000000 but nothing else.

    I installed sudo apt-get install gpsd gpsd-clients.
    I restarted the serial port with stty -F /dev/ttyAMA0 9600.
    I started GPSD by sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock.
    Then I started the gps monitor with cgps -s.

    But I don't get anything.

    Can somebody help?

    Cheers,
    Xaver

     
  • eschwellinger

    eschwellinger - 2018-09-25

    Hi Xaver,
    maybe a stupid question.
    Did you enable this serial port in raspi-config

    BR
    Edwin

    IMG: serial.png

     
  • CanBohr

    CanBohr - 2018-09-25

    Hi Edwin,

    Yes, serial port is enabled.
    I read something about that Bluetooth is connected on the serial pins of the Raspi 3B and that I would have to use an USB to Serial converter to connect the GPS to this type of Raspi.

    Can this be?

    Cheers,
    Xaver

     
  • CanBohr

    CanBohr - 2018-09-25

    I have established a connection now by using
    Linux.Devicefile=/dev/serial
    portnum := COM.SysCom.SYS_COMPORT1

    insead of
    Linux.Devicefile=/dev/ttyAMA
    portnum := COM.SysCom.SYS_COMPORT1

    Now I receive messages in Codesys by using serialComWithVisu example. But the messages don't synchonize. I get a continuous stream of strings from the Serial_Line (FB).
    Is there any existing filter or a tool to get the Serial_Line (FB) to synchronize after having received a line feed for example?

    Cheers,
    Xaver

     
  • tsimpson

    tsimpson - 2019-04-06

    I just spent the day installing two identical serial devices. One was a RS-485 dongle and the other an RS-485 to TTL adapter for a power supply. Both come up as an "QinHeng Electronics HL-340 USB-Serial adapter" with identical ID's according to "lsusb". The root problem was that occasionally, they would end up swapped. Since they are both identical, there was no distiguishing characteristics for my "udev" rules for the devices. Between this thread and some Linux sites I found a work around. I wanted to share it here in case it may help others, and also so that I can refer back to it after I forget how I made it work

    In essence, instead of giving the device a permanent linux device, I gave a permanent linux device to the USB port. It seems each port on the Pi board has a unigue ID. This is shown below as port 1.2-1.5 at the following link:

    https://askubuntu.com/questions/49910/h ... ters#50412

    Armed with this knowledge I then created and edited /etc/udev/rules.d/99-usb-serial.rules. This file contains the following:

    SUBSYSTEM=="tty", ATTRS{devpath}=="1.5", SYMLINK+="ttyUSC0"SUBSYSTEM=="tty", ATTRS{devpath}=="1.3", SYMLINK+="ttyUSC1"SUBSYSTEM=="tty", ATTRS{devpath}=="1.4", SYMLINK+="ttyUSC2"SUBSYSTEM=="tty", ATTRS{devpath}=="1.2", SYMLINK+="ttyUSC3"

    The 1.5 device is my RS-485 dongle and the 1.3 device goes to the USB-TTL board.

    Next I edited /etc/CODESYS_User.cfg. The following lines were added:

    [SysCom]Linux.Devicefile=/dev/ttyUSCportnum := COM.SysCom.SYSCOMPORT1;

    With this configuration the USB port number (as shown in the link), USB 1.5 will always be Codesys port 1. Likewise USB port 1.3 will always be Codesys port 2, etc. With the tests Ive performed, the comm adapter addresses are now tied to a USB "port" (or slot) rather than being first come first served. With all said and done the Modbus server connected to my dongle is now at (and as long as I dont change slots will be) com device 1. Likewise the Modbus at the other adaptor is and should remain comm 2. Long story short, I know what com port it is based on which slot the device is plugged into.

    A word of caution, I dont know how this will act with a USB hub or device besides a com device. My thought is if it causes problems, delete the lines from usb-serial-rules that are not needed. Also, the devices seem to no longer be "hot swappable". From what I have seen a reboot is required if a device is removed and reinserted. Hope this helps someone else also.

    IMG: Bild

     
  • Brewgold2

    Brewgold2 - 2019-06-24

    Hi,
    With my last ("burnt") raspberry pi and before the reinstallation of codesys, the serial connections were functioning perfectly with many devises as well. Now with the new rapbewrry pi and the new version of the codesys software it is not possible to communicate with a Schneider ATV-12, data doesn`t get to the device, that way it is confirmed that there is no connection. Am I missing any library or were may be the error?
    Thanks for the help.

    IMG: Bild

    IMG: modbus1.jpg

     
  • eschwellinger

    eschwellinger - 2019-06-25

    Hi,
    everything in the same version ( mean CODESYS / CODESYS Runtime?)
    except the PI and Stretch whatever you use on this?

    BR
    Edwin

     
  • Brewgold2

    Brewgold2 - 2019-06-25

    SOLVED

    Hi Edwin:

    CodeSys V3.5 SP14 Patch 2
    Runtime V3.5 .14.20
    Raspberry Pi 3B
    Raspbian Buster 4.19

    BR

    Fernando

     
  • bizer

    bizer - 2020-04-01

    Hello together,

    I'm facing some issue with the internal connection (UART) of the Raspberry 3 and Codesys 3.5.15.SP4.
    If I read everything right internal interface GPIO 14/15 should work with RS 485.

    • Activate serial via raspi-config.
    • Unable bluethooth:
      $ echo 'dtoverlay=pi3-disable-bt' | sudo tee -a /boot/config.txt
      $ sudo systemctl disable hciuart
      Removed /etc/systemd/system/multi-user.target.wants/hciuart.service
      $ sudo reboot

    • add in sudo nano /etc/CODESYSControl.cfg
      Linux.Devicefile=/dev/ttyAMA or ttyS
      portnum := COM.SysCom.SYS_COMPORT1

    With AMA -->Modbus Master is green, but Slave doesn't connect...
    With ttyS--> Modbus Master is red...
    Communication via USB-RS485-Adapter works...

    Any hints or tipps what could be modified?

    Regards
    Benedikt

     
  • bizer

    bizer - 2020-04-10

    No one on this topic?

     
<< < 1 2 3 4 5 > >> (Page 4 of 5)

Log in to post a comment.