using Common.Attributes;
using DeviceCommand.Base;
using Model.Models;
using NModbus;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceCommand.Devices
{
    //[ACPCommand]
    public class IOBoard : ModbusTcp
    {
        
        public IOBoard(TcpConfig config) : base(config)
        {
           
        }


        public async Task 写输出开关(byte 站号, ushort 开始地址, bool data)
        {
            await Modbus.WriteSingleCoilAsync(站号, 开始地址, data);
        }
        public async Task 批量写输出开关(byte 站号, ushort 开始地址, bool[] datas)
        {
            var 批量写入 = await Modbus.ReadCoilsAsync(1, 0, 16);
            for (int i = 0; i < datas.Length; i++)
            {
                if (开始地址 + i < 批量写入.Length)
                {
                    批量写入[开始地址 + i] = datas[i];
                }
            }
            await Modbus.WriteMultipleCoilsAsync(站号, 0, 批量写入);
        }
        public async Task 读输出开关(byte 站号, ushort 开始地址)
        {
            await Modbus.ReadCoilsAsync(站号, 开始地址, 1);
        }
        public async Task<bool[]> 批量读输出开关(byte 站号, ushort 开始地址,ushort 数量)
        {
            return await Modbus.ReadCoilsAsync(站号, 开始地址, 数量);
        }
    }
}
