public bool cHJReadTemp(int readLen, ref double[] mReturnBuff)
        {
            int  i           = 0;
            bool returnValue = false;

            if (readLen > mReturnBuff.Length || readLen > 8)
            {
                readLen = mReturnBuff.Length;
            }
            long[] ReturnBuff = new long[readLen];
            if (cMain.isDebug)
            {
                for (i = 0; i < readLen; i++)
                {
                    mReturnBuff[i] = 20 + i + Num.Rand();
                }
                returnValue = true;
            }
            else
            {
                returnValue = mStandarBoard.StandarBoardRead(0, readLen, ref ReturnBuff);
                if (returnValue)
                {
                    for (i = 0; i < readLen; i++)
                    {
                        mReturnBuff[i] = ReturnBuff[i] / 10.000;
                    }
                }
                else
                {
                    if (errStr.IndexOf(mStandarBoard.ErrStr) < 0)
                    {
                        errStr = errStr + mStandarBoard.ErrStr;
                    }
                }
            }
            return(returnValue);
        }
Exemple #2
0
        public bool SsetRead(ref double[] mReadBuff)
        {
            bool returnValue = true;

            long[] tempLong = new long[5];
            returnValue = mStandarBoard.StandarBoardRead(0x10, 5, ref tempLong);
            if (returnValue)
            {
                if (tempLong[1] < 10000)//大于10000就大于标称电流
                {
                    mReadBuff[0] = (double)tempLong[0] * 250 / 10000.000;
                    mReadBuff[3] = (double)tempLong[1] * 20 / 10000.000;
                    mReadBuff[6] = (double)tempLong[2] * 20 * 250 / 10000.00;
                }
                else
                {
                    returnValue = false;
                }
            }
            return(returnValue);
        }
