示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //string a = Send_Email("*****@*****.**", "*****@*****.**", "abcdefgh", "hgedcba");
            //MessageBox.Show(a);
            //timer1.Enabled = true;

            emailDevice.USBOpen(host);

            if (emailDevice.readSettingDevice() == false)
            {
                emailDevice.Close();
                return;
            }

            emailDevice.Close();

            if (emailDevice.byteLogging == 0x44)
            {
                MessageBox.Show("Logger is recording. Cannot write setting email");
                return;
            }

            emailDevice.USBOpen(host);

            string cc  = "";
            int    lan = 0;

            cc = richTextBox1.Text.Replace("\n", ";");
            //string dsEmail = textBox1.Text + ";" + cc;
            string dsEmail = cc;

            if (dsEmail.Substring(dsEmail.Length - 1, 1) == ";")
            {
                dsEmail = dsEmail.Substring(0, dsEmail.Length - 1);
            }
            //byte[] arrEmail = new byte[dsEmail.Length];
            byte[] arrEmail = new byte[600];

            int tmp = 0;

            if (arrEmail.Length <= 60)
            {
                tmp = arrEmail.Length;
            }
            else
            {
                tmp = 60;
            }

            for (int i = 0; i < dsEmail.Length; i++)
            {
                arrEmail[i] = Encoding.ASCII.GetBytes(dsEmail.Substring(i, 1))[0];
            }
            for (int i = dsEmail.Length; i < 600; i++)
            {
                arrEmail[i] = 0xff;
            }
            if (arrEmail.Length > 600)
            {
                MessageBox.Show(res_man.GetString("Emails are too long to save", cul));
                emailDevice.Close();
                return;
            }
            else
            {
                if (arrEmail.Length % 60 > 0)
                {
                    lan = arrEmail.Length / 60 + 1;
                }
                else
                {
                    lan = arrEmail.Length / 60;
                }
                for (int i = 0; i < 10; i++)
                {
                    byte[] buf = new byte[64];
                    buf[0] = 0x01;
                    buf[1] = 0xb6;
                    buf[2] = 0x00;
                    buf[3] = byte.Parse((i + 1).ToString());
                    //if (i == lan - 1)
                    //{
                    //    tmp = arrEmail.Length % 60;
                    //}
                    for (int j = 0; j < tmp; j++)
                    {
                        buf[j + 4] = arrEmail[60 * i + j];
                    }
                    Thread.Sleep(200);
                    if (!emailDevice.writeEmailSetting(buf))
                    {
                        emailDevice.Close();
                        MessageBox.Show(res_man.GetString("Write Setting fail", cul));
                        return;
                    }
                }
                saveEmail(dsEmail);
                btnRead.Enabled = true;
                emailDevice.Close();
                MessageBox.Show(res_man.GetString("Write setting successfully", cul));
            }
        }