⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 synopsys for the students in order to guide them
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ATSMS;
using System.IO;
using System.Runtime.InteropServices;

namespace MyMobile
{
 
    public partial class Form1 : Form
    {
        private ATSMS.GSMModem oGsmModem;
        public Form1()
        {
            InitializeComponent();
        }
        
        private string WhichDll = "";
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (WhichDll.Equals("mCore"))
            {
                objSMS.Disconnect();
            }
            if (cboComPort.Text.Length <= 1)
            {
                MessageBox.Show("Please Select a comprot");
                cboComPort.Focus();
                return;
            }
            oGsmModem.Port = cboComPort.Text;
            Information.Port = cboComPort.Text;
            {
                if (cboBaudRate.Text.Length > 0)
                {
                    oGsmModem.BaudRate = int.Parse(cboBaudRate.Text);
                }
                if (cboDataBit.Text.Length > 0)
                {
                    oGsmModem.DataBits = int.Parse(cboDataBit.Text);
                }

                try
                {
                    oGsmModem.Connect();
                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                try
                {
                    oGsmModem.NewMessageIndication = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return;
                }
                MessageBox.Show("connected");
                WhichDll = "ATSMS";
                btnDisconnect.Enabled = true;
                btnConnect.Enabled = false;
                btnSendMsg.Enabled = true;
        btnSendClass2Msg.Enabled = true;
        btnCheckPhone.Enabled = true;
            }
        }
        #region mobile robotic
        void Hori_Clock()
        {
            int j = i;
//            label1.Text = "start";
            for (; j < (i + 100); j++)
            {
                PortAccess.Output(data, single_c[(j) % 8]);
                System.Threading.Thread.Sleep(200);
            }
            i = j;
        }
        void Hori_Anti()
        {
            int j = i;
            PortAccess.Output(control, 255);



            for (; j < (i + 100); j++)
            {
                PortAccess.Output(data, single_a[(j) % 8]);
                System.Threading.Thread.Sleep(200);
            }
            i = j;
        }
        void Verti_Clock()
        {
            int j = k;
            for (; j < (k + 100); j++)
            {
                PortAccess.Output(data, single_ctop[(j) % 4]);
                System.Threading.Thread.Sleep(200);
            }
            k = j;
            //label1.Text = "complete";
        }
        void Both_Clock()
        {
            int p = i, q = k;
            for (; (p < (i + 100) && (q < (k + 100))); p++, q++)
            {
                PortAccess.Output(data, single_ctop[(p) % 4]);
                System.Threading.Thread.Sleep(200);
                PortAccess.Output(data, single_c[(q) % 8]);
                System.Threading.Thread.Sleep(200);
            }
            i = p;
            k = q;
        }
        void Both_Anti()
        {
            int p = i, q = k;
            for (; (p < (i + 100) && (q < (k + 100))); p++, q++)
            {
                PortAccess.Output(data, single_atop[(p) % 4]);
                System.Threading.Thread.Sleep(200);
                PortAccess.Output(data, single_a[(q) % 8]);
                System.Threading.Thread.Sleep(200);
            }
            i = p; k = q;
        }
        void Top_Anti_Hori_Clk()
        {
            int p = i, q = k;
            for (; (p < (i + 100) && (q < (k + 100))); p++, q++)
            {
                PortAccess.Output(data, single_atop[(p) % 4]);
                System.Threading.Thread.Sleep(200);
                PortAccess.Output(data, single_c[(q) % 8]);
                System.Threading.Thread.Sleep(200);
            }
            i = p; k = q;
        }
        void Top_Clk_Hori_Anti()
        {
            int p = i, q = k;
            for (; (p < (i + 100) && (q < (k + 100))); p++, q++)
            {
                PortAccess.Output(data, single_ctop[(p) % 4]);
                System.Threading.Thread.Sleep(200);
                PortAccess.Output(data, single_a[(q) % 8]);
                System.Threading.Thread.Sleep(200);
            }
            i = p; k = q;
        }
        void Move_Forward()
        {
            PortAccess.Output(control,0);
            System.Threading.Thread.Sleep(4000);
            PortAccess.Output(control, 255);

        }
        void Verti_Anti()
        {
            int j = k;
           // label1.Text = "start";
            for (; j < (k + 100); j++)
            {
                PortAccess.Output(data, single_atop[(j) % 4]);
                System.Threading.Thread.Sleep(200);
            }
            k = j;
        }
        public int i = 0,k=0;
        public int[] single_a = new int[8] { 1, 2, 4, 8, 1, 2, 4, 8 };
        public int[] single_atop = new int[8] { 16, 32, 64, 128, 16, 32, 64, 128 };
        public int[] single_ctop = new int[8] { 128, 64, 32, 16, 128, 64, 32, 16 };
        public int[] single_c = new int[8] { 8, 4, 2, 1, 8, 4, 2, 1 };
        public int[] dual_c = new int[8] { 3, 6, 12, 9, 3, 6, 12, 9 };
        public int[] dual_a = new int[8] { 9, 12, 6, 3, 9, 12, 6, 3 };
        public int[] half_a = new int[8] { 1, 3, 2, 6, 4, 12, 8, 9 };
        public int[] half_c = new int[8] { 9, 8, 12, 4, 6, 2, 3, 1 };
       // public int control = 890, data = 888, delay = 200;
        #endregion
        private void btnDisconnect_Click(object sender, EventArgs e)
        {
            try
            {

                oGsmModem.Disconnect();
                objSMS.Disconnect();
                btnConnect.Enabled = true;
                btnDisconnect.Enabled = false;
                btnSendMsg.Enabled = false;
                btnSendClass2Msg.Enabled = false;
                btnCheckPhone.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }


        }
        mCore.SMS objSMS = new mCore.SMS();
        private void SetCommParameters()
        {
            //Set communication parameters
            //check if port is already connected

            try
            {
                if (!objSMS.IsConnected && cboComPort.SelectedIndex > 0)
                {
                    objSMS.Port = cboComPort.Text;
                    
                }
            }
            catch (mCore.GeneralException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnSendMsg_Click(object sender, EventArgs e)
        {
            btnSendMsg.Text = "Sending SMS...Please Wait...";
            btnSendMsg.Enabled = false;
            System.Windows.Forms.Application.DoEvents();
            
            try
            {
                SetCommParameters();

                //Set message validity period
                       
                
               
                    //Send the message
                    string strSendResult = objSMS.SendSMS(txtPhoneNumber.Text, txtMsg.Text, true);

                    MessageBox.Show("Message sent!\r\n\r\n[Message Ref.: " + strSendResult + "]");
                
            }
            catch (mCore.SMSSendException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (mCore.GeneralException ex)
            {
                MessageBox.Show(ex.Message );
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message );
            }

            btnSendMsg.Text = "Send Message";
            btnSendMsg.Enabled = true;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (WhichDll.Equals("ATSMS"))
            {
                oGsmModem.Disconnect();
            }
            if (cboComPort.Text.Length <= 1)
            {
                MessageBox.Show("Please Select a comprot");
                cboComPort.Focus();
                return;
            }
            objSMS.Port = cboComPort.Text;
            //sending...
            
                

                try
                {
                    objSMS.Connect();
                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                
                MessageBox.Show("connected");
                GetDetails();
                WhichDll = "mCore";
                btnDisconnect.Enabled = true;
                btnConnect.Enabled = false;
                btnSendMsg.Enabled = true;
        btnSendClass2Msg.Enabled = true;
        btnCheckPhone.Enabled = true;
        }

        private void btnCheckPhone_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Going to analyze the phone please wait");
             oGsmModem.CheckATCommands();
             if (oGsmModem.ATCommandHandler.Is_SMS_Received_Supported)
             {
                 MessageBox.Show("Your phone is able to receive SMS. Message indication command is " + oGsmModem.ATCommandHandler.MsgIndication);
                 oGsmModem.NewMessageIndication = true;
             }
             else
                 MessageBox.Show("Sorry. Your phone cannot receive SMS");
            
        }
        string strMyAppName = "Integrated Ideas";

        void Analyze()
        {
            /* concepts corresponding to atsms dll
            System.IO.Ports.SerialPort sp = new System.IO.Ports.SerialPort();
            sp.PortName = "COM17";
            sp.BaudRate = 1900;
            sp.Write("Commands");
              */
            string s = Information.Message;
            
         //   MessageBox.Show("mobile="+Information.MobNo+ " command= "+s );
            if (s.Equals("Bulb On"))
            {
                BulbOn();
              
                

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -