Ejemplo n.º 1
0
        public void open()
        {
            #region 加载出对应的设备传感器集合
            string strFactoryId = "G01";
            AddressSets = DataLogHelper.GetPLCAddressSets(strFactoryId, _typeStr);
            #endregion
            //定义需要读取的寄存器数量
            Wrapper.RegCount = Convert.ToInt16(AddressSets.Count());

            Wrapper.Connect();
            try
            {
                _thread = new Thread(Receive)
                {
                    Name = _id.ToString()
                };
                _thread.Start();
                _status    = "服务连接中";
                _isRunning = true;

                ConnectSocketServer();
            }
            catch (Exception ex)
            {
                string errorStr = "[" + _name + "]" + "服务连接失败!" + ex.Message;
                MessageBox.Show(errorStr, "出错了", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 通过工厂和PLC机柜编号获取对应的传感器控制器的地址参数信息
        /// </summary>
        /// <param name="strFactoryId"></param>
        /// <param name="strPLCId"></param>
        /// <returns></returns>
        public static PLCAddressSetCollection GetPLCAddressSets(string strFactoryId, string strPLCId)
        {
            try
            {
                PLCAddressSetCollection addressSets = new PLCAddressSetCollection();
                string strSQL = "select * from p_plcaddressset where FactoryId=?FactoryId and PLC_Id=?PLC_Id";

                List <MySqlParameter> sqlParameters = new List <MySqlParameter>
                {
                    new MySqlParameter("?FactoryId", strFactoryId),
                    new MySqlParameter("?PLC_Id", strPLCId)
                };
                PLCAddressSet info = new PLCAddressSet();

                CreateDataList <PLCAddressSet>(addressSets, strSQL, sqlParameters, info, null);

                return(addressSets);
            }
            catch (Exception ex)
            {
                return(new PLCAddressSetCollection());
            }
        }