コード例 #1
0
ファイル: Form1.cs プロジェクト: tumoxuese/XSTORE_V3
        /// <summary>
        /// 拼接成一次性开多个箱子的指令,0x03开箱,0x05查询[MAC与校验外其他的字节可忽略],0x06向对方报告收到错误包[MAC与校验外其他的字节可忽略]
        /// </summary>
        /// <param name="mac"></param>
        /// <param name="box_number"></param>
        /// <returns></returns>
        //byte[] GetSendMulty(byte[] mac, byte[] box_number, byte command = 0x03)
        //{
        //    byte[] byte_open = new byte[12] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
        //    int bytelength = box_number.Length > 6 ? 6 : box_number.Length;
        //    var new_box_number = new byte[12] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

        //    byte[] bs = BitConverter.GetBytes(0x1234);
        //    Console.WriteLine(bs[0].ToString("X2") + " " + bs[1].ToString("X2"));
        //    //原先的逻辑是,1-6传0x01,0x02,0x03等信息
        //    //for (int i = 0; i < bytelength; i++)
        //    //{
        //    //    int boxNo = (int)box_number[i];
        //    //    if (boxNo > 0)
        //    //        byte_open[boxNo - 1] = 0x01;
        //    //}
        //    for (int i = 1; i < bytelength+1; i++)
        //    {
        //        int boxNo = (int)box_number[i - 1];
        //        switch (boxNo)
        //        {
        //            case 11: byte_open[i * 2 - 1] = 0x01; byte_open[i * 2 - 2] = 0x01; break;
        //            case 10: byte_open[i * 2 - 1] = 0x01; break;
        //            case 01: byte_open[i * 2 - 2] = 0x01; break;
        //            case 00:
        //            default:break;
        //        }
        //    }
        //    byte[] r_byte = new byte[37];
        //    Box_Date box_date = new Box_Date();
        //    byte[] date_control = new byte[38];
        //    date_control[0] = box_date.Date_flg[0];//
        //    Array.Copy(box_date.Date_start, 0, date_control, 1, 2);//
        //    date_control[3] = box_date.Date_length[0];//
        //    Array.Copy(box_date.Date_datetime, 0, date_control, 4, 6);////
        //    date_control[10] = command;//指令码
        //    Array.Copy(mac, 0, date_control, 11, 12);//
        //    //Array.Copy(byte_open, 0, date_control, 23, 6);//原先逻辑
        //    Array.Copy(box_number, 0, date_control, 23, 6);
        //    byte[] rcr = new byte[33];
        //    Array.Copy(date_control, 3, rcr, 0, 33);
        //    string aa = ByteToHexString(date_control);
        //    string aas = ByteToHexString(rcr);
        //    date_control[36] = Converts.GetCRCSUM(rcr)[0];//old
        //    date_control[37] = Converts.GetCRCSUM(rcr)[1];//old
        //    Array.Copy(date_control, 1, r_byte, 0, 37);
        //    return r_byte;
        //}

        byte[] GetSendMulty(byte[] mac, byte[] box_number, byte command = 0x03)
        {
            byte[] byte_open = new byte[12] {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            };
            int bytelength = box_number.Length > 12 ? 12 : box_number.Length;

            byte[] bs = BitConverter.GetBytes(0x1234);

            try { Console.WriteLine(bs[0].ToString("X2") + " " + bs[1].ToString("X2")); }
            catch (Exception ex2) {; }

            for (int i = 0; i < bytelength; i++)
            {
                int boxNo = (int)box_number[i];
                if (boxNo > 0)
                {
                    byte_open[i] = 0x01;
                }
            }

            byte[] r_byte = new byte[50];
            try
            {
                Box_Date box_date     = new Box_Date();
                byte[]   date_control = new byte[51];
                date_control[0] = box_date.Date_flg[0];                    //
                Array.Copy(box_date.Date_start, 0, date_control, 1, 2);    //
                date_control[3] = box_date.Date_length[0];                 //
                Array.Copy(box_date.Date_datetime, 0, date_control, 4, 6); ////
                date_control[10] = command;                                //指令码
                Array.Copy(mac, 0, date_control, 11, 15);                  //
                Array.Copy(box_number, 0, date_control, 26, 12);
                byte[] rcr = new byte[46];
                Array.Copy(date_control, 3, rcr, 0, 46);
                string aa  = ByteToHexString(date_control);
                string aas = ByteToHexString(rcr);
                date_control[49] = Converts.GetCRCSUM(rcr)[0]; //old
                date_control[50] = Converts.GetCRCSUM(rcr)[1]; //old
                Array.Copy(date_control, 1, r_byte, 0, 50);
            }
            catch (Exception ex3) {; }


            return(r_byte);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: tumoxuese/XSTORE_V3
        byte[] GetRightBeatsResponse(byte[] byte_mac, bool rightOrError)
        {
            Box_Date box_date = new Box_Date();

            byte[] beatResponse = new byte[50];
            try
            {
                Array.Copy(box_date.Date_start, 0, beatResponse, 0, 2);//Head
            }
            catch (Exception ex9) {; }


            beatResponse[2] = 0x32;
            //byte[] timestamp1 = new byte[6];
            //Array.Copy(box_date.Date_datetime, 0, timestamp1, 0, 6);//timeStamp
            //var ts =  ConvertToTen(timestamp1);
            try
            {
                Array.Copy(box_date.Date_datetime, 0, beatResponse, 3, 6);//timeStamp
            }
            catch (Exception ex8) {; }

            beatResponse[9] = 0x01;//Beats
            try
            {
                Array.Copy(byte_mac, 0, beatResponse, 10, 15);//timeStamp
            }
            catch (Exception ex7) {; }


            if (rightOrError)
            {
                beatResponse[25] = 0x00;
            }
            else
            {
                beatResponse[25] = 0x01;
            }
            byte[] byte_zero_12 = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

            try { Array.Copy(byte_zero_12, 0, beatResponse, 26, 12); }
            catch (Exception ex6) {; }


            byte[] rcr = new byte[46];
            try
            {
                Array.Copy(beatResponse, 2, rcr, 0, 46);
            }
            catch (Exception ex5) {; }


            string crcss = ByteToHexString(rcr);
            string ccccc = ByteToHexString(beatResponse);

            //beatResponse[35] = Converts.GetCRC16(rcr, true)[0];//
            //beatResponse[36] = Converts.GetCRC16(rcr, true)[1];//
            beatResponse[48] = Converts.GetCRCSUM(rcr)[0]; //
            beatResponse[49] = Converts.GetCRCSUM(rcr)[1]; //
            string cccccccc = ByteToHexString(beatResponse);

            return(beatResponse);
        }