Ejemplo n.º 1
0
        /// <summary>
        /// 设置I2C运行参数
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="para"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool SetRunPara(int addr, CI2C_RunPara para, out string er)
        {
            er = string.Empty;

            try
            {
                if (!_Mon.ContainsKey(addr))
                {
                    er = "I2C地址[" + addr.ToString("D2") + "不存在";
                    return(false);
                }

                _Mon[addr].Para.wRunPara = para.Clone();

                _Mon[addr].Para.wRunPara_OP = EOP.写入;

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
            finally
            {
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 复制
        /// </summary>
        /// <returns></returns>
        public CI2C_RunPara Clone()
        {
            CI2C_RunPara para = new CI2C_RunPara();

            para.PlaceType = this.PlaceType;

            para.ReadType = this.ReadType;

            para.ScanCycle = this.ScanCycle;

            para.ACONDelay = this.ACONDelay;

            para.RunI2CType = this.RunI2CType;

            para.RdCmdNum = this.RdCmdNum;

            para.I2C_Addr = this.I2C_Addr;

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

            return(para);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 读取I2C运行参数
        /// </summary>
        /// <param name="wAddr"></param>
        /// <param name="para"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool ReadI2C_RunPara(int wAddr, ref CI2C_RunPara para, out string er)
        {
            er = string.Empty;

            try
            {
                string cmd0 = "02";

                string cmd1 = "08";

                string wCmd = cmd0 + cmd1;

                string wData = string.Empty;

                wData = CalDataFromDDCmd(wAddr, wCmd, wData);

                string rData = string.Empty;

                int rLen = 13 + 3 * 0;

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

                para.PlaceType = (EPlace)System.Convert.ToInt16(rData.Substring(0, 2), 16);

                para.ReadType = (EReadType)System.Convert.ToInt16(rData.Substring(2, 2), 16);

                para.ScanCycle = System.Convert.ToInt16(rData.Substring(4, 2), 16);

                para.ACONDelay = System.Convert.ToInt16(rData.Substring(6, 2), 16);

                para.RunI2CType = (EModel)System.Convert.ToInt16(rData.Substring(8, 2), 16);

                para.RdCmdNum = System.Convert.ToInt16(rData.Substring(10, 2), 16);

                for (int i = 0; i < para.RdCmdNum; i++)
                {
                    para.I2C_Addr = rData.Substring(12 + i * 6, 2);

                    para.Cmd[i].CmdOP = rData.Substring(14 + i * 6, 2);

                    para.Cmd[i].RegNo = rData.Substring(14 + i * 6, 2);
                }

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 设置I2C运行参数
        /// </summary>
        /// <param name="wAddr"></param>
        /// <param name="para"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool SendToSetI2C_RunPara(int wAddr, CI2C_RunPara para, out string er)
        {
            er = string.Empty;

            try
            {
                string cmd0 = "01";

                string cmd1 = "04";

                string wCmd = cmd0 + cmd1;

                string wData = string.Empty;

                wData += ((int)para.PlaceType).ToString("X2");

                wData += ((int)para.ReadType).ToString("X2");

                wData += para.ScanCycle.ToString("X2");

                wData += para.ACONDelay.ToString("X2");

                wData += ((int)para.RunI2CType).ToString("X2");

                wData += para.RdCmdNum.ToString("X2");

                for (int i = 0; i < para.RdCmdNum; i++)
                {
                    wData += para.I2C_Addr;
                    wData += para.Cmd[i].CmdOP;
                    wData += para.Cmd[i].RegNo;
                }

                wData = CalDataFromDDCmd(wAddr, wCmd, wData);

                string rData = string.Empty;

                int rLen = 8;

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

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 读取I2C设置参数状态
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        private bool readRunPara(int addr, out string er)
        {
            er = string.Empty;

            try
            {
                _syncLock.AcquireWriterLock(-1);

                CI2C_RunPara para = new CI2C_RunPara();

                Thread.Sleep(_delayMs);

                if (!_devMon.ReadI2C_RunPara(addr, ref para, out er))
                {
                    Thread.Sleep(_delayMs);

                    if (!_devMon.ReadI2C_RunPara(addr, ref para, out er))
                    {
                        er = _Mon[addr].ToString() + "读参数;";
                        return(false);
                    }
                }

                _Mon[addr].Para.rRunPara = para.Clone();

                _Mon[addr].Para.rRunPara_OP = EOP.读取OK;

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
            finally
            {
                _syncLock.ReleaseWriterLock();
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 读取I2C运行参数
 /// </summary>
 /// <param name="wAddr"></param>
 /// <param name="para"></param>
 /// <param name="er"></param>
 /// <returns></returns>
 public bool ReadI2C_RunPara(int wAddr, ref CI2C_RunPara para, out string er)
 {
     return(_devMon.ReadI2C_RunPara(wAddr, ref para, out er));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 设置I2C运行参数
 /// </summary>
 /// <param name="wAddr"></param>
 /// <param name="para"></param>
 /// <param name="er"></param>
 /// <returns></returns>
 public bool SendToSetI2C_RunPara(int wAddr, CI2C_RunPara para, out string er)
 {
     return(_devMon.SendToSetI2C_RunPara(wAddr, para, out er));
 }