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

RevPi Connect RS485

2019-03-13
2023-12-11
  • hence.persson - 2019-03-13

    Hi. Having some troubles to get the RS485 port to work with Codesys.

    The device is a RevPi Connect which have a built in RS485 port. The port is accessible from terminal via /dev/ttyRS485.

    If I use this in the CodesysControl_User.cfg I only get bus failure in Codesys but if I use /dev/ttyUSB I get a green running.

    But I have some troubles getting the device to act as a Modbus RTU slave so I am wondering if maybe /dev/ttyUSB is wrong anyways. How can I check this?

     
  • hence.persson - 2019-03-13
    pi@RevPi11710:/dev $ dmesg | grep "tty"
    [    0.000000] Kernel command line: bcm2708_fb.fbwidth=640 bcm2708_fb.fbheight=480 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:4B:36:3A vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait nosplash plymouth.ignore-serial-consoles
    [    0.001842] console [tty1] enabled
    [    1.435344] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
    [    3.128774] systemd[1]: Created slice system-getty.slice.
    [    6.221504] usb 1-1.5.2: FTDI USB Serial Device converter now attached to ttyUSB0
    [    6.306834] usb 1-1.5.3: FTDI USB Serial Device converter now attached to ttyUSB1
    
    pi@RevPi11710:/dev $ ls
    autofs         cpu_dma_latency  gpiochip1  log    loop7             mmcblk0p1           piControl0  ram12  ram6    rtc0       stdout  tty14  tty21  tty29  tty36  tty43  tty50  tty58  tty8          uhid     vcs2   vcsa3      zero
    block          cuse             gpiochip2  loop0  loop-control      mmcblk0p2           ppp         ram13  ram7    serial     tty     tty15  tty22  tty3   tty37  tty44  tty51  tty59  tty9          uinput   vcs3   vcsa4
    btrfs-control  disk             gpiomem    loop1  mapper            mmcblk0rpmb         ptmx        ram14  ram8    serial0    tty0    tty16  tty23  tty30  tty38  tty45  tty52  tty6   ttyAMA0       urandom  vcs4   vcsa5
    bus            fb0              hwrng      loop2  mem               mqueue              pts         ram15  ram9    shm        tty1    tty17  tty24  tty31  tty39  tty46  tty53  tty60  ttyConBridge  vchiq    vcs5   vcsa6
    cachefiles     fd               i2c-1      loop3  memory_bandwidth  net                 ram0        ram2   random  snd        tty10   tty18  tty25  tty32  tty4   tty47  tty54  tty61  ttyprintk     vcio     vcs6   vcsm
    char           full             initctl    loop4  mmcblk0           network_latency     ram1        ram3   raw     spidev0.0  tty11   tty19  tty26  tty33  tty40  tty48  tty55  tty62  ttyRS485      vc-mem   vcsa   vhci
    char_dev       fuse             input      loop5  mmcblk0boot0      network_throughput  ram10       ram4   rfkill  stderr     tty12   tty2   tty27  tty34  tty41  tty49  tty56  tty63  ttyUSB0       vcs      vcsa1  watchdog
    console        gpiochip0        kmsg       loop6  mmcblk0boot1      null                ram11       ram5   rtc     stdin      tty13   tty20  tty28  tty35  tty42  tty5   tty57  tty7   ttyUSB1       vcs1     vcsa2  watchdog0
    
     

    Related

    Talk.ru: 1

  • hence.persson - 2019-03-13

    My CodesysControl_User.cfg

    [SysCom]
    Linux.Devicefile=/dev/ttyUSB
    portnum := COM.SysCom.SYS_COMPORT1;
    [CmpBlkDrvCom]
    ;Com.0.Name=MyCom
    ;Com.0.Baudrate=115200
    ;Com.0.Port=3
    ;Com.0.EnableAutoAddressing=1
    [SysProcess]
    Command.0=shutdown
    [CmpApp]
    Bootproject.RetainMismatch.Init=1
    Application.1=Application
    [CmpRasPi]
    Architecture=armv6l
    
     
  • hence.persson - 2019-03-13

    If I change for example baud rate from codesys then the baudrate changes for both /dev/ttyRS485 and /dev/ttyUSB0 so this seems fine.?

    Maybe there is something else that doesnt work. The Modbus Master is sending some data to me but I am not getting anything in Codesys and I have no faults. How do I proceed?

    Could it be that I havent bought the license yet as I am only testing the hardware? Shouldnt the bus function for 0,5h without license?

     
  • eschwellinger

    eschwellinger - 2019-03-16

    Hi,

    not sure,
    if you receive with the terminal on /dev/ttyRS485
    you should write:

    [SysCom]
    Linux.Devicefile=/dev/ttyRS485

    that's it, then it should work.

    BR
    Edwin

     
  • kevinl - 2022-10-31

    i did this recently. the solution is:
    [SysCom]
    Linux.Devicefile=/dev/ttyRS48 (remember, no 5 at the end!)

    then set com port in codesys to 6. that works

     
    • bossjosh21 - 2023-12-06

      Hi Sir Kevin. May I know how you came up with this solution. Im a bit confused but I tried to put this.
      [SysCom]
      Linux.Devicefile=/dev/ttyRS48 (remember, no 5 at the end!)
      then set com port in codesys to 6.
      It also works for me but want to know where did you get this. Thank you.

       
      • kevinl - 2023-12-11

        I figured this out on my own with this logic:

        usually the Serial port on a Raspberry pi is on /dev/ttyUSB0 then you need to set linux.DeviceFile=/dev/ttyUSB in codesys you then must set com port to 1 so i assumed codesys subtracts 1 from the number and adds this to the filename...
        (in code it would look like this:

        var
            comPort : byte := '1';
            linuxDevice : string := '/dev/ttyUSB';
            filename : string;
        end_var
        filename := concat(linuxDevice, (to_string(comPort-1));
        

        filaname then is /dev/ttyUSB0

        RevPi uses ttyRS485 as Serial port so you must remove the last number from the name and set the com port to this number +1

        i hope this is understandable ;-)

         

        Last edit: kevinl 2023-12-11

Log in to post a comment.