Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

How to connect serial devices ?

PLC
2014-04-02
2024-01-06
1 2 3 .. 6 > >> (Page 1 of 6)
  • PLC - 2014-04-02

    The Raspberry Pi has many interfaces and the 3S Target support many of them.
    But how connect simple serial devices ?

    On the pole pin connector of the raspberry pi there are these serial signals.
    With the additional RasPiComm board these signals are available on a DSUB9 RS232 interface connector.
    Do the 3S Target support this now or in the future ?

    Is it possible to use the 2 USB Ports with "PL2303HX USB to TTL UART RS232 COM Kabel-Modul Converter" to connect simple serial devices ?

     
  • eschwellinger

    eschwellinger - 2014-04-04

    Hi,

    this works already but you need to add your configuration:

    1. you need to check on linux side which tty port is available.

    For my tests I've used a USB to serial converter:
    Check under Linux with 'dmesg' which port is used:

    in my case it reports: ttyUSB0

    so you need to add in /etc/CODESYSControl.cfg
    (Attention you need to remove the 0 from USB0)

    [SysCom]Linux.Devicefile=/dev/ttyUSB
    this was the pi side under Linux

    1. then after reboot or restart plc, you could communicate via serial com from your IEC application see attached screenshot and attached projectarchive (this is an
      application example from store slightly modified)

    BR
    Edwin

    IMG: serialExample.jpg

    IMG: dmesg.jpg

    SerialComWithVisuRaspi.projectarchive [7.18 MiB]

     
    πŸ‘
    2
    • qaz478566 - 2021-02-01

      Can COM be changed?

       
  • PLC - 2014-04-14

    Thank you Edwin !

    I use a PL2303 usb-serial-adapter together with your example project and the standard configuration is working well.

    But if I change the Baud rate to 300 Bd (exactly 1200 Bd or slower) the comOpen method throws an UNKNOWN_ERROR.
    I need the 300 Baud to communicate with an IEC61107 electronic meter.

    Do you have a solution ?
    At the moment I don't know if it is a problem of the usb-serial-adapter, the RPI or in the CODESYS function block ?

    Thank you for your support.

    BR Martin

     
  • eschwellinger

    eschwellinger - 2014-04-15

    Hi Martin,

    could you please check if These baudrates are possible with plain Linux use?

    configure
    stty -F /dev/ttyUSB0 1200
    stty -F /dev/ttyUSB0 raw

    now read from the port by:
    cat /dev/ttyUSB0

    sending:

    echo Hello Raspberry > /dev/ttyUSB0

    or use a terminal on Linux:

    sudo apt-get install minicom

    minicom -b 1200 -D /dev/ttyUSB0

    Let me know the results of this tests,
    if this works on your Pi, this should be a problem in the libraries.

    BR
    Edwin

     
  • PLC - 2014-04-16

    Hello Edwin,

    I tried your recommendations, but there was no responds on cat /dev/ttyUSB0 (see attachments).
    Does this work on your raspberry ?

    The identical CODESYS program ist running on a WinV3 soft plc with 300 Baud.
    Therefore I think the USB-Serial-Adapter isn't the problem.

    Do you have any further ideas (after easter hollidays) ?

    Best Regards Martin

    IMG: Bd1200.jpg

    IMG: Bd2400.jpg

    IMG: BdRaw.jpg

    IMG: BdMinicom9600.jpg

     
  • eschwellinger

    eschwellinger - 2014-04-17

    Hi Martin,

    in my case it works under Linux see screenshot,
    anyway it seems there is a problem in CODESYS.
    We need to investigate this.

    BR Edwin

    IMG: 300baud.jpg

     
  • eschwellinger

    eschwellinger - 2014-04-17

    Hi Martin,

    i've added an JIRA for this at the moment baudrate below 4800 are not possible.
    Could you change the reciving device to an hight baudrate as a workaround?

    BR
    Edwin

     
  • PLC - 2014-04-17

    Yet I can also reproduce this.
    I agree Raspberry Serial communication on 300 Baud is possible, but CODESYS below 4800 Baud not (on a raspberry only).

    I can't change the baud rate of the corresponding device, because it's an electonic meter from EON Westfalen Weser .
    IEC61107 electronic meter get requests with 300 Baud and answer with 9600 Baud.
    This challange is handled by my codesys program and is running successfully on a WinV3 soft plc but I wan't do it on a raspberry ...

    Thank you for your Support and maybe for the bugfix in the future.

    BR Martin

     
  • switcher - 2014-04-23

    Hi,

    I tested USB/RS-485 adapter. I set up Raspberry just like Edwin described. It works perfectly from the start. I tested modbus RTU communication with room thermostat.

    There is only one thing which I don't like. If I break connection on RS-485 side (I leave USB adapter connected in Rpi), bus goes to Failure status:

    But even if I connect RS-485 line again, bus don't recover. Only Rpi reboot helps.
    Is there a way to auto recover the bus after failure?

    Thank you.
    Best regards,
    Zdenko.

    IMG: Bild

     
  • eschwellinger

    eschwellinger - 2014-04-24

    Hi,

    check if:

    Device.Application.Modbus_Master_COM_Port.xResetComPort
    Device.Application.Slave3.xReset

    does solve the restart problem.

    BR
    Edwin

    IMG: ModBusRTURestart.jpg

     
  • switcher - 2014-04-24

    Thank you Edwin,

    yes, Device.Application.Slave3.xReset does helps. Modbus communication works ok after reset. How can we make this works automatically?

    I think, Modbus RTU should work also in this case:
    -PLC as a Modbus master
    -10x modbus slave devices on the same RS-485 bus.
    -If one of this 10 slave devices won't respond, the communication with other devices should work normally.
    -Also if some slave device will not reply to one specific request from master, master should repeat this request (number of retries).

    Regarding this, is there a usable solution to make this work properly?

    Best regards,
    Zdenko.

     
  • eschwellinger

    eschwellinger - 2014-04-24

    Hi Zdenko,

    this is a open point which will be fixed to 3.5SP5 (release July 2014).

    At the moment you need to do this manually in the application.
    How?
    The Workaround is, always to check modbus error in modbus master function block and if error happens, restart the communication
    BR
    Edwin

     
  • switcher - 2014-04-24

    Hi Edwin,

    thank you.

    I am trying this declaration:
    IF Device.Application.Modbus_Slave_COM_Port.xError THEN
    Device.Application.Modbus_Slave_COM_Port.xReset := TRUE;
    END_IF

    But I think I am not doing this right. I get this exception:
    [ERROR] MB485_230414: PLC_PRG Device: Plc Logic: Application: C0062: 'Device.Application.Modbus_Slave_COM_Port' is no structured variable

    I also tried with FBD, but I also don't find Modbus master FB. Can you point me in the right direction, please.

    I understand that you will integrate the additional Modbus RTU master functionality in version V3.5. So this means, that this problem is in all controllers which uses Codesys for programming?

    Best regards,
    Zdenko.

     
  • eschwellinger

    eschwellinger - 2014-04-24

    Hi,

    IF Modbus_Slave_COM_Port.xError THEN
    Modbus_Slave_COM_Port.xReset := TRUE;
    END_IF

    BR
    Edwin

     
  • switcher - 2014-04-24

    Hi,

    thank you. This works.

    Is there a way to read and write the same Modbus holding register to the same Raspberry variable? This have to used if we like to change some modbus slave setpoint on the both devices (master and slave).

    Best regards,
    Zdenko.

     
  • eschwellinger

    eschwellinger - 2014-04-24

    Hi Zdenko,

    check this:

    l viewtopic.php?f=21&t=5713#p10314 l

    this should work for modbus_rtu too (sure with the modbus serial fb too)

    BR
    Edwin

     
  • switcher - 2014-04-24

    Hi Edwin,

    In this case Raspberry have to be Modbus master. Can we use the same FB here?

    Best regards,
    Zdenko

     
  • GunnarK - 2014-06-16

    Hello

    I am trying to use Edwins project SerialComWithVisuRaspi.projectarchive.

    I want to use the Pi’s internal serial port, I guess this is ttyAMA0.
    Where can I allocate ttyAMA0 to the project. By now I am getting the message UNKNOWN_ERROR, and now data at the serial port.

    Can anyone help me in the right direction here?

    "Edit":
    I se that I have used ttyAMA0 insted og ttyAMA in the config file /etc/CODESYSControl.cfg:

    Data is now sendt from the Pi and CoDeSys. But it seems like the baudrate is wrong. Do I have to configure the baudrate also in the /etc/CODESYSControl.cfg file?

     
  • eschwellinger

    eschwellinger - 2014-06-19

    Hi,
    which baudrate are you using exactly?
    there is a problem on baudrates <2400, this will be fixed in the next version..
    coming with 3.5SP5 release which should be on July.

    BR
    Edwin

     
  • switcher - 2014-08-07

    Hi,

    Is there a fix for auto reconnection on RS-485 after COM error in version 3.5.SP5?

    Best regards,
    Zdenko.

     
  • eschwellinger

    eschwellinger - 2014-08-07

    Hi Zdenko,

    I would give a yes 'auto-restart communication'

    BR
    Edwin

    IMG: modbus_autorestart.jpg

     
  • switcher - 2014-08-08

    Hi,

    yes, it works !
    Thank you Edwin.

    Best regards,
    Zdenko.

     
  • PLC - 2014-08-29

    Hello,

    Edwin has described how to connect one serial device and it works well.

    Edwin Schwellinger hat geschrieben:
    this works already but you need to add your configuration:
    1. you need to check on linux side which tty port is available.
    For my tests I've used a USB to serial converter:
    Check under Linux with 'dmesg' which port is used:
    in my case it reports: ttyUSB0
    so you need to add in /etc/CODESYSControl.cfg
    (Attention you need to remove the 0 from USB0)
    [SysCom]
    Linux.Devicefile=/dev/ttyUSB
    portnum := COM.SysCom.SYS_COMPORT1;
    this was the pi side under Linux
    2. then after reboot or restart plc, you could communicate via serial com from your IEC application

    What I have to do to connect a second serial device in parallel ?
    If I plug the second device then it known (using dmesg) as ttyUSB1.
    How the changes in the CODESYSControl.cfg looks like to use two Serial devices in paralell ?

    Thank you for your Support !

     
  • switcher - 2014-09-02

    Hi,

    I have a same question - how can I use two Serial devices in parallel (with USB-serial adapter)?

    Thank you!

    Best regards,
    Zdenko.

     
1 2 3 .. 6 > >> (Page 1 of 6)

Log in to post a comment.