![]() When the incoming message arrives, the comm_MessageReceived method will be invoked which in turn calls the MessageReceived() method in order to process the unread message. We will register with MessageReceivedEventHandler. This event is invoked when a message arrives at the GSM phone. The event handler for Phone connected is comm_PhoneConnected which will invoke OnPhoneConnectionChange(bool connected) with the help of Delegate ConnectedHandler. This event is invoked when you try to open the Comm port. We are going to register the following events for GSMComm object comm. " Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Information) ![]() MessageBox.Show( this, " Successfully connected to the phone.", display message if connection is a success. " Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning) MessageBox.Show( this, " Connection error: " + ex.Message, Close Comm port connection (Since it's just for testing // connection) MessageBoxIcon.Exclamation) = DialogResult.Cancel) " Connection setup", MessageBoxButtons.Retr圜ancel, If (MessageBox.Show( this, " No phone connected.", GsmCommMain comm = new GsmCommMain(port, baudRate, timeout) If any problem occurs "Phone not connected" message appears and you can either retry by clicking on the Retry button or else Cancel. The following block of code will try to connect. The EnterNewSettings() does validation, returns true if valid, and will invoke SetData(port,baud,timeout) for comm setting. Change the baud rate and check again by clicking the Test button until you get a message "Successfully connected to the phone."īefore creating a GSMComm object with settings, we need to validate the port number, baud rate and Timeout. This is mainly due to Baud rate settings. Sometimes if the comm port is unable to open, you will get a message "No phone connected". We can test the Comm port settings by clicking on the Test button after selecting the Comm port, baud rate and Time out. Then try to open with the above settings. We have to set the Comm port, Baud rate and time out for our comm object of type GsmCommMain. // TODO: Add constructor logic here //Ĭomm is an object of type GsmCommMain which is required for sending and receiving messages.
0 Comments
Leave a Reply. |