Ejemplo n.º 1
0
        /// <summary>
        /// 回读负载设定
        /// </summary>
        /// <param name="wAddr"></param>
        /// <param name="loadVal"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool ReadLoadSet(int wAddr, out CERS_Load loadVal, out string er)
        {
            er = string.Empty;

            loadVal = new CERS_Load();

            try
            {
                string cmd0  = "84";
                string wData = string.Empty;
                wData = CalDataFromERS272Cmd(wAddr, cmd0, wData);
                string rData = string.Empty;
                int    rLen  = 15;
                if (!SendCmdToERS272(wData, rLen, out rData, out er))
                {
                    return(false);
                }
                string rVal = string.Empty;
                if (!checkErrorCode(rData, out rVal, out er))
                {
                    return(false);
                }
                for (int i = 0; i < 4; i++)
                {
                    int valTemp = System.Convert.ToInt32(rVal.Substring(i * 4, 4), 16);
                    loadVal.cur[i] = ((double)valTemp) / 1024;
                }
                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 设置所有负载通道电流
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="load"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        public bool SetAllLoad(int addr, CERS_Load load, out string er, bool saveEPROM = true)
        {
            er = string.Empty;

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

                for (int i = 0; i < load.cur.Length; i++)
                {
                    _Mon[addr].Para.SetAllLoad.LoadSet[i] = load.cur[i];
                }

                _Mon[addr].Para.SetAllLoad.saveEPROM = saveEPROM;

                _Mon[addr].Para.SetAllLoad.op = EOP.写入;

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
            finally
            {
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 读取负载电流
        /// </summary>
        /// <param name="wAddr"></param>
        /// <param name="dataVal"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool ReadData(int wAddr, out CERS_Load dataVal, out string er)
        {
            er = string.Empty;

            dataVal = new CERS_Load();

            try
            {
                string cmd0  = "12";
                string wData = wAddr.ToString("X2");
                wData = CalDataFromERS272Cmd(wAddr, cmd0, wData);
                string rData = string.Empty;
                int    rLen  = 48;
                if (!SendCmdToERS272(wData, rLen, out rData, out er))
                {
                    return(false);
                }

                string rVal = string.Empty;
                if (!checkErrorCode(rData, out rVal, out er))
                {
                    return(false);
                }

                int valTemp = 0;

                valTemp         = System.Convert.ToInt16(rVal.Substring(0, 4), 16);
                dataVal.volt[0] = ((double)valTemp) * 320 / 4096;

                valTemp         = System.Convert.ToInt16(rVal.Substring(4, 4), 16);
                dataVal.volt[1] = ((double)valTemp) * 320 / 4096;

                valTemp        = System.Convert.ToInt16(rVal.Substring(8, 4), 16);
                dataVal.cur[0] = ((double)valTemp) / 1024;

                valTemp        = System.Convert.ToInt16(rVal.Substring(12, 4), 16);
                dataVal.cur[1] = ((double)valTemp) / 1024;

                valTemp         = System.Convert.ToInt16(rVal.Substring(56, 4), 16);
                dataVal.volt[2] = ((double)valTemp) * 320 / 4096;

                valTemp         = System.Convert.ToInt16(rVal.Substring(60, 4), 16);
                dataVal.volt[3] = ((double)valTemp) * 320 / 4096;

                valTemp        = System.Convert.ToInt16(rVal.Substring(64, 4), 16);
                dataVal.cur[2] = ((double)valTemp) / 1024;

                valTemp        = System.Convert.ToInt16(rVal.Substring(68, 4), 16);
                dataVal.cur[3] = ((double)valTemp) / 1024;

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 设置负载全部通道电流
        /// </summary>
        /// <param name="wAddr"></param>
        /// <param name="loadPara"></param>
        /// <param name="er"></param>
        /// <param name="saveEPROM"></param>
        /// <returns></returns>
        public bool SetNewLoad(int wAddr, CERS_Load loadPara, out string er, bool saveEPROM = true)
        {
            er = string.Empty;

            try
            {
                bool   setOK = true;
                string cmd0  = string.Empty;
                string wData = string.Empty;
                string rData = string.Empty;
                for (int i = 0; i < _maxCH; i++)
                {
                    if (saveEPROM)
                    {
                        cmd0 = (i + 0x3).ToString("X2");
                    }
                    else
                    {
                        cmd0 = (i + 0x16).ToString("X2");
                    }
                    wData = ((int)(loadPara.cur[i] * 1024)).ToString("X4");
                    wData = CalDataFromERS272Cmd(wAddr, cmd0, wData);
                    int rLen = 8;
                    if (!SendCmdToERS272(wData, rLen, out rData, out er))
                    {
                        setOK = false;
                        continue;
                    }
                    string temp = string.Empty;
                    string rVal = string.Empty;
                    if (!checkErrorCode(rData, out rVal, out temp))
                    {
                        er   += temp;
                        setOK = false;
                        continue;
                    }
                }
                return(setOK);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 设置负载所有通道电流
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        private bool writeAllLoad(int addr, out string er)
        {
            er = string.Empty;

            try
            {
                _syncLock.AcquireWriterLock(-1);

                CERS_Load load = new CERS_Load();

                for (int i = 0; i < load.cur.Length; i++)
                {
                    load.cur[i] = _Mon[addr].Para.SetAllLoad.LoadSet[i];
                }

                Thread.Sleep(_delayMs);

                if (!_devMon.SetNewLoad(addr, load, out er, _Mon[addr].Para.SetAllLoad.saveEPROM))
                {
                    Thread.Sleep(_delayMs);

                    if (!_devMon.SetNewLoad(addr, load, out er, _Mon[addr].Para.SetAllLoad.saveEPROM))
                    {
                        er = _Mon[addr].Base.name + "设置电流;";
                        return(false);
                    }
                }

                _Mon[addr].Para.SetAllLoad.op = EOP.写入OK;

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
            finally
            {
                _syncLock.ReleaseWriterLock();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 读取负载设置
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        private bool readLoadSet(int addr, out string er)
        {
            er = string.Empty;

            try
            {
                _syncLock.AcquireWriterLock(-1);

                Thread.Sleep(_delayMs);

                CERS_Load load = null;

                if (!_devMon.ReadLoadSet(addr, out load, out er))
                {
                    Thread.Sleep(_delayMs);

                    if (!_devMon.ReadLoadSet(addr, out load, out er))
                    {
                        er = _Mon[addr].Base.name + "读电流设置;";
                        return(false);
                    }
                }

                for (int i = 0; i < load.cur.Length; i++)
                {
                    _Mon[addr].Para.ReadLoad.LoadSet[i] = load.cur[i];
                }

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

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
            finally
            {
                _syncLock.ReleaseWriterLock();
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 读取负载电流
 /// </summary>
 /// <param name="wAddr"></param>
 /// <param name="dataVal"></param>
 /// <param name="er"></param>
 /// <returns></returns>
 public bool ReadData(int wAddr, out CERS_Load dataVal, out string er)
 {
     return(_devMon.ReadData(wAddr, out dataVal, out er));
 }
Ejemplo n.º 8
0
 public bool ReadLoadSet(int wAddr, out CERS_Load loadVal, out string er)
 {
     return(_devMon.ReadLoadSet(wAddr, out loadVal, out er));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 设置负载全部通道电流
 /// </summary>
 /// <param name="wAddr"></param>
 /// <param name="loadPara"></param>
 /// <param name="er"></param>
 /// <param name="saveEPROM"></param>
 /// <returns></returns>
 public bool SetNewLoad(int wAddr, CERS_Load loadPara, out string er, bool saveEPROM = true)
 {
     return(_devMon.SetNewLoad(wAddr, loadPara, out er, saveEPROM));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 设置负载单通道电流
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        private bool writeCHLoad(int addr, out string er)
        {
            er = string.Empty;

            try
            {
                _syncLock.AcquireWriterLock(-1);

                for (int i = 0; i < _Mon[addr].Para.SetCHLoad.Count; i++)
                {
                    if (_Mon[addr].Para.SetCHLoad[i].op == EOP.写入)
                    {
                        //设置电流

                        Thread.Sleep(_delayMs);

                        if (!_devMon.SetNewLoad(addr, i + 1, _Mon[addr].Para.SetCHLoad[i].loadVal, out er, _Mon[addr].Para.SetCHLoad[i].saveEPROM))
                        {
                            Thread.Sleep(_delayMs);

                            if (!_devMon.SetNewLoad(addr, i + 1, _Mon[addr].Para.SetCHLoad[i].loadVal, out er, _Mon[addr].Para.SetCHLoad[i].saveEPROM))
                            {
                                er = _Mon[addr].Base.name + "设置单通道电流;";
                                return(false);
                            }
                        }

                        //回读电流

                        Thread.Sleep(_delayMs);

                        CERS_Load LoadSetting = null;

                        if (!_devMon.ReadLoadSet(addr, out LoadSetting, out er))
                        {
                            Thread.Sleep(_delayMs);

                            if (!_devMon.ReadLoadSet(addr, out LoadSetting, out er))
                            {
                                er = _Mon[addr].Base.name + "回读设置电流;";
                                return(false);
                            }
                        }

                        if (_Mon[addr].Para.SetCHLoad[i].loadVal == LoadSetting.cur[i])
                        {
                            _Mon[addr].Para.SetCHLoad[i].op = EOP.写入OK;
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
            finally
            {
                _syncLock.ReleaseWriterLock();
            }
        }