Exemple #1
0
        //窗体初始化
        private void Form1_Load(object sender, EventArgs e)
        {
            // Liu - 清空,保险起见
            Array.Clear(laser_data, 0, laser_data.Length);

            string str   = "0xEE";
            string str1  = "0x16";
            int    i     = Convert.ToInt32(str, 16);
            int    ii    = Convert.ToInt32(str1, 16);
            string temp  = string.Format("{0:X}", i);
            string temp1 = string.Format("{0:X}", ii);

            //初始化下拉串口名称列表框
            string[] ports = SerialPort.GetPortNames();
            Array.Sort(ports);
            comboPortName.Items.AddRange(ports);
            comboPortName.SelectedIndex = comboPortName.Items.Count > 0 ? 0 : -1;
            comboBaudrate.SelectedIndex = comboBaudrate.Items.IndexOf("9600");

            //初始化SerialPort对象
            comm.NewLine   = "\r\n";
            comm.RtsEnable = true;//根据实际情况吧。

            //添加事件注册
            comm.DataReceived += comm_DataReceived;

            delegateData += ReceivedData;
        }
Exemple #2
0
        private void client_Load(object sender, EventArgs e)
        {
            //初始化下拉串口名称列表框
            string[] ports = SerialPort.GetPortNames();
            Array.Sort(ports);
            combo_PortName.Items.AddRange(ports);
            combo_PortName.SelectedIndex = combo_PortName.Items.Count > 0 ? 0 : -1;
            combo_Baudrate.SelectedIndex = combo_Baudrate.Items.IndexOf("9600");



            //添加事件注册
            comm.DataReceived += comm_DataReceived;
            delegateData      += comportReceived;


            //richTextBox1.Text = "M0";
            //richTextBox1.Text = "FR,01,037";
            button1.Enabled = true;
            button2.Enabled = false;
            send.Enabled    = false;
            //richTextBox2.Text = "等待建立连接...\n";

            Control.CheckForIllegalCrossThreadCalls = false;//线程间操作无效: 从不是创建控件“richTextBox1”的线程访问它,线程委托

            // 注意,@的作用是"过滤转义字符",就是说\\可以写成\
            imageList1.Images.Add(Image.FromFile(@"..\..\PNG\Circle_Grey.png"));   //读取--0--灰色图标的路径,注意更换地址
            imageList1.Images.Add(Image.FromFile(@"..\..\PNG\Circle_Green.png"));  //读取--1--绿色图标的路径
            imageList1.Images.Add(Image.FromFile(@"..\..\PNG\Circle_Red.png"));    //读取--2--红色图标的路径
            imageList1.Images.Add(Image.FromFile(@"..\..\PNG\Circle_Yellow.png")); //读取--3--黄色图标的路径
            imageList1.Images.Add(Image.FromFile(@"..\..\PNG\Circle_Blue.png"));   //读取--4--蓝色图标的路径
            this.pictureBox_LED.Image = imageList1.Images[0];

            // 载入标准刀具文件 - 这里假设这个文件肯定有
            Standard_height.Clear();
            StreamReader sr_standard_file = new StreamReader("StandardKnife", false);
            string       str_data         = "";

            while (true)
            {
                str_data = sr_standard_file.ReadLine();
                if (null == str_data)
                {
                    break;
                }
                else
                {
                    Standard_height.Add(System.Convert.ToDouble(str_data));
                    standard_data_num++;
                }
            }
            sr_standard_file.Close();

            //===============Liu - 多线程-初始化线程===========
            t1 = new Thread(CrossThreadFlush);
            t1.IsBackground = true;
            t1.Start();
            //================================================
        }
Exemple #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Liu - 清空,保险起见
            Array.Clear(laser_data, 0, laser_data.Length);

            // 载入标准刀具文件 - 这里假设这个文件肯定有
            Standard_height.Clear();
            StreamReader sr_standard_file = new StreamReader("StandardKnife", false);
            string       str_data         = "";

            while (true)
            {
                str_data = sr_standard_file.ReadLine();
                if (null == str_data)
                {
                    break;
                }
                else
                {
                    Standard_height.Add(System.Convert.ToDouble(str_data));
                    standard_data_num++;
                }
            }
            sr_standard_file.Close();


            //===============Liu - 多线程-初始化线程===========
            t1 = new Thread(CrossThreadFlush);
            t1.IsBackground = true;
            //t1.Start();
            //================================================

            //初始化下拉串口名称列表框
            string[] ports = SerialPort.GetPortNames();
            Array.Sort(ports);
            combo_PortName.Items.AddRange(ports);
            combo_PortName.SelectedIndex = combo_PortName.Items.Count > 0 ? 0 : -1;
            combo_Baudrate.SelectedIndex = combo_Baudrate.Items.IndexOf("9600");

            //添加事件注册
            comm.DataReceived += comm_DataReceived;
            delegateData      += ReceivedData;

            // //判断串口当前状态,是开、还是关
            // if (comm.IsOpen)
            // {
            //    // comm.Close();//怎么和stop按钮联合使用?
            // }
            // comm.ReadTimeout = 32;//读取超时之前的毫秒数
            // try
            // {
            //     //comm.Open();//怎么和start按钮联合使用?
            // }
            // catch
            // {
            //     MessageBox.Show("没发现此串口或串口已经在使用");
            // }


            // 注意,@的作用是"过滤转义字符",就是说\\可以写成\
            imageList1.Images.Add(Image.FromFile(@"..\..\PNG\Circle_Grey.png"));   //读取灰色图标的路径,注意更换地址
            imageList1.Images.Add(Image.FromFile(@"..\..\PNG\Circle_Green.png"));  //读取绿色图标的路径
            imageList1.Images.Add(Image.FromFile(@"..\..\PNG\Circle_Red.png"));    //读取红色图标的路径
            imageList1.Images.Add(Image.FromFile(@"..\..\PNG\Circle_Yellow.png")); //读取黄色图标的路径

            this.pictureBox_LED.Image = imageList1.Images[0];
        }