예제 #1
0
        public static string makeString(string filename)
        {
            string[][] s  = Float2Bytes.readFile(@filename);
            string     ss = "";

            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    if (s[i][j].Trim().ToUpper() == "CHECKSUM" ||
                        s[i][j].Trim().ToUpper() == "RESERVE")
                    {
                        ss += 0 + " ";
                    }
                    else
                    {
                        ss += s[i][j] + " ";
                    }
                }
                ss += "\r\n";
            }
            return(ss);
        }
예제 #2
0
        public static List <List <byte> > makeBytesSubROM(string filename)
        {
            string[][]          s     = Float2Bytes.readFile(@filename);
            List <List <byte> > bytes = new List <List <byte> >();

            for (int i = 0; i < 2; i++)
            {
                List <byte> bInit = new List <byte>();
                bytes.Add(bInit);
            }
            byte[] reserve = { 0, 0, 0, 0 };
            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    string temp = s[i][j].Trim().ToUpper();
                    if (temp == "RESERVE")
                    {
                        bytes[i].AddRange(reserve);
                    }
                    else
                    {
                        if (s[i][j].Substring(0, 2) == "0x")
                        {
                            UInt32 u32 = Convert.ToUInt32(s[i][j].Substring(2), 16);
                            bytes[i].AddRange(BitConverter.GetBytes(u32).Reverse());
                        }
                        else
                        {
                            byte[] floatBytes = BitConverter.GetBytes(Convert.ToSingle(temp));
                            bytes[i].AddRange(floatBytes.Reverse());
                        }
                    }
                }
            }
            return(bytes);
        }
예제 #3
0
        public static List <List <byte> > makeBytes(string filename)
        {
            string[][] s = Float2Bytes.readFile(@filename);
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i].Length != 8)
                {
                    MessageBox.Show("EXCEL读取有误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
            }
            List <List <byte> > bytes = new List <List <byte> >();

            for (int i = 0; i < 6; i++)
            {
                List <byte> bInit = new List <byte>();
                bytes.Add(bInit);
            }
            List <List <UInt16> > u16ArrayList = new List <List <UInt16> >();

            for (int i = 0; i < 6; i++)
            {
                List <UInt16> bInit = new List <UInt16>();
                u16ArrayList.Add(bInit);
            }
            byte[] reserve     = { 0, 0, 0, 0 };
            byte[] checksumTag = { 0, 0, 0, 0 };
            int    listIndex   = 0;

            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    string temp = s[i][j].Trim().ToUpper();
                    if (temp == "CHECKSUM")
                    {
                        if (i != 0)
                        {
                            listIndex++;
                        }
                        bytes[listIndex].AddRange(checksumTag);
                    }
                    else if (temp == "RESERVE")
                    {
                        bytes[listIndex].AddRange(reserve);
                    }
                    else
                    {
                        byte[] floatBytes = BitConverter.GetBytes(Convert.ToSingle(temp));
                        bytes[listIndex].AddRange(floatBytes.Reverse());
                        UInt16 u16 = (UInt16)((floatBytes[1] << 8) + floatBytes[0]);
                        u16ArrayList[listIndex].Add(u16);
                        u16 = (UInt16)((floatBytes[3] << 8) + floatBytes[2]);
                        u16ArrayList[listIndex].Add(u16);
                    }
                }
            }
            for (int i = 0; i < u16ArrayList.Count; i++)
            {
                UInt16 checkSum = 0;
                foreach (var item in u16ArrayList[i])
                {
                    checkSum += item;
                }
                //bytes[i].RemoveAt(0);
                //bytes[i].RemoveAt(0);
                byte[] u16Bytes = BitConverter.GetBytes(checkSum);
                bytes[i][0] = u16Bytes[1];
                bytes[i][1] = u16Bytes[0];
                //bytes[i].Insert(0, u16Bytes[1]);
            }
            return(bytes);
        }
