Ejemplo n.º 1
0
        public void OpenCanLoaderFile()
        {
            //   UInt32 crc32 = 0xffffffff;
            totalsize = 0;
            String Pathname = null;

            String[] filter = { "*.s19;*.glo;*.hex" };
            //if (openhexFileDialog.ShowDialog() == null)
            //{
            //    return;
            //}
            openFileDialog_HEXFILE.ShowDialog();
            if (openFileDialog_HEXFILE.FileName.EndsWith(".s19") ||
                openFileDialog_HEXFILE.FileName.EndsWith(".glo") ||
                openFileDialog_HEXFILE.FileName.EndsWith(".hex"))
            {
                //Pathname = openhexFileDialog.getFilterPath() + "\\" + openhexFileDialog.getFileName();
                Pathname = openFileDialog_HEXFILE.FileName;

                if (testUser.ReadFile(Pathname) == 0)//文件解析成功
                {
                    textBox_totalframe.Text = (UserExplainFile.Flash_SectionNum).ToString();
                    for (int i = 0; i < UserExplainFile.CurSecNum; i++)
                    {
                        totalsize += UserExplainFile.flash_Data[i].SectionDataNum;
                    }
                    totalsize += UserExplainFile.flash_Data[UserExplainFile.CurSecNum].SectionDataNum;
                    textBox_totalsize.Text = totalsize.ToString();
                    gCrc32 = 0xffffffff;
                    for (int i = 0; i < UserExplainFile.CurSecNum; i++)
                    {
                        gCrc32 = CHECKSUM.CRC32_MPEG_2(gCrc32, UserExplainFile.GetSectionData(i).data, (ushort)UserExplainFile.flash_Data[i].SectionDataNum);
                    }

                    gCrc32 = CHECKSUM.CRC32_MPEG_2(gCrc32, UserExplainFile.GetSectionData(UserExplainFile.CurSecNum).data, (ushort)UserExplainFile.flash_Data[UserExplainFile.CurSecNum].SectionDataNum);
                    //   gCrc32 = crc32;
                    文件CRC32.Text = gCrc32.ToString("X8");
                }
                else
                {
                    MessageBox.Show("文件解析失败");
                    textBox_totalframe.Text = ("0");
                }
            }
            else
            {
                MessageBox.Show("文件类型错误");
            }
        }
Ejemplo n.º 2
0
        public int WriteflashDataAPI(byte cmd, int datalen, int CursectionNum, byte[] flashdata)
        {
            byte[] txdata      = new byte[200];
            byte[] checkdata   = new byte[200];
            int    dataCRC     = 0;
            int    regedistNum = 0;
            int    result;


            if (datalen <= 0 || datalen > 200)
            {
                return(-1);
            }

            txdata[0] = 0x3a;
            txdata[1] = 0x16;
            txdata[2] = 0xf0;
            txdata[3] = (byte)datalen;

            txdata[4] = cmd;
            txdata[5] = (byte)(CursectionNum & 0x00ff);
            txdata[6] = (byte)((CursectionNum >> 8) & 0x00ff);


            for (int i = 0; i < flashdata.Length; i++)
            {
                txdata[7 + i] = flashdata[i];
            }

            for (int i = 0; i < datalen + 8 - 5; i++)
            {
                checkdata[i] = txdata[i + 1];
            }

            dataCRC = CHECKSUM.checksum(checkdata, (ushort)(datalen + 8 - 5));

            txdata[datalen + 8 - 3] = (byte)dataCRC;
            txdata[datalen + 8 - 4] = (byte)(dataCRC >> 8);

            //  txdata[datalen + 8 - 2] = 0x0d;
            //  txdata[datalen + 8 - 1] = 0x0a;


            result = SendRS485DataApi(txdata, 6 + datalen);

            return(result);
        }
Ejemplo n.º 3
0
        public int WriteflashCommandAPI(int datalen, byte[] dat)
        {
            byte[] txdata    = new byte[50];
            byte[] checkdata = new byte[50];
            int    dataCRC   = 0;
            int    result    = 0;

            txdata[0] = 0x3a;
            txdata[1] = 0x16;
            txdata[2] = 0xf0;
            txdata[3] = (byte)datalen;


            for (int i = 0; i < datalen; i++)
            {
                txdata[4 + i] = dat[i];
            }
            for (int i = 0; i < datalen + 8 - 5; i++)
            {
                checkdata[i] = txdata[i + 1];
            }


            dataCRC = CHECKSUM.checksum(checkdata, (ushort)(datalen + 8 - 5));

            txdata[datalen + 8 - 3] = (byte)dataCRC;
            txdata[datalen + 8 - 4] = (byte)(dataCRC >> 8);

            // txdata[datalen + 8 - 2] = 0x0d;
            // txdata[datalen + 8 - 1] = 0x0a;


            result = SendRS485DataApi(txdata, 6 + datalen);

            return(result);
        }
Ejemplo n.º 4
0
        private void 计算校验和ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CHECKSUM checkdialog = new CHECKSUM();

            checkdialog.ShowDialog();
        }