Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Write with ModbusMaster


cristian24 Jun 24, 2021 05:50 AM

Hi, I need to simply write to the "Holding Regs" registers with the ModbusMaster() statement, on a ModBus slave device. (with TCP/IP)

I have managed to read into those registers but not write to them, with the TCOpen() statement.


Please, can someone help me?


Sam Jul 5, 2021 06:36 PM

A Modbus server/slave 

Public ModbusReg(3)
Public ModbusCoil As Boolean

BeginProg

  ModbusSlave (502,0,1,ModbusReg,ModbusCoil,2)

  Scan (1,Sec,0,0)

    ModbusReg(1) = ModbusReg(1) + 1
    ModbusReg(2) = ModbusReg(2) + 0.1
    ModbusCoil = NOT ModbusCoil

  NextScan
EndProg

 

A Modbus client/master example

 

Public Handle As Long
Public ModbusReg(2)
Public ModbusRegWrite
Public Result As Long
Public Result2 As Long

BeginProg

  Scan (1,Sec,0,0)

    'open connection
    TCPOpen ("192.168.0.100",502,1000,7500,Handle,1)

    'read qty 2, 32 bit values starting at register 1
    ModbusMaster (Result,Handle,0,1,3,ModbusReg,1,2,1,100,2)

    ModbusRegWrite += 0.001
    'write qty 1, 32 bit value starting at register 5
    ModbusMaster (Result2,Handle,0,3,16,ModbusRegWrite,5,1,1,100,2)

  NextScan
EndProg

 

Log in or register to post/reply in the forum.