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

📄 frmdemo.cs

📁 a sample code for send sms using GPRS Modem.
💻 CS
📖 第 1 页 / 共 4 页
字号:
			this.label3.TabIndex = 27;
			this.label3.Text = "This application demonstrates a subset of the GSMComm functionality";
			this.label3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			// 
			// btnIsConnected
			// 
			this.btnIsConnected.Location = new System.Drawing.Point(8, 8);
			this.btnIsConnected.Name = "btnIsConnected";
			this.btnIsConnected.Size = new System.Drawing.Size(128, 32);
			this.btnIsConnected.TabIndex = 0;
			this.btnIsConnected.Text = "Is connected?";
			this.btnIsConnected.Click += new System.EventHandler(this.btnIsConnected_Click);
			// 
			// tabControl
			// 
			this.tabControl.Controls.Add(this.tabSMS);
			this.tabControl.Controls.Add(this.tabPhonebook);
			this.tabControl.Controls.Add(this.tabGeneral);
			this.tabControl.Location = new System.Drawing.Point(8, 32);
			this.tabControl.Name = "tabControl";
			this.tabControl.SelectedIndex = 0;
			this.tabControl.Size = new System.Drawing.Size(512, 240);
			this.tabControl.TabIndex = 0;
			// 
			// tabSMS
			// 
			this.tabSMS.Controls.Add(this.btnMsgMemStatus);
			this.tabSMS.Controls.Add(this.label8);
			this.tabSMS.Controls.Add(this.txtDelMsgIndex);
			this.tabSMS.Controls.Add(this.label4);
			this.tabSMS.Controls.Add(this.btnReadMessages);
			this.tabSMS.Controls.Add(this.btnDelMessage);
			this.tabSMS.Controls.Add(this.btnDelAllMsgs);
			this.tabSMS.Controls.Add(this.btnMsgStorages);
			this.tabSMS.Controls.Add(this.btnSendMessage);
			this.tabSMS.Controls.Add(this.txtNumber);
			this.tabSMS.Controls.Add(this.txtMessage);
			this.tabSMS.Controls.Add(this.label2);
			this.tabSMS.Controls.Add(this.label1);
			this.tabSMS.Controls.Add(this.btnMsgNotification);
			this.tabSMS.Controls.Add(this.btnMsgNotificationOff);
			this.tabSMS.Controls.Add(this.btnMsgRoutingOn);
			this.tabSMS.Controls.Add(this.btnMsgRoutingOff);
			this.tabSMS.Controls.Add(this.btnCopyMessages);
			this.tabSMS.Controls.Add(this.btnExportMessages);
			this.tabSMS.Controls.Add(this.btnImportMessages);
			this.tabSMS.Controls.Add(this.rbMessagePhone);
			this.tabSMS.Controls.Add(this.rbMessageSIM);
			this.tabSMS.Location = new System.Drawing.Point(4, 22);
			this.tabSMS.Name = "tabSMS";
			this.tabSMS.Size = new System.Drawing.Size(504, 214);
			this.tabSMS.TabIndex = 0;
			this.tabSMS.Text = "SMS Messages";
			// 
			// btnMsgMemStatus
			// 
			this.btnMsgMemStatus.Location = new System.Drawing.Point(152, 120);
			this.btnMsgMemStatus.Name = "btnMsgMemStatus";
			this.btnMsgMemStatus.Size = new System.Drawing.Size(128, 32);
			this.btnMsgMemStatus.TabIndex = 21;
			this.btnMsgMemStatus.Text = "Get memory status";
			this.btnMsgMemStatus.Click += new System.EventHandler(this.btnMsgMemStatus_Click);
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(80, 48);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(56, 16);
			this.label8.TabIndex = 2;
			this.label8.Text = "Index:";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// txtDelMsgIndex
			// 
			this.txtDelMsgIndex.Location = new System.Drawing.Point(80, 64);
			this.txtDelMsgIndex.Name = "txtDelMsgIndex";
			this.txtDelMsgIndex.Size = new System.Drawing.Size(56, 20);
			this.txtDelMsgIndex.TabIndex = 3;
			this.txtDelMsgIndex.Text = "1";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(432, 128);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 32);
			this.label4.TabIndex = 18;
			this.label4.Text = "Message storage";
			this.label4.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
			// 
			// rbMessagePhone
			// 
			this.rbMessagePhone.Location = new System.Drawing.Point(432, 184);
			this.rbMessagePhone.Name = "rbMessagePhone";
			this.rbMessagePhone.Size = new System.Drawing.Size(64, 24);
			this.rbMessagePhone.TabIndex = 20;
			this.rbMessagePhone.Text = "Phone";
			// 
			// rbMessageSIM
			// 
			this.rbMessageSIM.Checked = true;
			this.rbMessageSIM.Location = new System.Drawing.Point(432, 160);
			this.rbMessageSIM.Name = "rbMessageSIM";
			this.rbMessageSIM.Size = new System.Drawing.Size(64, 24);
			this.rbMessageSIM.TabIndex = 19;
			this.rbMessageSIM.TabStop = true;
			this.rbMessageSIM.Text = "SIM";
			// 
			// tabPhonebook
			// 
			this.tabPhonebook.Controls.Add(this.btnPbMemStatus);
			this.tabPhonebook.Controls.Add(this.btnPbStorages);
			this.tabPhonebook.Controls.Add(this.label9);
			this.tabPhonebook.Controls.Add(this.txtDelPbIndex);
			this.tabPhonebook.Controls.Add(this.label7);
			this.tabPhonebook.Controls.Add(this.label6);
			this.tabPhonebook.Controls.Add(this.txtPbNumber);
			this.tabPhonebook.Controls.Add(this.txtPbName);
			this.tabPhonebook.Controls.Add(this.btnCreatePbEntry);
			this.tabPhonebook.Controls.Add(this.label5);
			this.tabPhonebook.Controls.Add(this.rbPhonebookPhone);
			this.tabPhonebook.Controls.Add(this.rbPhonebookSIM);
			this.tabPhonebook.Controls.Add(this.btnExportPhonebook);
			this.tabPhonebook.Controls.Add(this.btnImportPhonebook);
			this.tabPhonebook.Controls.Add(this.btnDumpPhonebook);
			this.tabPhonebook.Controls.Add(this.btnDeletePhonebookEntry);
			this.tabPhonebook.Controls.Add(this.btnDeletePhonebook);
			this.tabPhonebook.Location = new System.Drawing.Point(4, 22);
			this.tabPhonebook.Name = "tabPhonebook";
			this.tabPhonebook.Size = new System.Drawing.Size(504, 214);
			this.tabPhonebook.TabIndex = 1;
			this.tabPhonebook.Text = "Phonebook";
			// 
			// btnPbMemStatus
			// 
			this.btnPbMemStatus.Location = new System.Drawing.Point(152, 8);
			this.btnPbMemStatus.Name = "btnPbMemStatus";
			this.btnPbMemStatus.Size = new System.Drawing.Size(128, 32);
			this.btnPbMemStatus.TabIndex = 22;
			this.btnPbMemStatus.Text = "Get memory status";
			this.btnPbMemStatus.Click += new System.EventHandler(this.btnPbMemStatus_Click);
			// 
			// btnPbStorages
			// 
			this.btnPbStorages.Location = new System.Drawing.Point(8, 136);
			this.btnPbStorages.Name = "btnPbStorages";
			this.btnPbStorages.Size = new System.Drawing.Size(128, 32);
			this.btnPbStorages.TabIndex = 5;
			this.btnPbStorages.Text = "Get supported phonebook storages";
			this.btnPbStorages.Click += new System.EventHandler(this.btnPbStorages_Click);
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(80, 48);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(48, 16);
			this.label9.TabIndex = 2;
			this.label9.Text = "Index:";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// txtDelPbIndex
			// 
			this.txtDelPbIndex.Location = new System.Drawing.Point(80, 64);
			this.txtDelPbIndex.Name = "txtDelPbIndex";
			this.txtDelPbIndex.Size = new System.Drawing.Size(56, 20);
			this.txtDelPbIndex.TabIndex = 3;
			this.txtDelPbIndex.Text = "1";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(144, 168);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(56, 24);
			this.label7.TabIndex = 7;
			this.label7.Text = "Name:";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(144, 192);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(56, 24);
			this.label6.TabIndex = 9;
			this.label6.Text = "Number:";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// txtPbNumber
			// 
			this.txtPbNumber.Location = new System.Drawing.Point(208, 192);
			this.txtPbNumber.Name = "txtPbNumber";
			this.txtPbNumber.Size = new System.Drawing.Size(128, 20);
			this.txtPbNumber.TabIndex = 10;
			this.txtPbNumber.Text = "+483341234567";
			// 
			// txtPbName
			// 
			this.txtPbName.Location = new System.Drawing.Point(208, 168);
			this.txtPbName.Name = "txtPbName";
			this.txtPbName.Size = new System.Drawing.Size(128, 20);
			this.txtPbName.TabIndex = 8;
			this.txtPbName.Text = "Test dummy";
			// 
			// btnCreatePbEntry
			// 
			this.btnCreatePbEntry.Location = new System.Drawing.Point(8, 176);
			this.btnCreatePbEntry.Name = "btnCreatePbEntry";
			this.btnCreatePbEntry.Size = new System.Drawing.Size(128, 32);
			this.btnCreatePbEntry.TabIndex = 6;
			this.btnCreatePbEntry.Text = "Create new entry";
			this.btnCreatePbEntry.Click += new System.EventHandler(this.btnCreatePbEntry_Click);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(432, 128);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(64, 32);
			this.label5.TabIndex = 14;
			this.label5.Text = "Phonebook storage";
			this.label5.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
			// 
			// rbPhonebookPhone
			// 
			this.rbPhonebookPhone.Location = new System.Drawing.Point(432, 184);
			this.rbPhonebookPhone.Name = "rbPhonebookPhone";
			this.rbPhonebookPhone.Size = new System.Drawing.Size(64, 24);
			this.rbPhonebookPhone.TabIndex = 15;
			this.rbPhonebookPhone.Text = "Phone";
			// 
			// rbPhonebookSIM
			// 
			this.rbPhonebookSIM.Checked = true;
			this.rbPhonebookSIM.Location = new System.Drawing.Point(432, 160);
			this.rbPhonebookSIM.Name = "rbPhonebookSIM";
			this.rbPhonebookSIM.Size = new System.Drawing.Size(64, 24);
			this.rbPhonebookSIM.TabIndex = 14;
			this.rbPhonebookSIM.TabStop = true;
			this.rbPhonebookSIM.Text = "SIM";
			// 
			// tabGeneral
			// 
			this.tabGeneral.Controls.Add(this.btnIdentify);
			this.tabGeneral.Controls.Add(this.btnIsConnected);
			this.tabGeneral.Controls.Add(this.btnReset);
			this.tabGeneral.Location = new System.Drawing.Point(4, 22);
			this.tabGeneral.Name = "tabGeneral";
			this.tabGeneral.Size = new System.Drawing.Size(504, 214);
			this.tabGeneral.TabIndex = 2;
			this.tabGeneral.Text = "General";
			// 
			// txtClearOutput
			// 
			this.txtClearOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.txtClearOutput.Location = new System.Drawing.Point(432, 472);
			this.txtClearOutput.Name = "txtClearOutput";
			this.txtClearOutput.Size = new System.Drawing.Size(88, 23);
			this.txtClearOutput.TabIndex = 3;
			this.txtClearOutput.Text = "Clear Output";
			this.txtClearOutput.Click += new System.EventHandler(this.txtClearOutput_Click);
			// 
			// lblNotConnected
			// 
			this.lblNotConnected.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.lblNotConnected.BackColor = System.Drawing.Color.White;
			this.lblNotConnected.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.lblNotConnected.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblNotConnected.ForeColor = System.Drawing.Color.Red;
			this.lblNotConnected.Location = new System.Drawing.Point(166, 472);
			this.lblNotConnected.Name = "lblNotConnected";
			this.lblNotConnected.Size = new System.Drawing.Size(196, 23);
			this.lblNotConnected.TabIndex = 28;
			this.lblNotConnected.Text = "NO PHONE CONNECTED";
			this.lblNotConnected.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.lblNotConnected.UseMnemonic = false;
			// 
			// frmDemo
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(528, 502);
			this.Controls.Add(this.lblNotConnected);
			this.Controls.Add(this.txtClearOutput);
			this.Controls.Add(this.tabControl);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.chkDebugTrace);
			this.Controls.Add(this.txtOutput);
			this.Name = "frmDemo";
			this.Text = "GSMComm Demo";
			this.Load += new System.EventHandler(this.frmDemo_Load);
			this.Closed += new System.EventHandler(this.frmDemo_Closed);
			this.tabControl.ResumeLayout(false);
			this.tabSMS.ResumeLayout(false);
			this.tabPhonebook.ResumeLayout(false);
			this.tabGeneral.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmDemo());
		}

		private void frmDemo_Load(object sender, System.EventArgs e)
		{
			// Prompt user for connection settings
			int port = 1;
			int baudrate = 19200;
			int timeout = 300;
			frmConnection dlg = new frmConnection();
			dlg.StartPosition = FormStartPosition.CenterScreen;
			dlg.SetData(port, baudrate, timeout);
			if (dlg.ShowDialog(this) == DialogResult.OK)
				dlg.GetData(out port, out baudrate, out timeout);
			else
			{
				Close();
				return;
			}

			Cursor.Current = Cursors.WaitCursor;
			comm = new GsmComm(port, baudrate, timeout);
			Cursor.Current = Cursors.Default;
			comm.PhoneConnected += new EventHandler(comm_PhoneConnected);
			comm.PhoneDisconnected += new EventHandler(comm_PhoneDisconnected);

			bool retry;
			do
			{
				retry = false;
				try
				{
					Cursor.Current = Cursors.WaitCursor;
					comm.Open();
					Cursor.Current = Cursors.Default;
				}
				catch(Exception)
				{
					Cursor.Current = Cursors.Default;
					if (MessageBox.Show(this, "Unable to open the port.", "Error",
						MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry)
						retry = true;
					else
					{
						Close();
						return;
					}
				}
			}
			while(retry);
		}

		private void frmDemo_Closed(object sender, System.EventArgs e)
		{
			if (comm != null)
			{
				comm.Close();
				comm = null;
			}
		}

		private void Output(string text)
		{
			lock(this)
			{
				txtOutput.AppendText(text);
				txtOutput.AppendText("\r\n");
			}
		}

		private void ShowException(Exception ex)
		{
			Output("Error: " + ex.Message + " (" + ex.GetType().ToString() + ")");
			Output("");
		}

		private bool Confirmed()
		{
			return (MessageBox.Show(this, "Really?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
				== DialogResult.Yes);
		}

		private bool CheckConnection()
		{
			try
			{
				Cursor.Current = Cursors.WaitCursor;
				while (!comm.IsConnected())
				{
					Cursor.Current = Cursors.Default;
					if (MessageBox.Show(this, "No phone connected.", "Warning",
						MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
						return false;
					else
						Cursor.Current = Cursors.WaitCursor;
				}
				Cursor.Current = Cursors.Default;
				return true;
			}
			catch(Exception ex)
			{

⌨️ 快捷键说明

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