communication with Modbus slave

praveena
2014-03-28
2018-03-26
  • praveena - 2014-03-28

    Dear all,
    I am working on Codesys V3.5. I am using WIN V3 as my device.I want to communicate with a Modbus slave connected to my Workstation on the COM port.
    So I have successfully added IODrvModbus library to my project. I am able to view all the files in the library.
    I have added a MASTER COM port in my codesys project. Now as I have iodrvmodbus library added to my project,
    I have the following function blocks available

    a) IoDrvModbuscomport
    b) Modbus request
    c) Modbusrequest2
    d) ModbusSlavecomport

    Which one should I use in my PLC_PRG page ?Do I have to use all the blocks together
    

    2) Also, as a Modbus master, where do I mention Function Code, Slave id, no of bytes to read etc.

    Kindly guide

    Praveena

     
  • eschwellinger

    eschwellinger - 2014-03-29

    Hi,

    you do not need to call anything manually from the library all is done implicit by the config/ iodriver
    just generate the device configuration in the device tree, then add the mapping to your slave
    - use the IO variables that't it.
    BR
    E. Schwellinger

    IMG: Mapping.jpg

    IMG: ModbusSlave.jpg

     
  • Moun72 - 2015-09-30

    Hi all,

    Ok for Implicit configuration IODrv, but i have to access to 2000 registers with one register by channel. So, there isn't enough channels. I would like to set with a variable the offset shield. Or maybe use ModbusRequest FB from iodrvmodbus library. But i don't know how to find the hComPort (RTS_IEC_HANDLE)???? for this FB...

    IMG: ScreenShot.gif

     
  • gatto

    gatto - 2017-01-09

    Hi all,
    I'm on codesys 3.5 sp7 patch5 and I'm trying to use the ModbusRequest FB from iodrvmodbus library. But i don't know how to find the hComPort, me too like the user Moun72.

    I suppose my serial port is number 1 but if i try to put 1 directly to input of FB when i launch the command execute the system crash.

    Can someone help me ?
    thanks in advance

     
  • gatto

    gatto - 2017-01-10

    hello, i'm here again,
    After some days of search on google and here in this forum i don't find nothing about this function block.
    I can not believe no one has ever used this.
    And I can not believe that there is no information on this.
    No manual, no examples, nothing.
    Why ?

     
  • bjh - 2018-03-06

    I am also in need of some information on how to give the handle for my serial port to an instance of IoDrvModbus.ModbusRequest2.

    My Modbus device is set up poorly and as such I would need to create a channel for almost every word I need to write to. I've created a function block to pass in an offset and value and it will write to the modbus register. With ModbusTCP I have used ModbusRequest and it is working great but I now need to use the serial port for a different device with the same I/O layout.

     
  • mirasoft - 2018-03-08

    Since we had the same problems, we decided to develop our own Modbus library. This will be available in the CODESYS store in March. Hold on

     
  • bjh - 2018-03-19

    https://forum.codesys.com/viewtopic.php?f=11&t=8568&p=20894#p20894

    Mirasoft, I am very much looking forward to your library!

    I had to open the COM port first using the SysCom library - this returns the RTS_IEC_HANDLE for the port to pass into the ModbusRequest block.

    There is very, very little documentation on this...

    VAR
       modbusRequestSerial: IoDrvModbus.ModbusRequest2;
       modbusCommandSerial : IoDrvModbus.ModbusCommand;
       comm : IoDrvModbus.RTS_IEC_HANDLE;
       commSettings : SysCom.COM_Settings;
       pntResult : POINTER TO SysCom.RTS_IEC_RESULT;
    END_VAR
                      comm := SysCom.SysComOpen2(pSettings := ADR(commSettings),0, pResult:=pntResult);
                      modbusRequestSerial(
                         xExecute:= xExecute, 
                         xAbort:= , 
                         hComPort:= comm, 
                         usiSlaveAddr:= 32, 
                         modbusCommand:= modbusCommandSerial, 
                         tResponseTimeout:= , 
                         uiSendTimeout:= , 
                         pSendData:= ADR(servoOpcode), 
                         pRecvData:= , 
                         transmission:= , 
                         xDone=> xDone, 
                         xBusy=> , 
                         xError=> xError, 
                         xAborted=> , 
                         uiDataLength=> , 
                         byModbusError=> );
    
     
  • mirasoft - 2018-03-26

    bjh hat geschrieben:
    Mirasoft, I am very much looking forward to your library!

    It's done. Have a look at Universal Modbus Client/Master

     

Log in to post a comment.