示例#1
0
        /// <summary>
        /// 获取当前的通讯设备
        /// </summary>
        /// <returns></returns>
        public IDeviceCore GetCurDeviceCore()
        {
            IDeviceCore deviceCore = DeviceCores.FirstOrDefault();

            if (CommParam.CommInterface == DeviceCommInterface.CNC_Fanuc)          //Faunc CNC 线程
            {
                string threadID = Thread.CurrentThread.ManagedThreadId.ToString(); //按照线程分别建立ID

                foreach (var device in DeviceCores)
                {
                    FocasManager focasDevice = device as FocasManager;

                    if ((focasDevice != null) && (focasDevice.CurThreadID == threadID))  //线程相同
                    {
                        return(device);
                    }
                }

                for (int i = DeviceCores.Count - 1; i >= 3; i--)
                {
                    DeviceCores[i].Dispose();
                    DeviceCores.RemoveAt(i);
                }

                #region 创建新的通讯

                deviceCore = new FocasManager(this, CallBack);

                if (!DeviceHelper.CommDevices.Contains(this))
                {
                    DeviceHelper.CommDevices.Add(this);                                           //添加到通讯设备中
                }
                DeviceCores.Add(deviceCore);

                #endregion
            }

            return(deviceCore);
        }
示例#2
0
        /// <summary>
        /// 初始化设备
        /// </summary>
        /// <param name="divDeviceTagParams"></param>
        /// <param name="callback"></param>
        public IDeviceCore InitialDevice(List <DeviceTagParam> divDeviceTagParams, DataChangeEventHandler callback) //初始化设备
        {
            DeviceTags = divDeviceTagParams;
            CallBack   = callback;

            IDeviceCore deviceCore = null;

            #region 初始化主通讯设备

            switch (CommParam.CommInterface)
            {
            case DeviceCommInterface.CNC_Fanuc:     //Fanuc CNC
                deviceCore = new FocasManager(this, callback);
                break;

            case DeviceCommInterface.FanucRobot:      //Fanuc机器人
                deviceCore = new ModbusTCPManager(this, callback);
                break;

            case DeviceCommInterface.ModulaTCP:      //Modula 自动货柜
                deviceCore = new SocketClientManager(this, callback);
                break;

            case DeviceCommInterface.ABPLC:      //Modula 自动货柜
                deviceCore = new HslAllenBradleyNetManager(this, callback);
                break;

            case DeviceCommInterface.ZeissTCP:      //蔡司 三坐标
                int    serverIndex = this.CommParam.CommAddress.IndexOf('|', 0);
                string serverAdd   = this.CommParam.CommAddress.Substring(serverIndex + 1);
                serverIndex = serverAdd.IndexOf('|', 0);
                serverAdd   = serverAdd.Substring(serverIndex + 1);
                DeviceManager deviceComm = new DeviceManager(this.DevicePKNO + "_S", DeviceCommInterface.ZeissTCP, serverAdd);
                deviceCore = new SocketClientManager(this, callback);
                var serverManager = new SocketServerManager(deviceComm, callback);      //新的Server端
                break;

            case DeviceCommInterface.OPC_Classic:     //OPC Server
                //deviceCore = new OpcClassicManager(this, callback);
                break;

            case DeviceCommInterface.TCP_Custom:      //自定义TCP协议
                deviceCore = new SocketClientManager(this, callback);
                break;

            case DeviceCommInterface.TCP_Modbus:      //Modbus TCP
                deviceCore = new ModbusTCPManager(this, callback);
                break;

            case DeviceCommInterface.TCP_Server:      //TCP 服务器
                deviceCore = new SocketServerManager(this, callback);
                break;

            case DeviceCommInterface.WebApi:      //WebApi
                deviceCore = new WebApiManager(this, callback);
                break;

            case DeviceCommInterface.DataBase:     //数据库通讯
                deviceCore = new DatabaseManager(this, callback);
                break;

            case DeviceCommInterface.ShareFile:     //数据库通讯
                deviceCore = new CopyFileManager();
                break;
            }

            #endregion

            if (deviceCore != null)
            {
                if (!DeviceHelper.CommDevices.Contains(this))
                {
                    DeviceHelper.CommDevices.Add(this);                                           //添加到通讯设备中
                }
                DeviceCores.Add(deviceCore);
            }

            return(deviceCore);
        }