示例#1
0
文件: apprun.cs 项目: skyclub66/HMI
        private void Sendbo()
        {
            Random     random = new Random();
            List <int> list   = new List <int>();
            int        num    = 0;
            int        num2   = 1;

            byte[] array = new byte[3];
            Win32.timeBeginPeriod(1);
            array[0] = 255;
            array[1] = 255;
            array[2] = 255;
            Kuozhan.Getquxian(this.quxianfudu, this.quxianyidong, ref list);
            this.sendboyan = this.textBox2.Text.Getint();
            while (this.sendbo == 1)
            {
                try
                {
                    Application.DoEvents();
                    this.sendboyan = this.textBox2.Text.Getint();
                    byte b    = (byte)list[num];
                    int  num3 = 0;
                    for (int i = 0; i < 4; i++)
                    {
                        if (this.quxiantongdaos[i] < 4)
                        {
                            byte b2;
                            if (num + 16 * i >= list.Count)
                            {
                                int j;
                                for (j = num + 16 * i; j >= list.Count; j -= list.Count)
                                {
                                }
                                b2 = (byte)list[j];
                            }
                            else
                            {
                                b2 = (byte)list[num + 16 * i];
                            }
                            if (this.checkBox2.Checked)
                            {
                                b  = (byte)random.Next(int.Parse(this.textBox8.Text), int.Parse(this.textBox9.Text));
                                b2 = (byte)random.Next(int.Parse(this.textBox8.Text), int.Parse(this.textBox9.Text));
                            }
                            string text = string.Concat(new string[]
                            {
                                "add ",
                                this.textBox5.Text,
                                ",",
                                this.quxiantongdaos[i].ToString(),
                                ",",
                                b2.ToString()
                            });
                            if (this.quxiansendmoni)
                            {
                                this.sendmoni(text, this.checkBox3.Checked, null);
                                num3 += text.Length;
                            }
                            if (this.quxiansendcom)
                            {
                                if (this.com1.IsOpen)
                                {
                                    this.com1.sendstring_End(text, this.checkBox3.Checked, null);
                                    num3 = 0;
                                }
                            }
                        }
                    }
                    Application.DoEvents();
                    for (int k = 0; k < this.sendboyan; k++)
                    {
                        Thread.Sleep(1);
                        Application.DoEvents();
                        if (this.sendbo != 1)
                        {
                            break;
                        }
                    }
                    for (int k = 0; k < num3; k++)
                    {
                        Thread.Sleep(1);
                        Application.DoEvents();
                        if (this.sendbo != 1)
                        {
                            break;
                        }
                    }
                    num2++;
                    num++;
                    if (num == list.Count)
                    {
                        num  = 0;
                        num2 = 1;
                    }
                }
                catch (Exception ex)
                {
                    MessageOpen.Show(ex.Message);
                    this.sendbo = 1;
                    while (this.sendbo == 1)
                    {
                        Application.DoEvents();
                    }
                }
            }
            this.sendbo = 0;
        }