Пример #1
0
        /// <summary>
        /// 连接网络设备
        /// </summary>
        public void LinkDevicesClient()
        {
            try
            {
                // 清空设备
                DataControl._mSocket.Close();
                // 获取设备设定档资讯
                String    sql = "select * from wcs_config_device where FLAG <> 'N' order by CREATION_TIME";
                DataTable dt  = DataControl._mMySql.SelectAll(sql);
                if (DataControl._mStools.IsNoData(dt))
                {
                    return;
                }
                List <WCS_CONFIG_DEVICE> devList = dt.ToDataList <WCS_CONFIG_DEVICE>();
                // 遍历加入网络设备
                foreach (WCS_CONFIG_DEVICE dev in devList)
                {
                    byte[] refreshB = null;
                    switch (dev.TYPE)
                    {
                    case DeviceType.固定辊台:
                        refreshB = FRT._GetData();
                        break;

                    case DeviceType.摆渡车:
                        refreshB = ARF._GetData();
                        break;

                    case DeviceType.行车:
                        refreshB = ABC._GetData();
                        break;

                    case DeviceType.运输车:
                        refreshB = RGV._GetData();
                        break;

                    default:
                        continue;
                    }
                    if (!DataControl._mSocket.AddClient(dev.DEVICE, dev.IP, dev.PORT, refreshB, out string result))
                    {
                        throw new Exception(result);
                    }
                }
            }
            catch (Exception ex)
            {
                // 记录LOG
                RecordTaskErrLog("LinkDevicesClient()", "连接网络设备", null, null, ex.ToString());
                MessageBox.Show("连接网络设备发生异常:" + ex.ToString(), "Error");
                System.Environment.Exit(0);
            }
        }