By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

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

P: 14
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?

Sep 7 '07 #1
Share this Question
Share on Google+
7 Replies

P: 14
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:- etc... how do i format and keep left?
Sep 8 '07 #2

P: 180
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.

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)
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
t.Text = t.Text + TextString
TextString = TextString + NewString
t.Text = TextString

Please let me know more precisely what you'd like to achieve. ;)
Sep 8 '07 #3

P: 14
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(strWeight, "")
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...
Sep 12 '07 #4

P: 180
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) :
Expand|Select|Wrap|Line Numbers
  1. Private Sub MSComm1_OnComm()
  2.     Dim strInput, strWeight As String
  3.     strInput = MSComm1.Input
  4.     '[DEAL WITH strInput HERE]
  5. End Sub
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:
Expand|Select|Wrap|Line Numbers
  1. dim rsPolarity as Boolean 'True means Positive
  2. dim rsWeight as Double
  3. dim rsUnits as Double
  4. dim rsStability as Boolean 'True means Stable
This is how you can set their values:
Expand|Select|Wrap|Line Numbers
  1. strInput = MSComm1.Input
  2. rsPolarity = Iif(mid(strInput,1,1)=" ",True, False)
  3. 'If the first character is a space, rsPolarity becomes True, otherwise False
  4. rsWeight = Val(mid(strInput,3,7))
  5. 'rsWeight becomes the numeric value of characters 3 -> 9 (7 chars)
  6. rsUnits = Val(mid(strInput,11,5))
  7. 'rsUnits becomes numeric value of chars 11 -> 15 (5 chars)
  8. rsStability = Iid(mid(strInput,16,1)=" ",True, False)
  9. 'If the 16th character is a space, rsStability becomes True, otherwise False
(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. ^-'
Sep 12 '07 #5

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

P: 14
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.
Sep 13 '07 #7

P: 1
Hey friend I am facing the same problem.
Do you get the solution out of it?

Please help me out.
Oct 19 '14 #8

Post your reply

Sign in to post your reply or Sign up for a free account.