Beijer Electronics (formerly QSI Corporation)
http://qsiforums.com/

MBSlaveV2: RegisterValueChanged, and CoilValueChanged Events
http://qsiforums.com/viewtopic.php?f=20&t=3850
Page 1 of 1

Author:  Ron L. [ Wed Jun 17, 2009 9:52 am ]
Post subject:  MBSlaveV2: RegisterValueChanged, and CoilValueChanged Events

Here is some sample code of how you might use the RegisterValueChanged, and CoilValueChanged events of the MBSlaveV2 object. This is only if your going to use the Qlarity-based terminal as a Modbus slave. If your going to use the terminal as a Modbus master, than see this tutorial:
http://www.qsicorp.com/pdf/?id=appnote/ ... bus_master

Code:
func RegisterValueChanged(register as unibyte, length as unibyte)
    dim i as integer
    dim tmpF as float
    dim tmpI as integer

    'each register is 16 bits, reading two registers for 32 bit variables
    for i = register to register+length-1 step 2
        if register == 1 then
            tmpF := me.GetRegisterFloat(true, register)
            label_1.value = _formatFloat(tmpF, 0, 2, _FLOAT_NORMAL)
        elseif register == 3 then
            tmpI := me.GetRegisterInteger(true, register)
            label_2.value = str(tmpI)
        endif
    next
endfunc


Code:
func CoilValueChanged(coil as unibyte, length as unibyte)
    dim i as integer

    for i = coil to coil+length-1
        if coil == 1 then
            checkbox_1.isChecked = me.GetCoil(true, coil)
        elseif coil == 2 then
            'etc...
        endif
    next
endfunc

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/