예제 #1
0
 private void btOpenClose_Click(object sender, EventArgs e)
 {
     if (null == _dev)
     {
         MessageBox.Show("打开设备失败!设备对象为空");
         return;
     }
     if (_dev.IsDeviceOpen)
     {
         int err = _dev.CloseDevice();
         if (err != 0)
         {
             MessageBox.Show("关闭设备失败,错误信息:" + _dev.GetErrorInfo(err));
             return;
         }
     }
     else
     {
         int err = _dev.OpenDevice();
         if (err != 0)
         {
             MessageBox.Show("打开设备失败,错误信息:" + _dev.GetErrorInfo(err));
             return;
         }
     }
     AdjustUI();
 }
        /// <summary>
        /// 打开所有轴设备
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btOpenAllDev_Click(object sender, EventArgs e)
        {
            if (null == _station)
            {
                return;
            }
            string[] axisNames = _station.AxisNames;
            if (null == axisNames || 0 == axisNames.Length)
            {
                ShowTips("工站 未提供轴/电机!");
                return;
            }
            bool isOK = true;

            foreach (string axisName in axisNames)
            {
                JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetAxisCellInfo(axisName);
                if (null == ci)
                {
                    isOK = false;
                    ShowTips("未发现轴 = \"" + axisName + "\"所属 通道信息!");
                    continue;
                }
                IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                if (null == dev)
                {
                    isOK = false;
                    ShowTips("未发现轴 = \"" + axisName + "\"所属 设备ID = \"" + ci.DeviceID + "\"!");
                    continue;
                }
                if (!dev.IsDeviceOpen)
                {
                    int errCode = dev.OpenDevice();
                    if (0 != errCode)
                    {
                        isOK = false;
                        ShowTips(string.Format("打开轴 = \"{0}\"所属设备=\"{1}\"失败,错误信息:{2}", axisName, ci.DeviceID, dev.GetErrorInfo(errCode)));
                        continue;
                    }
                    ShowTips(string.Format("轴 = \"{0}\"所属设备=\"{1}\"已打开 ", axisName, ci.DeviceID));
                }
            }
            if (isOK)
            {
                ShowTips("所有轴设备已打开");
            }
            LayoutStation();
        }
        private void btOpenAllDev_Click(object sender, EventArgs e)
        {
            if (null == _station)
            {
                ShowTips("打开所有DIO设备失败:工站未设置");
                return;
            }
            string[] diNames = _station.DINames;
            string[] doNames = _station.DONames;
            if ((null == diNames || 0 == diNames.Length) && (null == doNames || 0 == doNames.Length))
            {
                ShowTips("打开所有DIO设备失败:工站未设置DI/DO");
                return;
            }
            bool isOK = true;

            if (null != diNames)
            {
                foreach (string diName in diNames)
                {
                    JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDiCellInfo(diName);
                    if (null == ci)
                    {
                        isOK = false;
                        ShowTips("未发现DI = \"" + diName + "\"所属 通道信息!");
                        continue;
                    }
                    IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                    if (null == dev)
                    {
                        isOK = false;
                        ShowTips("未发现DI = \"" + diName + "\"所属 设备ID = \"" + ci.DeviceID + "\"!");
                        continue;
                    }
                    if (!dev.IsDeviceOpen)
                    {
                        int errCode = dev.OpenDevice();
                        if (0 != errCode)
                        {
                            isOK = false;
                            ShowTips(string.Format("打开DI = \"{0}\"所属设备=\"{1}\"失败,错误信息:{2}", diName, ci.DeviceID, dev.GetErrorInfo(errCode)));
                            continue;
                        }
                        ShowTips(string.Format("DI = \"{0}\"所属设备=\"{1}\"已打开 ", diName, ci.DeviceID));
                    }
                }
            }


            if (null != doNames)
            {
                foreach (string doName in doNames)
                {
                    JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDoCellInfo(doName);
                    if (null == ci)
                    {
                        isOK = false;
                        ShowTips("未发现DO = \"" + doName + "\"所属 通道信息!");
                        continue;
                    }
                    IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq;
                    if (null == dev)
                    {
                        isOK = false;
                        ShowTips("未发现DO = \"" + doName + "\"所属 设备ID = \"" + ci.DeviceID + "\"!");
                        continue;
                    }
                    if (!dev.IsDeviceOpen)
                    {
                        int errCode = dev.OpenDevice();
                        if (0 != errCode)
                        {
                            isOK = false;
                            ShowTips(string.Format("打开DO = \"{0}\"所属设备=\"{1}\"失败,错误信息:{2}", doName, ci.DeviceID, dev.GetErrorInfo(errCode)));
                            continue;
                        }
                        ShowTips(string.Format("DO = \"{0}\"所属设备=\"{1}\"已打开 ", doName, ci.DeviceID));
                    }
                }
            }
            if (isOK)
            {
                ShowTips("工站所有DIO设备已打开");
            }
            AdjustStationUI();
        }