RS232 scale data string needs 'filtering' or 'parsing'?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wagsy
    New Member
    • Apr 2007
    • 14

    RS232 scale data string needs 'filtering' or 'parsing'?

    Hi All,
    I have a small form that allows scale weigh data to be diplayed in a textbox. i can communicate with the scale - tare, zero etc.

    how do i filter the weight string or i think it may be called parsing? i'll try to explain: currently i can have the scale sending continuous weight data, but i can also set it to print every secon or so, this looks messy however 'cos the textbox flickers.

    when the weight changes on the scale a question mark appears to show motion - but i dont want this in the textbox, also the textbox weight display shifts because of the extra chr$

    if i use continuous data stream how can i check for inital chr$ or parse this data so it looks all neat n tidy?

    i think i need to look for certain chr$ <LF><CR> or something?

    Thanks
  • Wagsy
    New Member
    • Apr 2007
    • 14

    #2
    Its me|! someone told me to first convert to Val then put into the textbox then format.

    i managed to convert to Val, put it in txtxbox but now the weight just 'concanteates'?

    i.e. what should be 0.00 looks like:-
    0.000.000.000.0 0 etc... how do i format and keep left?

    Comment

    • Robbie
      New Member
      • Mar 2007
      • 180

      #3
      Hi. I don't know have an RS-232, or even know what it does (I only have a board called SSC-32, it's for controlling servos, and a few other functions).


      Please could you explain what actually happens - it sounds like the RS-232 is returning data to you, which you are able to receive, but you only want SOME of what it's giving back, and you want to look out for a character which is separating what you DO and DON'T want.

      Well...
      If the data it gives back DOES have values separated by a new line, you would be able to find them like this:

      dim SeparatePos as long
      SeparatePos = InStr(1, DataString, vbCrLf)

      (DataString being the string given back from the RS-232).

      SeparatePos would now contain the position of the first new-line. Then you can use Mid() to get everything up to, or after, that character.

      Up to:
      NewString = Mid(NewString, 1, SeparatePos-1)
      After:
      NewString = Mid(NewString, SeparatePos+1)

      You may need to change the vbCrLf in the first piece of code into either vbCr or vbLf. This is because often, new-lines are written as chr(13) and chr(10) together (this is vbCrLf), but sometimes it's just chr(13) (vbCr) or chr(10) (vbLf).

      If it was a space that separated the values, then use " " or if you like for some reason, chr(32).

      Like I said, I'm not sure what exactly you even want, but I've tried to help with what I can make out.

      As for why the text in the textbox is 'concatenating' , it wouldn't by itself - you must either be saying:
      t.Text += TextString
      or
      t.Text = t.Text + TextString
      or
      TextString = TextString + NewString
      t.Text = TextString


      Please let me know more precisely what you'd like to achieve. ;)

      Comment

      • Wagsy
        New Member
        • Apr 2007
        • 14

        #4
        Hi Robbie,

        OK... the default serial output from the scale is:

        Polarity = 1chr$
        Space = 1chr$
        Weight = 7chr$
        Space = 1chr$
        Units = 5chr$
        Stability = 1chr$
        CR = 1chr$
        LF = 1chr$

        Definitions: Polarity, “-” sign if negative, blank if positive.
        Weight, up to 6 numbers and 1 decimal, right justified, leading zero blanking.
        Units, up to 5 characters.
        Stability, “?” character is printed if not stable, blank if stable.

        The code i have upto now is:

        PrivateSub MSComm1_OnComm( )
        Dim strInput, strWeight As String
        With MSComm1
        'test for incomming
        Select Case .CommEvent
        'display to TextBox
        strInput = .Input
        strWeight = Val (strInput)
        strWeight = Format(strWeigh t, "")
        Text1.SelText = strWeight
        End Select
        End With 'MSComm1
        End Sub

        In my text box all i want to see is the weight left justified in the textbox if possible. At the moment it is right justified but it also concantenates to the right. For example 1.245 would soon become 1.2451.2451.245 etc!

        I have been playing with the format thing but has strange effects. Anyway all advice welcome. Thanks.

        Scale Manual Note:
        "Note: If the Print Content-Numeric Only is set to On, the Units and Stability fields are omitted." This may be worth considering...

        Comment

        • Robbie
          New Member
          • Mar 2007
          • 180

          #5
          I'm going to pretend the textbox you want the weight to go into is called txtWeight.
          If you are doing:
          txtWeight.Text = txtWeight.Text + strWeight
          ...then it's obvious it would concatenate.
          BUT, I don't imagine that you're doing that.
          I think that the input from the comm is never clearing, and so you're building up a massive string in .Input where there are many copies of received text from the RS-232.

          The way I always deal with the comm is like this (adapted to suit your code) :
          [code=vb]
          Private Sub MSComm1_OnComm( )
          Dim strInput, strWeight As String
          strInput = MSComm1.Input
          '[DEAL WITH strInput HERE]
          End Sub
          [/code]
          When I do that, the .Input clears itself so that the next time the OnComm event comes along, Input only contains new text. I thought it reset to being blank whenever you accessed it, so it not clearing seems a little weird to me. (Are you even using VB6?)

          So every string you receive from the RS-232 should ALWAYS be 18 characters? If that's so, then this is how you can 'extract' each part of the text...
          These are the data types:
          [code=vb]
          dim rsPolarity as Boolean 'True means Positive
          dim rsWeight as Double
          dim rsUnits as Double
          dim rsStability as Boolean 'True means Stable
          [/code]
          This is how you can set their values:
          [code=vb]
          strInput = MSComm1.Input
          rsPolarity = Iif(mid(strInpu t,1,1)=" ",True, False)
          'If the first character is a space, rsPolarity becomes True, otherwise False
          rsWeight = Val(mid(strInpu t,3,7))
          'rsWeight becomes the numeric value of characters 3 -> 9 (7 chars)
          rsUnits = Val(mid(strInpu t,11,5))
          'rsUnits becomes numeric value of chars 11 -> 15 (5 chars)
          rsStability = Iid(mid(strInpu t,16,1)=" ",True, False)
          'If the 16th character is a space, rsStability becomes True, otherwise False
          [/code]
          (I presume that when you say "blank", you mean a space?)

          Now to set the value of the textbox, you'd do:
          txtWeight = cStr(rsWeight)

          Please let me know if it helps! (Or if it doesn't... but you're more likely to let me know if it doesn't =P)

          P.S. I don't think you need to set content-numeric to On. ^-'

          Comment

          • Wagsy
            New Member
            • Apr 2007
            • 14

            #6
            Thanks very much Robbie, i'll give this a go and keep you informed. :-)

            Comment

            • Wagsy
              New Member
              • Apr 2007
              • 14

              #7
              Hi Robbie,
              think im getting somewhere now! however the actual displayed weight appears to be 'flashing' somewhat. may go from 0 to 1.454 (the 0 appears to be most prominant and the 1.454 is faint because its refresh rate is too quick or slow?)

              someone suggested putting a timer function in to set the refresh rate of the text1.text .

              im not sure how to implement this? any ideas? thanks.

              Comment

              • sparth999
                New Member
                • Oct 2014
                • 1

                #8
                Originally posted by Wagsy
                Hi Robbie,
                think im getting somewhere now! however the actual displayed weight appears to be 'flashing' somewhat. may go from 0 to 1.454 (the 0 appears to be most prominant and the 1.454 is faint because its refresh rate is too quick or slow?)

                someone suggested putting a timer function in to set the refresh rate of the text1.text .

                im not sure how to implement this? any ideas? thanks.
                Hey friend I am facing the same problem.
                Do you get the solution out of it?

                Please help me out.

                Comment

                Working...