AIOAIManager.cs 1.8 KB
using Asa.IOModule;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
 public   class AIOAIManager:AIManager
    {
        private   object AILock = ""; 
        private   int AILength = 4;
        private   Asa.IOModule.AIOBOX AiBox = null; 
        public override void StartConnect(params string[] ipList)
        { 
            foreach (string ip in ipList)
            {
                bool result = ConnectionIP(ip);
            } 
        }
        private bool ConnectionIP(string ioIp)
        {
            int autoMS = 150;
            try
            {
                AiBox = new Asa.IOModule.AIOBOX();
                AiBox.IP = ioIp;
                AiBox.SetType(Asa.IOModule.Box_Type.AI, AILength, Box_Type.AO, 0);
                LogUtil.debug("开始连接AI模块[" + ioIp + "][" + autoMS + "],尝试重连三次");
                bool result = AiBox.Connect();
            }
            catch (Exception error)
            {
                LogUtil.error("连接IO模块[" + ioIp + "][" + autoMS + "]出错:" + error.ToString());
            }
            return false;
        } 
        public override void CloseConnect()
        {
            try
            {
                if (AiBox != null)
                {
                    AiBox.Close();
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("断开AI连接出错:" + ex.ToString());
            }
        }


        public override double GetAIValue(string ioiP, int index)
        {
            if (AiBox != null)
            {
                return AiBox.ReadAI(index);
            }
            return -1;

        } 
    }
}