Example #1
0
        public static byte[] BroadcastValue(string content, byte[] broadcastTipcontentFront, byte[] broadcastTipcontentBack)
        {
            string hexContent = HexCodeHelper.ToHex(content, "GBK", false);

            byte[] contentByte = HexCodeHelper.strToToHexByte(hexContent);
            int    contentLen  = contentByte.Length;
            int    broadcastTipcontentFrontLen = 0;
            int    broadcastTipcontentBackLen  = 0;

            if (broadcastTipcontentFront != null)
            {
                broadcastTipcontentFrontLen = broadcastTipcontentFront.Length;
            }
            if (broadcastTipcontentBack != null)
            {
                broadcastTipcontentBackLen = broadcastTipcontentBack.Length;
            }
            byte[] broadReturnValueByte = new byte[contentLen + broadcastTipcontentFrontLen + broadcastTipcontentBackLen];


            int m = 0;

            if (broadcastTipcontentFront != null)
            {
                foreach (byte b in broadcastTipcontentFront)
                {
                    broadReturnValueByte[m] = broadcastTipcontentFront[m];
                    m++;
                }
            }
            int n = 0;
            int k = m + n;

            foreach (byte b in contentByte)
            {
                broadReturnValueByte[k + n] = contentByte[n];
                n++;
            }

            int p = 0;
            int q = k + n;

            if (broadcastTipcontentBack != null)
            {
                foreach (byte b in broadcastTipcontentBack)
                {
                    broadReturnValueByte[q + p] = broadcastTipcontentBack[p];
                    p++;
                }
            }
            return(BroadcastValue(broadReturnValueByte));
        }
Example #2
0
        public static byte[] ScreenByteValue(string content, int lineNumber, int time, int color)
        {
            string hexContent = HexCodeHelper.ToHex(content, "GBK", false);

            byte[] contentByte = HexCodeHelper.strToToHexByte(hexContent);
            int    dataLength  = 4 + contentByte.Length;  //数据长度
            int    length      = 15 + contentByte.Length; //总的数据位数

            byte[] showValueByte = new byte[length];      //显示数据byte数组

            //生成CRC校验,去除帧头和帧尾
            int dataLen = length - 3;  //CRC校验的byte数组长度

            byte[] contextBytes = new byte[dataLen];
            contextBytes[0] = Convert.ToByte("01", 16);
            contextBytes[1] = Convert.ToByte("64", 16);
            contextBytes[2] = Convert.ToByte("00", 16); //3位预留
            contextBytes[3] = Convert.ToByte("26", 16); //命令
            contextBytes[4] = Convert.ToByte("00", 16);
            contextBytes[5] = Convert.ToByte(Convert.ToString(dataLength, 16), 16);
            contextBytes[6] = Convert.ToByte(Convert.ToString(lineNumber, 16), 16);
            contextBytes[7] = Convert.ToByte(Convert.ToString(time, 16), 16);
            contextBytes[8] = Convert.ToByte(Convert.ToString(color, 16), 16);
            //contextBytes[7] = Convert.ToByte(Convert.ToString(color, 16), 16);
            //contextBytes[8] = Convert.ToByte(Convert.ToString(time, 16), 16);
            contextBytes[9] = Convert.ToByte("00", 16);  //保留位
            int m = 0;

            foreach (byte b in contentByte)
            {
                contextBytes[m + 10] = contentByte[m];
                m++;
            }
            int n = m + 10;

            contextBytes[n]     = Convert.ToByte("00", 16); //保留位
            contextBytes[n + 1] = Convert.ToByte("00", 16); //保留位
            byte[] CRCBytes = HexCodeHelper.CRC16(contextBytes, dataLen);

            //生成发送数据byte数组
            showValueByte[0]  = Convert.ToByte("AA", 16);
            showValueByte[1]  = Convert.ToByte("55", 16); //2位帧头
            showValueByte[2]  = Convert.ToByte("01", 16);
            showValueByte[3]  = Convert.ToByte("64", 16);
            showValueByte[4]  = Convert.ToByte("00", 16); //3位预留
            showValueByte[5]  = Convert.ToByte("26", 16); //命令
            showValueByte[6]  = Convert.ToByte("00", 16);
            showValueByte[7]  = Convert.ToByte(Convert.ToString(dataLength, 16), 16);
            showValueByte[8]  = Convert.ToByte(Convert.ToString(lineNumber, 16), 16);
            showValueByte[9]  = Convert.ToByte(Convert.ToString(time, 16), 16);
            showValueByte[10] = Convert.ToByte(Convert.ToString(color, 16), 16);
            showValueByte[11] = Convert.ToByte("00", 16);  //保留位
            int i = 0;

            foreach (byte b in contentByte)
            {
                showValueByte[i + 12] = contentByte[i];
                i++;
            }
            int j = i + 12;

            showValueByte[j]     = CRCBytes[1];
            showValueByte[j + 1] = CRCBytes[0];
            showValueByte[j + 2] = Convert.ToByte("AF", 16);
            return(showValueByte);
        }