Exemple #3
0
        /// <summary>
        /// 读取2010模块数据
        /// </summary>
        /// <param name="ReturnBuff">返回读取9元素数组,0,1,2为电压,3,4,5为电流,6,7,8为功率</param>
        /// <returns>返回读取数据是否成功</returns>
        public bool Ft2010Read(ref double[] ReturnBuff)
        {
            //if (cMain.isDebug)
            //{
            //    ReturnBuff[0] = 220 + 10 * Num.Rand();
            //    ReturnBuff[1] = 220 + 10 * Num.Rand();
            //    ReturnBuff[2] = 220 + 10 * Num.Rand();
            //    ReturnBuff[3] = 4;// +5 * Num.Rand();
            //    ReturnBuff[4] = 6;// +5 * Num.Rand();
            //    ReturnBuff[5] = 8;// +5 * Num.Rand();
            //    ReturnBuff[6] = ReturnBuff[0] * ReturnBuff[3];
            //    ReturnBuff[7] = ReturnBuff[1] * ReturnBuff[4];
            //    ReturnBuff[8] = ReturnBuff[2] * ReturnBuff[5];
            //    return true;
            //}
            bool returnValue = false;

            long[] mReturnBuff = new long[35];
            if (!mStandarBoard.mStandarBoardInit)
            {
                mStandarBoard.StandarBoardInit();
            }
            float volBase = 0.25f;

            returnValue = mStandarBoard.StandarBoardRead(0x030A, 1, ref mReturnBuff);
            if (returnValue)
            {
                if (mReturnBuff[0] > 0)
                {
                    volBase = 1;
                }
            }
            returnValue = mStandarBoard.StandarBoardRead(0, 35, ref mReturnBuff);
            if (returnValue)
            {
                ReturnBuff[0] = mReturnBuff[0] / (double)100;//电压
                ReturnBuff[1] = mReturnBuff[8] / (double)100;
                ReturnBuff[2] = mReturnBuff[16] / (double)100;
                ReturnBuff[3] = mReturnBuff[2] * curBase / 10000;//电流
                ReturnBuff[4] = mReturnBuff[10] * curBase / 10000;
                ReturnBuff[5] = mReturnBuff[18] * curBase / 10000;
                if (mReturnBuff[4] >= 32768)
                {
                    mReturnBuff[4] = -((mReturnBuff[4] ^ 0xFFFF) + 1);
                }
                if (mReturnBuff[12] >= 32768)
                {
                    mReturnBuff[12] = -((mReturnBuff[12] ^ 0xFFFF) + 1);
                }
                if (mReturnBuff[20] >= 32768)
                {
                    mReturnBuff[20] = -((mReturnBuff[20] ^ 0xFFFF) + 1);
                }
                ReturnBuff[6] = mReturnBuff[04] * curBase * 0.4f * volBase; //功率
                ReturnBuff[7] = mReturnBuff[12] * curBase * 0.4f * volBase; //功率
                ReturnBuff[8] = mReturnBuff[20] * curBase * 0.4f * volBase; //功率

                if (ReturnBuff.Length > 10)
                {
                    //当三相电流都大于0.1A即三相有电流时,功率因素取总功率因素
                    if (Num.DoubleMin(ReturnBuff[3], ReturnBuff[4], ReturnBuff[5]) > 0.1)
                    {
                        ReturnBuff[9] = mReturnBuff[29] / 10000;
                    }
                    else//否则取最大电流的功率因素
                    {
                        ReturnBuff[9] = mReturnBuff[Num.IndexMax(ReturnBuff[3], ReturnBuff[4], ReturnBuff[5]) * 8 + 5] / 10000;
                    }
                }
            }
            else
            {
                if (errStr.IndexOf(mStandarBoard.ErrStr) < 0)
                {
                    errStr = errStr + mStandarBoard.ErrStr;
                }
            }
            return(returnValue);
        }
        ///// <summary>
        ///// 要求SN板发送一次指令给外机
        ///// </summary>
        ///// <returns>返回此次操作是否成功</returns>
        //public bool SnBoardSendDelay()//SN板发送一次命令
        //{
        //    if (cMain.isDebug)
        //    {
        //        return true;
        //    }
        //    if (!mSnBoardInit)
        //    {
        //        SnBoardInit();
        //        return false;
        //    }
        //    byte[] WriteBuff = new byte[10];//发送数据
        //    byte[] ReadBuff = new byte[10];//接收数据
        //    int ReturnByte = 0;//返回数据
        //    bool IsReturn = false;//是否成功返回
        //    bool IsTimeOut = false;//是否超时
        //    DateTime NowTime = DateTime.Now;//当前时间
        //    TimeSpan ts;//时间差
        //    byte CrcHi = 0, CrcLo = 0;//CRC校验
        //    try
        //    {
        //        if (!comPort.IsOpen)
        //        {
        //            comPort.Open();
        //        }
        //        WriteBuff[0] = (byte)(StandarModebusAddress & 0xFF);
        //        WriteBuff[1] = 0x06;
        //        WriteBuff[2] = 0x00;
        //        WriteBuff[3] = 0x07;
        //        WriteBuff[4] = 0x00;
        //        WriteBuff[5] = 0x02;
        //        cMain.CRC_16(WriteBuff, 6, ref CrcLo, ref CrcHi);
        //        WriteBuff[6] = CrcLo;
        //        WriteBuff[7] = CrcHi;
        //        comPort.DiscardOutBuffer();//刷新串口
        //        comPort.Write(WriteBuff, 0, 8);
        //        NowTime = DateTime.Now;
        //        do
        //        {
        //            if (comPort.BytesToRead >= 8)//收到数据
        //            {
        //                ReturnByte = comPort.BytesToRead;
        //                IsReturn = true;
        //            }
        //            ts = DateTime.Now - NowTime;
        //            if (ts.TotalMilliseconds > timeOut)//时间超时
        //            {
        //                IsTimeOut = true;
        //            }
        //        } while (!IsReturn && !IsTimeOut);
        //        if (!IsReturn && IsTimeOut)//超时
        //        {
        //            if (ErrStr.IndexOf("SN发送失败,接收数据已超时") < 0)
        //            {
        //                ErrStr = ErrStr + DateTime.Now.ToString() + mName + ":发送失败,接收数据已超时" + (char)13 + (char)10;
        //            }
        //            return false;
        //        }
        //        else
        //        {
        //            comPort.Read(ReadBuff, 0, ReturnByte);
        //            if ((ReadBuff[0] != WriteBuff[0]) || (ReadBuff[1] != WriteBuff[1]))//数据检验失败
        //            {
        //                if (ErrStr.IndexOf("SN发送失败,接收数据错误") < 0)
        //                {
        //                    ErrStr = ErrStr + DateTime.Now.ToString() + mName + ":发送失败,接收数据错误" + (char)13 + (char)10;
        //                }
        //                return false;
        //            }
        //        }
        //    }
        //    catch (Exception exc)
        //    {
        //        if (ErrStr.IndexOf(exc.ToString()) < 0)
        //        {
        //            ErrStr = ErrStr + DateTime.Now.ToString() + mName + ":" + exc.ToString() + (char)13 + (char)10;
        //        }
        //        return false;
        //    }
        //    return true;
        //}
        /// <summary>
        /// 读取SN板上外机返回指令,前6位数据(接收指令长度,频率,冷凝,室温,排气温度,T3)
        /// </summary>
        /// <param name="ReturnBuff">数组,将要返回的数据</param>
        /// <returns>返回读取变频板是否成功,-1返回数据不正确,0读取数据不正确,1正确</returns>
        public int SnBoardReadCmd(out long[] ReturnBuff)//读SN板
        {
            ReturnBuff = new long[10];
            int i;

            for (i = 0; i < ReturnBuff.Length; i++)
            {
                ReturnBuff[i] = 0;
            }
            ReadSnStr = "";
            if (cMain.isDebug)
            {
                ReturnBuff[0] = 18;
                ReturnBuff[1] = 0x32 + (int)(Num.Rand() * 10);
                ReturnBuff[2] = 0x7D + (int)(Num.Rand() * 10);
                ReturnBuff[3] = 0x7D + (int)(Num.Rand() * 10);
                ReturnBuff[4] = 0x7D + (int)(Num.Rand() * 10);
                return(1);
            }
            bool returnValue = false;

            byte[] readValue = new byte[30];
            long   SnLength  = 0;

            returnValue = mStandarBoard.StandarBoardRead(0x15, 0x0F, ref readValue);
            if (!returnValue)
            {
                if (errStr.IndexOf(mStandarBoard.ErrStr) < 0)
                {
                    errStr = errStr + mStandarBoard.ErrStr;
                }
                return(0);
            }
            else
            {
                SnLength = readValue[1];
                for (i = 0; i < SnLength; i++)
                {
                    if (i < readValue.Length - 2)
                    {
                        ReadSnStr = ReadSnStr + string.Format("{0:X2}", readValue[i + 2]);
                    }
                }
                switch (SnLength)
                {
                case 18:
                    ReturnBuff[1] = readValue[7];
                    ReturnBuff[2] = readValue[10];
                    ReturnBuff[3] = readValue[11];
                    ReturnBuff[4] = readValue[12];
                    ReturnBuff[5] = 0;
                    break;

                case 20:
                    ReturnBuff[1] = readValue[8];
                    ReturnBuff[2] = readValue[11];
                    ReturnBuff[3] = readValue[12];
                    ReturnBuff[4] = readValue[13];
                    ReturnBuff[5] = 0;
                    break;

                case 6:
                    ReturnBuff[1] = 0;
                    ReturnBuff[2] = 0;
                    ReturnBuff[3] = 0;
                    ReturnBuff[4] = 0;
                    ReturnBuff[5] = readValue[2];
                    break;

                case 8:
                    ReturnBuff[1] = 0;
                    ReturnBuff[2] = readValue[4];
                    ReturnBuff[3] = readValue[5];
                    ReturnBuff[4] = 0;
                    ReturnBuff[5] = 0;
                    break;

                default:
                    return(-1);
                }
            }
            return(1);

            /*
             * if (!mSnBoardInit)//没有初始化
             * {
             *  SnBoardInit();
             *  return false;
             * }
             * if (ReturnBuff.Length < 10)
             * {
             *  if (ErrStr.IndexOf("输入数组大小不能小于") < 0)
             *  {
             *      ErrStr = ErrStr + DateTime.Now.ToString() + mName + ":" + "输入数组大小不能小于10" + (char)13 + (char)10;
             *  }
             *  return false;
             * }
             * byte[] WriteBuff = new byte[10];//发送数据
             * byte[] ReadBuff = new byte[80];//接收数据
             * int[] ReadTempBuff = new int[35];//临时数据
             * int ReturnByte = 0;//返回数据
             * bool IsReturn = false;//是否成功返回
             * bool IsTimeOut = false;//是否超时
             * DateTime NowTime;//当前时间
             * TimeSpan ts;//时间差
             * byte CrcHi = 0, CrcLo = 0;//CRC校验
             * int i;
             * try
             * {
             *  WriteBuff[0] = StandarModebusAddress;
             *  WriteBuff[1] = 0x03;
             *  WriteBuff[2] = 0x00;
             *  WriteBuff[3] = 0x15;
             *  WriteBuff[4] = 0x00;
             *  WriteBuff[5] = 0x0B;
             *  cMain.CRC_16(WriteBuff, 6, ref CrcLo, ref CrcHi);
             *  WriteBuff[6] = CrcLo;
             *  WriteBuff[7] = CrcHi;
             *  if (!comPort.IsOpen)
             *  {
             *      comPort.Open();
             *  }
             *  comPort.DiscardInBuffer();//刷新串口
             *  comPort.Write(WriteBuff, 0, 8);
             *  NowTime = DateTime.Now;
             *  do
             *  {
             *      if (comPort.BytesToRead >= (2 * WriteBuff[5] + 5))//收到数据
             *      {
             *          ReturnByte = comPort.BytesToRead;
             *          IsReturn = true;
             *      }
             *      ts = DateTime.Now - NowTime;
             *      if (ts.TotalMilliseconds > timeOut)//时间超时
             *      {
             *          IsTimeOut = true;
             *      }
             *  } while (!IsReturn && !IsTimeOut);
             *  if (!IsReturn && IsTimeOut)//超时
             *  {
             *      if (ErrStr.IndexOf("读取失败,接收数据已超时") < 0)
             *      {
             *          ErrStr = ErrStr + DateTime.Now.ToString() + mName + ":读取失败,接收数据已超时" + (char)13 + (char)10;
             *      }
             *      return false;
             *  }
             *  comPort.Read(ReadBuff, 0, ReturnByte);
             *  if ((ReadBuff[0] != WriteBuff[0]) || (ReadBuff[1] != WriteBuff[1]))//数据检验失败
             *  {
             *      if (ErrStr.IndexOf("读取失败,接收数据错误") < 0)
             *      {
             *          ErrStr = ErrStr + DateTime.Now.ToString() + mName + ":读取失败,接收数据错误" + (char)13 + (char)10;
             *      }
             *      return false;
             *  }
             *  else
             *  {
             *      for (i = 0; i < WriteBuff[5]; i++)
             *      {
             *          ReadTempBuff[i] = (ReadBuff[i * 2 + 3] & 0xFF) * 256 + (ReadBuff[i * 2 + 4] & 0xFF);
             *
             *      }
             *      for (i = 1; i < 10; i++)
             *      {
             *          ReadSnStr = ReadSnStr + string.Format("{0:X2}", ReadBuff[i * 2 + 3]);
             *          ReadSnStr = ReadSnStr + string.Format("{0:X2}", ReadBuff[i * 2 + 4]);
             *      }
             *  }
             * }
             * catch (Exception exc)
             * {
             *  if (ErrStr.IndexOf(exc.ToString()) < 0)
             *  {
             *      ErrStr = ErrStr + DateTime.Now.ToString() + mName + ":" + exc.ToString() + (char)13 + (char)10;
             *  }
             *  return false;
             * }
             * for (i = 0; i < ReturnBuff.Length; i++)
             * {
             *  ReturnBuff[i] = ReadBuff[i + 3];
             * }
             * return true;
             */
        }