Ejemplo n.º 1
0
        public int getAreaLen()
        {
            Led5kSDK.bx_5k_area_header tu = new Led5kSDK.bx_5k_area_header();
            int hsz = Marshal.SizeOf(tu);

            //再考header
            text = text.Replace("₩₩F", "\\F");
            List <byte[]> Byte_Area = new List <byte[]>();
            int           Byte_t    = 0;

            string[] str_Area = text.Trim().Split('\\');
            int      font     = 0;

            for (int n = 0; n < str_Area.Length; n++)
            {
                if (n > 0 && str_Area[n].Length > 1)
                {
                    if (str_Area[n].Substring(0, 2).Equals("FK"))
                    {
                        font = 1;
                        if (str_Area[n].Length > 5)
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 5));
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;

                            string Area_str = str_Area[n].Remove(0, 5);
                            byte[] Korean   = System.Text.Encoding.Unicode.GetBytes(Area_str);
                            for (int k = 0; k < Korean.Length / 2; k++)
                            {
                                byte a = Korean[k * 2];
                                Korean[k * 2]     = Korean[k * 2 + 1];
                                Korean[k * 2 + 1] = a;
                            }
                            Byte_Area.Add(Korean);
                            Byte_t += Korean.Length;
                        }
                        else
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;
                        }
                    }
                    else if (str_Area[n].Substring(0, 2).Equals("FE") || str_Area[n].Substring(0, 2).Equals("FO") || str_Area[n].Substring(0, 2).Equals("WF") || str_Area[n].Substring(0, 2).Equals("WC"))
                    {
                        font = 0;
                        byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                        byte[] special   = new byte[special_1.Length + 1];
                        special[0] = 0x5c;
                        for (int c = 0; c < special_1.Length; c++)
                        {
                            special[c + 1] = special_1[c];
                        }
                        Byte_Area.Add(special);
                        Byte_t += special.Length;
                    }
                    else if (str_Area[n].Substring(0, 1).Equals("C") || str_Area[n].Substring(0, 1).Equals("D") || str_Area[n].Substring(0, 1).Equals("B") || str_Area[n].Substring(0, 1).Equals("T"))
                    {
                        if (font == 1)
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 2));
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;

                            string Area_str = str_Area[n].Remove(0, 2);
                            byte[] Korean   = System.Text.Encoding.Unicode.GetBytes(Area_str);
                            for (int k = 0; k < Korean.Length / 2; k++)
                            {
                                byte a = Korean[k * 2];
                                Korean[k * 2]     = Korean[k * 2 + 1];
                                Korean[k * 2 + 1] = a;
                            }
                            Byte_Area.Add(Korean);
                            Byte_t += Korean.Length;
                        }
                        else
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;
                        }
                    }
                    else if (str_Area[n].Substring(0, 1).Equals("n"))
                    {
                        if (font == 1)
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 1));
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;

                            string Area_str = str_Area[n].Remove(0, 1);
                            byte[] Korean   = System.Text.Encoding.Unicode.GetBytes(Area_str);
                            for (int k = 0; k < Korean.Length / 2; k++)
                            {
                                byte a = Korean[k * 2];
                                Korean[k * 2]     = Korean[k * 2 + 1];
                                Korean[k * 2 + 1] = a;
                            }
                            Byte_Area.Add(Korean);
                            Byte_t += Korean.Length;
                        }
                        else
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;
                        }
                    }
                }
                else
                {
                    if (n > 0)
                    {
                        byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                        byte[] special   = new byte[special_1.Length + 1];
                        special[0] = 0x5c;
                        for (int c = 0; c < special_1.Length; c++)
                        {
                            special[c + 1] = special_1[c];
                        }
                        Byte_Area.Add(special);
                        Byte_t += special.Length;
                    }
                    else
                    {
                        byte[] special = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                        Byte_Area.Add(special);
                        Byte_t += special.Length;
                    }
                }
            }
            byte[] tmp = new byte[Byte_t];
            int    g   = 0;

            for (int n = 0; n < Byte_Area.Count(); n++)
            {
                if (n > 0)
                {
                    for (int j = 0; j < Byte_Area[n].Length; j++)
                    {
                        tmp[g + j] = Byte_Area[n][j];
                    }
                    g += Byte_Area[n].Length;
                }
                else
                {
                    for (int j = 0; j < Byte_Area[n].Length; j++)
                    {
                        tmp[j] = Byte_Area[n][j];
                    }
                    g += Byte_Area[n].Length;
                }
            }
            int len = tmp.Length + hsz + 4;

            return(len);
        }
