Help with MSComm serial port communications
-
HELP please someone I'm using MSComm with C#.....at the moment I'm communicating via a null modem connection between 2 PCs. At the moment I'm just sending out some bytes from one PC to another PC... Got the communication to work... all is well. The problem; I only expect something to be sent from one PC to other when I press a button on the sending PC which then uses the command object.Output= new byte [] {a number}; to send a byte to the other computer.... the recieving computer in turn recieves this and displays it via the ONComm event handler. The ONComm event on the recieving PC is raised when a byte arrives at the recieving PC serial port on pressing a button on the sending PC.... HOWEVER the ONComm Event is also raised (on the recieving PC)when I start up and exit the sending application. I just can't understand this! This could obviously be a really big problem... Can someone explain or have a solution to this? I would be grateful... I just can't seem to stop this event from raising when the sending application starts up or shuts down... This could be reallly disasterous if the sending PC sends something on start up (ie without me even having instructed the sending application to output a signal by pressing a button) when connected to a PICmicrocontroller which shouldn't recieve that signal.... Here is how i set up the 2 PCs; com.CommPort = 1; if (com.PortOpen) com.PortOpen = false; com.RThreshold = 1; com.Settings = "9600,n,8,1"; //com.DTREnable = true; com.Handshaking = MSCommLib.HandshakeConstants.comNone; com.InputMode = MSCommLib.InputModeConstants.comInputModeBinary; com.InputLen = 0; com.NullDiscard = false; com.OnComm += new System.EventHandler(this.OnComm); com.PortOpen = true; Here is the ONComm event handler on the recieving PC which is connected with a null modem cable; // MSCommLib OnComm Event Handler private void OnComm(object sender, EventArgs e) { //Message box 1 MessageBox.Show("recieved something 1"); switch (com.CommEvent) { case (short)MSCommLib.OnCommConstants.comEvReceive: //Message box 2 MessageBox.Show("recieved something 2"); byte[] x = (byte[]) com.Input; foreach (byte byt in x) { strrecvd += (char) byt; //Message box 3 MessageBox.Show(strrecvd);........................ The only Message box that should show on the recieving PC is 3 and that only when I press a button to send a byte on the sending PC... However on the inclusion of message boxes 1 and 2 I noticed that when I started up or shut down the sending applic