예제 #4
0
        private void buttonStart_Thread()
        {
            //Timeout t = new Timeout();
            //for (int i = 0; i < 9; i++)
            //{
            //    textBox1.Text += t.IsTimeout().ToString();
            //    Thread.Sleep(500);//休眠时间
            //}
            //    return;
            Stopwatch sw = new Stopwatch();

            sw.Start();
            if (!serialSettingDialog.isOpen())
            {
                MessageBox.Show("串口未打开", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!File.Exists(@txtDataFilename))
            {
                MessageBox.Show("请选择数据文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (textBox2.Text.Trim() == "")
            {
                MessageBox.Show("请输入流水号", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List <string[]> para = new List <string[]>()
            {
                //new string[]{ "9200","99",""},//SPI_Speed 参数-9200
                //new string[]{ "9200","99",""},//保护刷写   参数-无
                new string[] { "9200", "99", "" },//初始化刷写 参数-无
                //new string[]{ "110","30",""},//读          参数-地址0x110 长度6
            };
            List <byte[]> sendBytes = new List <byte[]>()
            {
                //new byte[]{0x00,0x00 },
                //new byte[]{0x00,0x00 },
                new byte[] { 0x00, 0x00 },
                //new byte[]{0x00,0x00 }
            };
            List <Functions> fuc = new List <Functions>()
            {
                //Functions.setBaudrate,
                //Functions.writeDisable,
                Functions.writeEnable,
                //Functions.readBytes
            };

            UInt32 addr = 0;
            List <List <byte> > allBytes = Float2Bytes.makeBytes(@txtDataFilename);

            foreach (var item in allBytes)
            {
                fuc.Add(Functions.writeBytes);
                para.Add(new string[] { (addr).ToString(), "1" });//参数-地址0x110 是否回读1
                addr += (UInt32)item.Count / 2;
                sendBytes.Add(item.ToArray());
            }
            UInt32 addrROM = 0x01E0;
            List <List <byte> > allBytesROM = Float2Bytes.makeBytesSubROM(@subROMInfoFilename);

            foreach (var item in allBytesROM)
            {
                fuc.Add(Functions.writeBytes);
                para.Add(new string[] { addrROM.ToString(), "1" });//参数-地址0x110 是否回读1
                addrROM = 0x01F0;
                sendBytes.Add(item.ToArray());
            }
            for (int testi = 0; testi < 1; testi++)
            {
                bool isPass    = true;
                bool isAllPass = true;
                textBox1.Text = "";

                for (int i = 0; i < fuc.Count; i++)
                {
                    string[] s = TxRx(fuc[i], para[i], sendBytes[i], out isPass);
                    textBox1.Text += s[0] + "\r\n";
                    //waitHandle.WaitOne();
                    if (isAllPass)
                    {
                        isAllPass = isPass;
                    }
                }
                statistics(isAllPass);
                pictureBox1.BackgroundImage = isAllPass ? Properties.Resources.green : Properties.Resources.red;
                textBox1.Text += "测试结果:" + isAllPass + "\r\n";
                string nowTime = System.DateTime.Now.ToString("_yyyy_MM_dd_HH_mm_ss_ffff");
                textBox1.Text += "测试时间:" + nowTime + "\r\n";
                string tempLogFilename = testLogDirectory + textBox2.Text + nowTime + "_" + isAllPass + ".txt";
                textBox1.Text += "文件记录:" + tempLogFilename + "\r\n";
                sw.Stop();
                string elapsedTicks = (sw.ElapsedTicks / (decimal)Stopwatch.Frequency).ToString("F2");
                textBox1.Text += "测试用时:" + elapsedTicks + "\r\n";
                File.WriteAllText(@tempLogFilename, programBytes(allBytes) + "\r\n" + textBox1.Text);
                //textBox2.Text = "" + (Convert.ToInt32(textBox2.Text) + 1);
                textBox2.Clear();
                textBox2.Focus();
            }
        }