Ejemplo n.º 2
0
        public byte[] AreaToByteArray()
        {
            //计算header的大小:结构体bx_5k_area_header的大小
            Led5kSDK.bx_5k_area_header tu = new Led5kSDK.bx_5k_area_header();
            int hsz = Marshal.SizeOf(tu);

            //计算len的大小
            text = text.Replace("₩₩F", "\\F");
            List <byte[]> Byte_Area = new List <byte[]>();
            int           Byte_t    = 0;

            string[] str_Area = text.Trim().Split('\\');
            int      font     = 0;

            for (int n = 0; n < str_Area.Length; n++)
            {
                if (n > 0 && str_Area[n].Length > 1)
                {
                    if (str_Area[n].Substring(0, 2).Equals("FK"))
                    {
                        font = 1;
                        if (str_Area[n].Length > 5)
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 5));
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;

                            string Area_str = str_Area[n].Remove(0, 5);
                            byte[] Korean   = System.Text.Encoding.Unicode.GetBytes(Area_str);
                            for (int k = 0; k < Korean.Length / 2; k++)
                            {
                                byte a = Korean[k * 2];
                                Korean[k * 2]     = Korean[k * 2 + 1];
                                Korean[k * 2 + 1] = a;
                            }
                            Byte_Area.Add(Korean);
                            Byte_t += Korean.Length;
                        }
                        else
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;
                        }
                    }
                    else if (str_Area[n].Substring(0, 2).Equals("FE") || str_Area[n].Substring(0, 2).Equals("FO") || str_Area[n].Substring(0, 2).Equals("WF") || str_Area[n].Substring(0, 2).Equals("WC"))
                    {
                        font = 0;
                        byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                        byte[] special   = new byte[special_1.Length + 1];
                        special[0] = 0x5c;
                        for (int c = 0; c < special_1.Length; c++)
                        {
                            special[c + 1] = special_1[c];
                        }
                        Byte_Area.Add(special);
                        Byte_t += special.Length;
                    }
                    else if (str_Area[n].Substring(0, 1).Equals("C") || str_Area[n].Substring(0, 1).Equals("D") || str_Area[n].Substring(0, 1).Equals("B") || str_Area[n].Substring(0, 1).Equals("T"))
                    {
                        if (font == 1)
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 2));
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;

                            string Area_str = str_Area[n].Remove(0, 2);
                            byte[] Korean   = System.Text.Encoding.Unicode.GetBytes(Area_str);
                            for (int k = 0; k < Korean.Length / 2; k++)
                            {
                                byte a = Korean[k * 2];
                                Korean[k * 2]     = Korean[k * 2 + 1];
                                Korean[k * 2 + 1] = a;
                            }
                            Byte_Area.Add(Korean);
                            Byte_t += Korean.Length;
                        }
                        else
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;
                        }
                    }
                    else if (str_Area[n].Substring(0, 1).Equals("n"))
                    {
                        if (font == 1)
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 1));
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;

                            string Area_str = str_Area[n].Remove(0, 1);
                            byte[] Korean   = System.Text.Encoding.Unicode.GetBytes(Area_str);
                            for (int k = 0; k < Korean.Length / 2; k++)
                            {
                                byte a = Korean[k * 2];
                                Korean[k * 2]     = Korean[k * 2 + 1];
                                Korean[k * 2 + 1] = a;
                            }
                            Byte_Area.Add(Korean);
                            Byte_t += Korean.Length;
                        }
                        else
                        {
                            byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                            byte[] special   = new byte[special_1.Length + 1];
                            special[0] = 0x5c;
                            for (int c = 0; c < special_1.Length; c++)
                            {
                                special[c + 1] = special_1[c];
                            }
                            Byte_Area.Add(special);
                            Byte_t += special.Length;
                        }
                    }
                }
                else
                {
                    if (n > 0)
                    {
                        byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                        byte[] special   = new byte[special_1.Length + 1];
                        special[0] = 0x5c;
                        for (int c = 0; c < special_1.Length; c++)
                        {
                            special[c + 1] = special_1[c];
                        }
                        Byte_Area.Add(special);
                        Byte_t += special.Length;
                    }
                    else
                    {
                        byte[] special = System.Text.Encoding.Default.GetBytes(str_Area[n]);
                        Byte_Area.Add(special);
                        Byte_t += special.Length;
                    }
                }
            }
            byte[] tmp = new byte[Byte_t];
            int    g   = 0;

            for (int n = 0; n < Byte_Area.Count(); n++)
            {
                if (n > 0)
                {
                    for (int j = 0; j < Byte_Area[n].Length; j++)
                    {
                        tmp[g + j] = Byte_Area[n][j];
                    }
                    g += Byte_Area[n].Length;
                }
                else
                {
                    for (int j = 0; j < Byte_Area[n].Length; j++)
                    {
                        tmp[j] = Byte_Area[n][j];
                    }
                    g += Byte_Area[n].Length;
                }
            }
            int len = tmp.Length + hsz + 4;

            header.DataLen = tmp.Length;
            //先copy len
            byte[] bt = new byte[len];
            //byte[] lenToByte = System.BitConverter.GetBytes(len);
            byte[] lenToByte = System.BitConverter.GetBytes(len);
            lenToByte.CopyTo(bt, 0);
            int index = lenToByte.Length;

            //再copy header
            //分配结构体大小的内存空间
            IntPtr structPtr = Marshal.AllocHGlobal(hsz);

            //将结构体拷到分配好的内存空间
            Marshal.StructureToPtr(header, structPtr, false);

            //从内存空间拷到AreaDataList数组
            Marshal.Copy(structPtr, bt, index, hsz);
            //释放内存空间
            Marshal.FreeHGlobal(structPtr);
            //copy text
            tmp.CopyTo(bt, index + hsz);
            return(bt);
        }