コード例 #1
0
        private void btnSaveSMS_Click(object sender, EventArgs e)
        {
            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 mySMS = rtxtSMS.Text.Trim();

            if (mySMS.Length > 210)
            {
                //MessageBox.Show(res_man.GetString("Too many SMS recipients. Only 10 SMS recipients are allowed", cul));
                MessageBox.Show("Too many SMS recipients. Only 10 SMS recipients are allowed");
                emailDevice.Close();
                return;
            }

            string[] SMSlist = mySMS.Split('\n');
            string[] fullSMS = new string[10];
            for (int i = 0; i < 10; i++)
            {
                fullSMS[i] = String.Empty;
            }

            for (int i = 0; i < SMSlist.Length; i++)
            {
                if (SMSlist[i].Length > 20)
                {
                    MessageBox.Show("SMS number cannot be over 20 characters");
                    emailDevice.Close();
                    return;
                }

                fullSMS[i] = SMSlist[i];
            }

            byte[] writeSMS = new byte[44];
            for (int i = 0; i < 5; i++)
            {
                Array.Clear(writeSMS, 0, writeSMS.Length);

                writeSMS[0] = 0x01;
                writeSMS[1] = 0xb7;
                writeSMS[2] = 0x00;
                writeSMS[3] = Convert.ToByte(i + 1);
                byte[] byteSMS1 = Encoding.ASCII.GetBytes(fullSMS[2 * i]);
                byte[] byteSMS2 = Encoding.ASCII.GetBytes(fullSMS[2 * i + 1]);
                for (int j = 0; j < byteSMS1.Length; j++)
                {
                    writeSMS[j + 4] = byteSMS1[j];
                }

                for (int j = 0; j < byteSMS2.Length; j++)
                {
                    writeSMS[j + 24] = byteSMS2[j];
                }

                if (!emailDevice.writeSMSSetting(writeSMS))
                {
                    emailDevice.Close();
                    MessageBox.Show("Write SMS fail");
                    return;
                }
            }

            emailDevice.Close();
            MessageBox.Show("Write SMS successfully");
        }