Reeciev a single charcater (8 bits) from Serial port using Mscomm


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Reeciev a single charcater (8 bits) from Serial port using Mscomm

  1. #1
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    84

    Reeciev a single charcater (8 bits) from Serial port using Mscomm

    Hi

    I wish to receive single character from an electronic device connected to PC via serial comm . I have used MSCOMM control. See the code below

    Mscomm_oncomm

    Dim X As String
    X = Convert.ToString(mscomm.input)
    Dim substring As String = X.Substring(2, 1)


    endsub

    I am not receiving anything. However when I store the X variable into a file, I can see the charcater received. But I am interested in displaying the charcater rather than stroing into a binary file

    Any help would be appreciated ?

    Regards

    Faisal
    Last edited by pfaisalbe; 04-06-2011 at 12:15 PM.

  2. #2
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    I am surprised you don't get an error. you named your variable the same as one of the String objects methods.
    Try using a different variable name.
    Also did you realize that the Substring Methods Index is Zero based, therefore X.Substring(2, 1) returns the third character in the string.
    There could also be non-printable characters in the input string, as a test, try looping through one character at a time until you find the character you are looking for.

  3. #3
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    84
    Thanks Ron weller.

    I am surprised you don't get an error. you named your variable the same as one of the String objects methods.

    I won't be surprised , since this is ms product.

    It works when I use the following lines

    Mscomm_oncomm

    If MSComm1.CommEvent = 2 Then
    InBuff1 = MSComm1.Input
    InBuff3 = InBuff3 & InBuff1
    End if

    If (InBuff1 = "A") Then
    SENDDATA("Acknowledgment received")
    End If

    End sub


    on the other hand If I use the following lines. It does not work


    Mscomm_oncomm

    If MSComm1.CommEvent = 2 Then
    InBuff1 = MSComm1.Input
    InBuff3 = MSComm1.Input
    End if

    If (InBuff3 = "A") Then
    SENDDATA("Acknowledgment received")
    End If

    End sub



    This put me in to ask question about how the Mscomm_ oncomm event is fired

    For the serial communication ,

    startbit , data bit and stopbit

    startbit would be zero ,followed by data bit and start bit would be 1.

    I guess
    Oncomm event starts from start bit and finish at stop bit. This time is shorter than time needed to execute statement 2 from after statement 1 is execuited. So Inbuff3 should not have data , I am looking for

    InBuff1 = MSComm1.Input // statement 1
    InBuff3 = MSComm1.Input // statement 2


    Please comment


    Regards

    Faisal
    Last edited by pfaisalbe; 04-08-2011 at 08:12 AM.

  4. #4
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Check out the InputLen property. It defaults to zero, which means to retreive the entire receive buffer. If you only want one character at a time then set it to one.
    Mscomm1.InputLen = 1

    Also there is InputMode, 0 retreives data as characters in a string, and 1 retreaves data as binary 8 bit values into a byte array.

    You can also use the InBufferCount property to find out how many characters are in the receive buffer. Do this before you call Input and you can see if anything is there first.

    One more property InBufferSize defaults to 1024, and is the size of the receive buffer. If you get alot of overflows you can increase this value. Of course you can avoid overflows by using handshaking.

  5. #5
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    One more thing...check here for information on the CommEvent.
    http://msdn.microsoft.com/en-us/libr...05(VS.60).aspx

  6. #6
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    I do not program communication ports myself, but I am still puzzled as to why so many programmers still insist on using the 15 years old MSComm in .NET, with all the complications it seems to show (and with reasons, old VB6 stuff does not translate well into the .NET world) while there is a SerialPort control in the framework?
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  7. #7
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    84
    Thanks Jacques Bourgeois

    but I am still puzzled as to why so many programmers still insist on using the 15 years old MSComm in .NET, with all the complications it seems to show (and with reasons, old VB6 stuff does not translate well into the .NET world) while there is a SerialPort control in the framework?

    I am not a professional programmer. My objective is to get the work done. I have tried using serial port control in vb.net. Unfortunately I was not successful , I have faced some issues in data format while sending data to Host PC. So I have reverted back to Mscomm.

Similar Threads

  1. Replies: 0
    Last Post: 02-02-2011, 10:42 AM
  2. open Serial port, send array of hex bytes
    By rciprogrammer in forum C++
    Replies: 8
    Last Post: 03-10-2009, 05:45 PM
  3. "using kernel32 to read serial port into Excel" Reloaded
    By brumbarchris in forum VB Classic
    Replies: 2
    Last Post: 11-19-2008, 06:54 PM
  4. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 11:40 PM
  5. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center