Esempio n. 1
0
        /// <summary>
        /// 添加写寄存器操作
        /// </summary>
        /// <param name="regDes"></param>
        /// <param name="regVal"></param>
        /// <returns></returns>
        public bool AddIoWrite(string regDes, int regVal)
        {
            try
            {
                if (!wIOVal.ContainsKey(regDes))
                {
                    return(false);
                }

                CWIOVal wIO = new CWIOVal(regDes, regVal);

                if (!wSetIOVal.Contains(wIO))
                {
                    wSetIOVal.Enqueue(wIO);

                    wIOVal[regDes] = -1;
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 写单个寄存器
        /// </summary>
        /// <param name="er"></param>
        /// <returns></returns>
        private bool writeIO(out string er)
        {
            er = string.Empty;

            try
            {
                ioWriteLock.AcquireWriterLock(-1);

                bool flag = true;

                for (int i = 0; i < wSetIOVal.Count;)
                {
                    bool regOk = true;

                    if (_dispose)
                    {
                        return(true);
                    }

                    CWIOVal wIO = wSetIOVal.Dequeue();

                    if (!wIOREG.ContainsKey(wIO.regDes))
                    {
                        er    = "[" + wIO.regDes + "]" + CLanguage.Lan("写操作错误") + ":" + CLanguage.Lan("该寄存器不存在");
                        flag  = false;
                        regOk = false;
                    }

                    string regKey = wIO.regDes;

                    int regVal = wIO.regVal;

                    Thread.Sleep(10);

                    if (!_devIO.Write(wIOREG[regKey].devAddr, wIOREG[regKey].regType, wIOREG[regKey].regAddr, regVal, out er))
                    {
                        Thread.Sleep(10);

                        if (!_devIO.Write(wIOREG[regKey].devAddr, wIOREG[regKey].regType, wIOREG[regKey].regAddr, regVal, out er))
                        {
                            er    = "[" + regKey + "]" + CLanguage.Lan("写操作错误") + ":" + er;
                            flag  = false;
                            regOk = false;
                        }
                    }

                    if (!regOk)
                    {
                        wSetIOVal.Enqueue(wIO);
                    }
                }
                return(flag);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
            finally
            {
                ioWriteLock.ReleaseWriterLock();
            }
        }