예제 #1
0
        /// <summary>
        /// 读取I2C数据
        /// </summary>
        /// <param name="wAddr"></param>
        /// <param name="uutNo">产品1或产品2</param>
        /// <param name="data"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool ReadI2C_Data(int wAddr, int uutNo, ref CI2C_Data data, out string er)
        {
            er = string.Empty;

            try
            {
                string cmd0 = "02";

                string cmd1 = uutNo.ToString("X2");

                string wCmd = cmd0 + cmd1;

                string wData = string.Empty;

                wData = CalDataFromDDCmd(wAddr, wCmd, wData);

                string rData = string.Empty;

                int rLen = 9 + 4 * data.CmdNum;

                if (!SendCmdToDDLoad(wData, rLen, out rData, out er))
                {
                    return(false);
                }

                int sgnVal = System.Convert.ToInt16(rData.Substring(0, 2));

                if ((sgnVal & (1 << 3)) == (1 << 3))
                {
                    data.AC_ONOFF = 1;
                }
                else
                {
                    data.AC_ONOFF = 0;
                }

                if (data.CmdNum == 0)
                {
                    data.CmdNum = (rData.Length / 2 - 1) / 4;
                }

                for (int i = 0; i < data.CmdNum; i++)
                {
                    data.Val[i].CmdNo = System.Convert.ToInt16(rData.Substring(2 + 8 * i, 2));

                    data.Val[i].RdStatus = System.Convert.ToInt16(rData.Substring(4 + 8 * i, 2));

                    data.Val[i].RdByte0 = System.Convert.ToInt16(rData.Substring(6 + 8 * i, 2));

                    data.Val[i].RdByte1 = System.Convert.ToInt16(rData.Substring(8 + 8 * i, 2));
                }

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// 读取I2C数据状态
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        private bool readSignal(int addr, out string er)
        {
            er = string.Empty;

            try
            {
                _syncLock.AcquireWriterLock(-1);

                if (_Mon[addr].Para.wRunPara.PlaceType == EPlace.只有左边产品 || _Mon[addr].Para.wRunPara.PlaceType == EPlace.两边都有产品)
                {
                    CI2C_Data data = new CI2C_Data();

                    Thread.Sleep(_delayMs);

                    if (!_devMon.ReadI2C_Data(addr, 1, ref data, out er))
                    {
                        Thread.Sleep(_delayMs);

                        if (!_devMon.ReadI2C_Data(addr, 1, ref data, out er))
                        {
                            er = _Mon[addr].ToString() + "读数据1;";
                            return(false);
                        }
                    }

                    _Mon[addr].Para.RunData[0] = data.Clone();
                }

                if (_Mon[addr].Para.wRunPara.PlaceType == EPlace.只有右边产品 || _Mon[addr].Para.wRunPara.PlaceType == EPlace.两边都有产品)
                {
                    CI2C_Data data = new CI2C_Data();

                    Thread.Sleep(_delayMs);

                    if (!_devMon.ReadI2C_Data(addr, 2, ref data, out er))
                    {
                        Thread.Sleep(_delayMs);

                        if (!_devMon.ReadI2C_Data(addr, 2, ref data, out er))
                        {
                            er = _Mon[addr].ToString() + "读数据2;";
                            return(false);
                        }
                    }

                    _Mon[addr].Para.RunData[1] = data.Clone();
                }

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
            finally
            {
                _syncLock.ReleaseWriterLock();
            }
        }
예제 #3
0
        /// <summary>
        /// 复制
        /// </summary>
        /// <returns></returns>
        public CI2C_Data Clone()
        {
            CI2C_Data para = new CI2C_Data();

            para.CmdNum = this.CmdNum;

            para.AC_ONOFF = this.AC_ONOFF;

            for (int i = 0; i < 20; i++)
            {
                para.Val[i] = this.Val[i].Clone();
            }

            return(para);
        }
예제 #4
0
 /// <summary>
 /// 读取I2C数据
 /// </summary>
 /// <param name="wAddr"></param>
 /// <param name="uutNo">产品1或产品2</param>
 /// <param name="data"></param>
 /// <param name="er"></param>
 /// <returns></returns>
 public bool ReadI2C_Data(int wAddr, int uutNo, ref CI2C_Data data, out string er)
 {
     return(_devMon.ReadI2C_Data(wAddr, uutNo, ref data, out er));
 }