import request from '@/utils/request'
//获取设备id索引列表
export function getEquipmentIndexList() {
    return request({
        url: '/hnyz/param/getIndexList',
        method: 'get',
        headers: {
            'Content-Type': 'application/json'
        },
    })
}
//dataType:数据类型 (1线圈, 2浮点数, 3整型)
//functionCode:功能码 (1读线圈, 3读保持寄存器,4读输入寄存器)
//quantity:读取数量
//获取数据
export function getValues({ dataArr, startAddress }) {
    return request({
        url: '/modbus/getValues?data='+dataArr+'&slaveId=1&startAddress='+startAddress+'&dataType=1&functionCode=1&quantity=1',
        method: 'get',
        headers: {
            'Content-Type': 'application/json'
        },
    })
}

// 设置单个线圈
export function setCoil({ dataArr, startAddress }) {
    return request({
        url: '/modbus/setCoil?data='+dataArr+'&slaveId=1&startAddress='+startAddress+'&dataType=1&functionCode=1&quantity=1',
        method: 'post',
        headers: {
            'Content-Type': 'application/json' 
        },
    })
}

//设置多个线圈
export function setCoils({ dataArr, startAddress , quantity }) {
    return request({
        url: '/modbus/setCoils?data='+dataArr+'&slaveId=1&startAddress='+startAddress+'&dataType=1&functionCode=1&quantity='+quantity,
        method: 'post',
        headers: {
            'Content-Type': 'application/json' 
        },
    })
}

//设置单个整型
export function setIntRegister({ dataArr, startAddress }) {
    return request({
        url: '/modbus/setIntRegister?data='+dataArr+'&slaveId=1&startAddress='+startAddress+'&dataType=3&functionCode=3&quantity=1',
        method: 'post',
        headers: {
            'Content-Type': 'application/json' 
        },
    })
}

//设置单个浮点数
export function setFloatRegister({ dataArr, startAddress }) {
    return request({
        url: '/modbus/setFloatRegister?data='+dataArr+'&slaveId=1&startAddress='+startAddress+'&dataType=2&functionCode=3&quantity=1',
        method: 'post',
        headers: {
            'Content-Type': 'application/json' 
        },
    })
}