private void Form1_Load(object sender, EventArgs e)
        {
            for (byte i = 0; i < 50; i++)
            {
                comm = new GsmCommMain((i + 1), 9600, 300);
                try
                {
                    comm.Open();
                    if (comm.IsConnected() == true)
                    {
                        comboBox1.Items.Add((i+1));
                    }
                    comm.Close();
                }
                catch (Exception)
                {
                }
            }

            if (comboBox1.Items.Count > 0)
            {
                comboBox1.SelectedIndex = 0;
            }
            else
            {
                MessageBox.Show("Tidak Ada port yang terbuka !!!\n "+
                    "Cek kembali bluetooth Anda !","Warning !!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }
示例#2
0
        private void btnTesKoneksi_Click(object sender, EventArgs e)
        {
            var port = "COM1"; // port yang digunakan menyesuaikan
            var baudRate = 9600;
            var timeout = 150;

            comm = new GsmCommMain(port, baudRate, timeout);
            comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);

            try
            {
                comm.Open();

                while (!comm.IsConnected())
                {
                    var msgResult = MessageBox.Show(this, "No phone connected.", "Connection setup",
                                                    MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);

                    if (msgResult == DialogResult.Cancel)
                    {
                        comm.Close();
                        return;
                    }
                    else
                    {
                        comm.Close();
                        comm.Open();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Connection error: " + ex.Message, "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#3
0
        public void connect()
        {
            string cmbCOM = "COM" + comms.Text;
            comm = new GsmCommMain(cmbCOM, 9600, 150);

            try
            {

                if (comm.IsConnected())
                {
                    info.Content = comm.IdentifyDevice().Manufacturer.ToUpper().ToString();
                    info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Manufacturer.ToUpper().ToString();
                    info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Model.ToUpper().ToString();
                    info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Revision.ToUpper().ToString();
                    info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().SerialNumber.ToUpper().ToString();
                    info.Content = info.Content + Environment.NewLine + comm.GetCurrentOperator();
                    info.Content = info.Content + Environment.NewLine + comm.GetSignalQuality();
                    info.Content = info.Content + Environment.NewLine + comm.GetSmscAddress();
                    info.Content = info.Content + Environment.NewLine + comm.GetSubscriberNumbers();
                    save.Visibility = Visibility.Visible;


                    Console.WriteLine("comm is already open");

                }
                else
                {
                    Console.WriteLine("comm is not open");
                    comm.Open();

                    info.Content = comm.IdentifyDevice().Manufacturer.ToUpper().ToString();
                    info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Manufacturer.ToUpper().ToString();
                    info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Model.ToUpper().ToString();
                    info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Revision.ToUpper().ToString();
                    info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().SerialNumber.ToUpper().ToString();
                    save.Visibility = Visibility.Visible;

                }

            }
            catch (Exception r)
            {

                MessageBox.Show(r.Message);
            }

        }
 private void vistaButton1_Click(object sender, EventArgs e)
 {
     try
     {
         comm = new GsmCommMain(int.Parse(comboBox1.Text), 9600, 300);
         comm.Open();
         if (comm.IsConnected() == true)
         {
             MessageBox.Show("Koneksi Suksess !!", "Information !!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             MessageBox.Show("Tidak Ada port yang terbuka !!!\n " +
             "Cek kembali bluetooth Anda !", "Warning !!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         comm.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#5
0
		private void btnTest_Click(object sender, System.EventArgs e)
		{
			if (!EnterNewSettings())
				return;

			Cursor.Current = Cursors.WaitCursor;
			GsmCommMain comm = new GsmCommMain(port, baudRate, timeout);
			try
			{
				comm.Open();
				while (!comm.IsConnected())
				{
					Cursor.Current = Cursors.Default;
					if (MessageBox.Show(this, "No phone connected.", "Connection setup",
						MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
					{
						comm.Close();
						return;
					}
					Cursor.Current = Cursors.WaitCursor;
				}

				comm.Close();
			}
			catch(Exception ex)
			{
				MessageBox.Show(this, "Connection error: " + ex.Message, "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				return;
			}
			MessageBox.Show(this, "Successfully connected to the phone.", "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
			
				
		}
示例#6
0
        private int? findGSMCommPort()
        {
            String[] portNames = System.IO.Ports.SerialPort.GetPortNames();
            int? portNumber = null;

            foreach (string portName in portNames)
            {
                String[] port = portName.Split(new string[] { "COM" }, StringSplitOptions.None);

                GsmCommMain comm = new GsmCommMain(Int32.Parse(port[1]), gsmBaudRate/*baudRate*/, gsmTimeOut/*timeout*/);
                try
                {
                    comm.Open();

                    if (comm.IsConnected())
                    {

                        AddressData addrData = comm.GetSmscAddress();
                        portNumber = Convert.ToInt32(port[1]);

                   }
                   comm.Close();
                   if (portNumber != null)
                       break;
                }
                catch (Exception e)
                {
                    if( comm.IsOpen())
                        comm.Close();
                }
            }

            
            return portNumber;
        }
示例#7
0
        public static string connect()
        {
            state = "false";
            int d = 0;
            do
            {
                d++;
                cmbCOM = "COM" + d.ToString();
                comm = new GsmCommMain(cmbCOM, 9600, 150);
                Console.WriteLine(cmbCOM);
                try
                {
                    if (comm.IsConnected())
                    {
                        Console.WriteLine("comm is already open");
                        ports = true;
                        state = "true";
                        break;
                    }
                    else {
                        Console.WriteLine("comm is not open");
                        comm.Open();
                        ports = true;
                        state = "true";
                    }
                    
                }
                catch (Exception)
                {
                    ports = false;
                    state = "true";

                }

            }
            while (!comm.IsConnected() && d < 30);


            Console.WriteLine(cmbCOM);
            return state;

        }
示例#8
0
        public static bool connected(string network, string comms)
        {
            netName = network;

            comm = new GsmCommMain(comms, 9600, 150);

            try
            {
                if (comm.IsConnected())
                {

                    Console.WriteLine(netName + "comm is already open");
                    okay = true;
                    if (!comm2.IsConnected())
                    {
                        comm2 = new GsmCommMain(comms, 9600, 150);

                        comm2.Open();
                        CommNetwork _cm = new CommNetwork() { Names = netName, Comms = comm2 };
                        primes.Add(_cm);
                    }
                    else
                    {

                        Console.WriteLine(netName + "all comms are open comm is already open");
                    }

                }
                else
                {
                    comm.Open();
                    CommNetwork _cm = new CommNetwork() { Names = netName, Comms = comm };
                    primes.Add(_cm);
                    Console.WriteLine(netName + "comm has connected");
                    okay = true;


                }

            }
            catch (Exception r)
            {
                Console.WriteLine("comm has failed");
                okay = false;

            }

            return okay;

        }
示例#9
0
        public static bool SendUpdate(DBObject parent, string id, string message, string number, string network, string cb)
        {
            _network = new Network(null);
            comm = new GsmCommMain(cb, 9600, 150);
            try
            {

                SmsSubmitPdu pdu;
                byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
                pdu = new SmsSubmitPdu(message, Convert.ToString(number), dcs);
                int times = 1;
                for (int i = 0; i < times; i++)
                {

                    if (comm.IsConnected())
                    {
                        Console.WriteLine("comm is already open");
                        Console.WriteLine("modem  connected:" + network + "to:" + comm);
                        _network.UpdateStatus(network, "connected");
                    }
                    else
                    {
                        comm.Open();
                        _network.UpdateStatus(network, "connected");
                    }

                    comm.SendMessage(pdu);
                    _message = new Message(parent);
                    _message.Update(id, "T");

                    sent = true;
                }
                sent = true;

            }
            catch (Exception r)
            {
                sent = false;
                _network.UpdateStatus(network, "disconnected");
                Console.WriteLine("comm is already open");
            }
            return sent;
        }
示例#10
0
        private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCellStyle style = new DataGridViewCellStyle();

            style.Font = new Font(dataGridView3.Font, FontStyle.Bold);
            style.BackColor = Color.Green;
            style.ForeColor = Color.White;

                int i = dataGridView3.CurrentRow.Index;

                try
                {
                    Comm_Port =     Convert.ToInt16(dataGridView3.Rows[i].Cells[0].Value.ToString().Substring(3));
                    Comm_BaudRate = Convert.ToInt32(dataGridView3.Rows[i].Cells[2].Value.ToString());
                    Comm_TimeOut =  Convert.ToInt32(dataGridView3.Rows[i].Cells[3].Value.ToString());
                }
                catch (Exception E1)
                {
                    MessageBox.Show("Error Converting COM Port Settings Values", "Check COM Port Values", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut);

                try
                {

                        comm.Open();
                        if (comm.IsConnected())
                        {

                            pictureBox3.Image = imageList1.Images[1];

                            MessageBox.Show("Connected Successfully To GSM Phone / Modem...!!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            dataGridView3.Rows[i].Cells[4].Value = "Connected";
                            dataGridView3.Rows[i].DefaultCellStyle = style;
                            dataGridView3.ClearSelection();
                            Single_SMS.Enabled = true;

                        }

                        try
                        {
                            Phone_Name.Text = comm.IdentifyDevice().Manufacturer.ToUpper().ToString();
                            Phone_Model.Text = comm.IdentifyDevice().Model.ToUpper().ToString();
                            Revision_Num.Text = comm.IdentifyDevice().Revision.ToUpper().ToString();
                            Serial_Num.Text = comm.IdentifyDevice().SerialNumber.ToUpper().ToString();
                        }
                        catch (Exception e50)
                        {
                            MessageBox.Show("Error Retriving COM Port Phone Information"+e50, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                }
                catch (Exception E2)
                {
                    MessageBox.Show("Error While Connecting To GSM Phone / Modem"+E2, "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dataGridView3.ClearSelection();

                }
        }
示例#11
0
        private void button1_Click(object sender, EventArgs e)
        {
            DataGridViewCellStyle style = new DataGridViewCellStyle();

            style.Font = new Font(dataGridView3.Font, FontStyle.Bold);
            style.BackColor = Color.Green;
            style.ForeColor = Color.White;

            int i = dataGridView3.CurrentRow.Index;

            try
            {
                Comm_Port = Convert.ToInt16(listBox1.SelectedItem.ToString().Substring(3));

                Comm_BaudRate = Convert.ToInt32(listBox2.SelectedItem.ToString());

                Comm_TimeOut = Convert.ToInt32(dataGridView3.Rows[i].Cells[3].Value.ToString());
               //load   = new loadSettings(Comm_Port,Comm_BaudRate,Comm_TimeOut);

               //   load.Show();

            }
            catch (Exception E1)
            {
                MessageBox.Show("Error Converting COM Port Settings Values"+E1.Message.ToString(), "Check COM Port Values", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut);

            try
            {
                if (!comm.IsOpen())

                comm.Open();
                if (comm.IsConnected())
                {

                    MessageBox.Show("Connected Successfully To GSM Phone / Modem...!!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dataGridView3.Rows[i].Cells[4].Value = "Connected";
                    dataGridView3.Rows[i].DefaultCellStyle = style;
                    dataGridView3.ClearSelection();

                }

            }
            catch (Exception E2)
            {
                MessageBox.Show("Error While Connecting To GSM Phone / Modem/nError:" + E2.Message.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dataGridView3.ClearSelection();

            }
            //load.Close();
        }