Esempio n. 1
0
        /// <summary>
        /// 查询温湿度 值
        /// </summary>
        /// <param name="iAddr"></param>
        /// <returns></returns>
        public int[] AskWsd(int iAddr)
        {
            int[] Wsd = new int[2] {
                25, 55
            };
            //serialWsdYg.ReadExisting();
            SendWsd[4] = 0;
            SendWsd[3] = (byte)iAddr;
            for (int i = 0; i < 4; i++)
            {
                SendWsd[4] = (byte)(SendWsd[4] + SendWsd[i]);
            }
            //txt 发送
            string strContent = SerialPortUtil.ByteToStrHex(SendWsd);

            txtLog.WriteTxt("Wsd.txt", "Send", strContent, false);

            byte[] bRece   = new byte[7];
            int    iRetLen = mainSerial.SendReceByte(SendWsd, ref bRece, 300);

            //txt 接受
            if (iRetLen > 0)
            {
                strContent = SerialPortUtil.ByteToStrHex(bRece);
                txtLog.WriteTxt("Wsd.txt", "Rece", strContent, true);
            }

            byte ReceCheck = 0;

            for (byte bLen = 0; bLen < 6; bLen++)
            {
                ReceCheck = (byte)(ReceCheck + bRece[bLen]);
            }
            if (iRetLen == 7 && bRece[0] == 0x2A && bRece[1] == 0x44 &&
                bRece[2] == bRece[3] && bRece[4] == bRece[5] && bRece[6] == ReceCheck)//2A 44 B3 B3 C9 C9 66
            {
                //温度
                byte b = bRece[2];
                if ((b & 0x80) == 0x80)
                {
                    Wsd[0] = 0 - b & 0x7f;
                }
                else
                {
                    Wsd[0] = b;
                }
                //湿度
                Wsd[1] = bRece[4];
            }
            else//不等于 7位校验 正确
            {
                Wsd[0] = 25;
                Wsd[1] = 55;
            }
            return(Wsd);
        }
Esempio n. 2
0
        /// <summary>
        /// 设置空调厂家
        /// </summary>
        /// <param name="bAddr"></param>
        /// <param name="bTemp"></param>
        public bool OtherAirSetType(byte bAddr, byte bFactory, int iCode)
        {
            bool blRet = false;

            if (bAddr >= 10)
            {
                Byte bHAddr = (byte)(bAddr % 10);
                OtherAirType[3] = (byte)(bHAddr + 0x30);//地址高位
            }
            else
            {
                OtherAirType[4] = (byte)(bAddr + 0x30); //地址低位
            }
            OtherAirType[5] = 0x02;                     //设置空调厂家
            OtherAirType[7] = bFactory;;
            OtherAirType[6] = 0x00;
            //校验
            OtherAirType[9]  = (byte)(OtherAirType[5] ^ OtherAirType[6] ^ OtherAirType[7] ^ OtherAirType[8]);
            OtherAirType[11] = (byte)iCode;
            OtherAirType[10] = (byte)(iCode >> 8);

            //txt 发送
            string strContent = SerialPortUtil.ByteToStrHex(OtherAirType);

            txtLog.WriteTxt("Air.txt", "OtherAirCode Send", strContent, false);

            byte[] bRece   = new byte[14];
            int    iRetLen = mainSerial.SendReceByte(OtherAirType, ref bRece, 300);

            //txt 接受
            if (iRetLen > 0)
            {
                strContent = SerialPortUtil.ByteToStrHex(bRece);
                txtLog.WriteTxt("Air.txt", "OtherAirCode Rece", strContent, true);
            }

            if (iRetLen == 14)
            {
                byte ReceCheck = (byte)(bRece[5] ^ bRece[6] ^ bRece[7] ^ bRece[8]);
                if (bRece[0] == OtherAirType[0] && bRece[1] == OtherAirType[1] && bRece[2] == OtherAirType[2] && bRece[3] == OtherAirType[3] && bRece[4] == OtherAirType[4] &&
                    bRece[5] == 0x02 && bRece[9] == ReceCheck && bRece[12] == 0x01 && bRece[13] == 0x0D)
                {
                    blRet = true;
                }
            }
            return(blRet);
        }
Esempio n. 3
0
        public bool OtherAirControl(byte bAddr, OtherAirControlType controlType, byte btContent)
        {
            bool blRet = false;

            if (bAddr >= 10)
            {
                Byte bHAddr = (byte)(bAddr % 10);
                OtherAirSend[3] = (byte)(bHAddr + 0x30);//地址高位
            }
            else
            {
                OtherAirSend[4] = (byte)(bAddr + 0x30); //地址低位
            }
            OtherAirSend[5] = (byte)controlType;        //控制类型
            OtherAirSend[6] = btContent;
            //校验
            OtherAirSend[9] = (byte)(OtherAirSend[5] ^ OtherAirSend[6] ^ OtherAirSend[7] ^ OtherAirSend[8]);

            //txt 发送
            string strContent = SerialPortUtil.ByteToStrHex(OtherAirSend);

            txtLog.WriteTxt("Air.txt", "OtherAir Send", strContent, false);

            byte[] bRece   = new byte[12];
            int    iRetLen = mainSerial.SendReceByte(OtherAirSend, ref bRece, 500);

            //txt 接受
            if (iRetLen > 0)
            {
                strContent = SerialPortUtil.ByteToStrHex(bRece);
                txtLog.WriteTxt("Air.txt", "OtherAir Rece", strContent, true);
            }

            if (iRetLen == 12)
            {
                byte ReceCheck = (byte)(bRece[5] ^ bRece[6] ^ bRece[7] ^ bRece[8]);
                if (bRece[0] == OtherAirSend[0] && bRece[1] == OtherAirSend[1] && bRece[2] == OtherAirSend[2] && bRece[3] == OtherAirSend[3] && bRece[4] == OtherAirSend[4] &&
                    bRece[5] == OtherAirSend[5] && bRece[6] == OtherAirSend[6] && bRece[7] == OtherAirSend[7] && bRece[8] == OtherAirSend[8] && bRece[9] == ReceCheck &&
                    bRece[10] == 0x01 && bRece[11] == OtherAirSend[11])
                {
                    blRet = true;
                }
            }
            return(blRet);
        }
Esempio n. 4
0
 public static void TxtWriteByte(string strFileName, string strType, byte[] bContent, bool blNewLine)
 {
     if (frmMain.blDebug)
     {
         string strContent = SerialPortUtil.ByteToStrHex(bContent);
         string strFile    = IsTodayFile();
         strFile += strFileName;
         string str = strType;
         str += ":  ";
         str += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
         str += "  ";
         str += strContent;
         str += "\r\n";
         if (blNewLine)
         {
             str += "\r\n";
         }
         WriteFile(strFile, true, str);
     }
 }