Results 1 to 16 of 16

Thread: MSComm1 Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    9

    Exclamation MSComm1 Help

    I'm trying to read in strings of hex values, 12 bytes in total (ex. 01 09 0C 96 38 F0 07 00 00 00 00 5C). I want to be able to take these strings, ignore the first three bytes (they're always the same), and compare them so that they can be used in IF statements (ie IF "hex string" comes in, send out value). The deal is that I have very little Visual Basic experience. If someone could give me a few pointers it would be greatly appreciated.

  2. #2
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: MSComm1 Help

    This is off the top of my head but basically use mid to grab the data you want
    Then use select case to compare it to known values and respond accordingly.
    Code:
    dim myInput as string
    myInput=trim(mid(myInput,10,len(myInput))) 'should recreate the string starting at 4th byte
    
    select case myInput
    
    case "96 38 F0 07 00 00 00 00 5C"
    'output serial command here
    
    case "96 37 FA 27 00 00 00 00 FF"
    'output serial command here
    
    case else
    
    end select
    Truly, you have a dizzying intellect.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    9

    Re: MSComm1 Help

    I'm not sure I really understand the code. As I said I have very little experience with VB.

    Here is the code that I have so far. All it does is takes in the data and outputs it to a text box. How could I insert that code in there to display just the 9 bytes in the text box?

    Code:
    Private Sub cmdRun_Click()
    Do
    dummy = DoEvents()
    Loop Until MSComm1.InBufferCount >= 12
    Value = MSComm1.Input
    Text1.Text = Value
    Timer1.Enabled = True
    End Sub
    
    Private Sub Option1_Click()
    On Error GoTo Error:
    MSComm1.PortOpen = False
    Exit Sub
    Error:
    MsgBox "Cannot Perform Function"
    End Sub
    
    Private Sub Option2_Click()
    MSComm1.PortOpen = True
    End Sub
    
    Private Sub Timer1_Timer()
    cmdRun_Click
    End Sub
    Last edited by Jeff_T_H; Apr 12th, 2007 at 08:14 AM.

  4. #4
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: MSComm1 Help

    try this...
    Code:
    text1.text=trim(mid(Value,10,len(Value)))
    Truly, you have a dizzying intellect.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    9

    Re: MSComm1 Help

    I have tried to insert that code, but nothing is appearing in the text box. If i remove that and just print Value I get values such as " –8ð" (there's usually more black bars or boxes in place of the space). Another question, the hex values coming in get changed into those ascii character when displayed in the text box. Is there any way to prevent this from happening so that we can just get the hex?

    Code:
    Private Sub cmdRun_Click()
    Do
    dummy = DoEvents()
    Loop Until MSComm1.InBufferCount >= 12
    Value = MSComm1.Input
    Text1.Text = Trim(Mid(Value, 10, Len(Value)))
    
    Select Case Value
     Case "96 38 F0 07 00 00 00 00 5C"
             'output serial command here
       Text2.Text = 5
     Case "07 39 F0 07 00 00 00 00 CC"
              'output serial command here
     Case Else
    End Select
    Timer1.Enabled = True
    End Sub

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: MSComm1 Help

    Installation Question?????

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    9

    Re: MSComm1 Help

    What?

  8. #8
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: MSComm1 Help

    You are posting in the Application Deployment Forum and there are no deployment questions.

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    9

    Re: MSComm1 Help

    Where would be the best place to post?

  10. #10
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: MSComm1 Help

    It depend on your question. If you are asking about VB6 then the Visual Basic Classic forum if VB.Net then the Visual Basic .NET forum... About Application Deployment... Then this forum

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: MSComm1 Help

    Moved to Classic VB forum

  12. #12
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: MSComm1 Help

    As I mentioned in the other post, you need to use Byte Arrays to get your data from the RS232 port correctly.
    Truly, you have a dizzying intellect.

  13. #13
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: MSComm1 Help

    Hello.
    By the way did you check if you're getting this string on other software? Sometimes, because of bad configuration, you won't be able to get anything, even your program is perfect.
    Best regards

  14. #14

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    9

    Re: MSComm1 Help

    We've used programs called "HHD Serial Monitor" and "Advanced Serial Port Terminal" to read the information sent back and forth between computer and our RFID reader. Every time there is a valid read of a transponder we get back a values such as 01 09 0C 07 39 F0 07 00 00 00 00 CC. We have it set up for 9600.8.n.1 which is what the reader operates at.

  15. #15

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    9

    Re: MSComm1 Help

    Thanks for the help. We now have our problem solved!!!!

  16. #16
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: MSComm1 Help

    What you're getting back is the values (in hex) 01 09 0C 96 38 F0 07 00 00 00 00 5C. What you want to display are the characters "0", "1", " ", "0", "9", etc. What you're seeing is "☺ ♀ û 8 ≡ • \" (plus a few non-printable characters - the 09 and the 00 values, in this case).

    The input isn't "01 09 0c ...", it's ""☺<a tab here>♀ ...", so your case statement will never match anything.

    If you want to display the input, either get the input as an array of byte, or input it as a string (you'll need the Asc() of each character instead of the value of each element of the byte array) and convert each value into a 2-byte string representing its hex value. There are examples on the site, but basically you use the value of each part of the character ((value And 240) \ 16) and (value And 15) to select the nth element of a 16 element string array, ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F").

    5C, for instance, is 92. (92 And 240) \ 16 is 5, so Array(5) is "5". 92 And 15 is 12. Array(12) is "C". So Array(5) & Array(12) is "5C".

    For the case statement you'd need a string consisting of Chr$(1) & Chr$(9) & Chr$(12) ... or you could take your hex string (the one you'd display) and use your current case statement.

    BTW, you should really use the OnComm event to get serial input. Polling the port is very CPU-intensive. Also, there's no need to use the DoEvents() function if you're not going to use the return - just use the DoEvents statement.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width