Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. MSComm serial port control HELP!!!

MSComm serial port control HELP!!!

Scheduled Pinned Locked Moved Visual Basic
helpcsharpcomquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maria_p
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • M maria_p

      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

      J Offline
      J Offline
      John Kuhn
      wrote on last edited by
      #2

      Perhaps you should try posting this in the C# message board instead of the VB message board?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups