_ENCRYPT_=0    --LUA脚本加密

--数据类型定义
VT_LW = 1    --变量地址
VT_RW = 2    --FLASH存储
VT_0x = 10   --线圈
VT_1x = 11   --输入点
VT_3x = 12   --输入寄存器
VT_4x = 13   --保持寄存器

function on_init()
    set_uint16(VT_LW, 0x6010, 0xFFFF)
end


function on_run(screen)

end

function on_press(state, x, y)

end

function on_update(slave,vtype,addr)

    if vtype == VT_0x
    then
        if addr == 0x0000
        then
            set_bit(VT_0x, 0x0001, get_bit(VT_0x, 0x0000))
        end
    end

    if vtype == VT_LW
    then
        if addr == 0x1000
        then
            set_uint16(vtype, addr+1, get_uint16(vtype, addr))

        elseif addr == 0x1002
        then
            set_int16(vtype, addr+1, get_int16(vtype, addr))

        elseif addr == 0x1004
        then
            set_uint32(vtype, addr+2, get_uint32(vtype, addr))

        elseif addr == 0x1008
        then
            set_int32(vtype, addr+2, get_int32(vtype, addr))

        elseif addr == 0x100C
        then
            print('0x'..((string.format('%04X', addr)))..' = '..(string.format('%016X', get_uint64(vtype, addr))))
            set_uint64(vtype, addr+4, get_uint64(vtype, addr))
            print('0x'..((string.format('%04X', (addr + 4))))..' = '..(string.format('%016X', get_uint64(vtype, (addr + 4)))))

        elseif addr == 0x1014
        then
            set_int64(vtype, addr+4, get_uint64(vtype, addr))

        elseif addr == 0x101C
        then
            set_float(vtype, addr+2, get_float(vtype, addr))

        elseif addr == 0x1020
        then
            set_double(vtype, addr+4, get_double(vtype, addr))

        elseif addr == 0x1030
        then
            set_string(vtype, addr+16, get_string(vtype, addr))

        elseif addr == 0x1050 and get_uint16(vtype, addr) % 2 == 0
        then
            set_uint16_ex(vtype, 0x1060,1,2,3,4,5,6,7,8,9,10)

        elseif addr == 0x1051 and get_uint16(vtype, addr) % 2 == 0
        then
            local ex_buff = {}
            for i = 1, 10
            do
                ex_buff[i] = i*10
            end
            set_array(vtype, 0x1060, ex_buff)
        end
    end
end


function on_draw(screen_id,control_id)
end

