473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Wagsy
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?

Thanks
Sep 7 '07 #1
7 4181
Wagsy
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:-
0.000.000.000.00 etc... how do i format and keep left?
Sep 8 '07 #2
Robbie
180 100+
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. ;)
Sep 8 '07 #3
Wagsy
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
Robbie
180 100+
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
  6.  
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
  5.  
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
  10.  
(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
Wagsy
14
Thanks very much Robbie, i'll give this a go and keep you informed. :-)
Sep 12 '07 #6
Wagsy
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
@Wagsy
Hey friend I am facing the same problem.
Do you get the solution out of it?

Please help me out.
Oct 19 '14 #8

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

Similar topics

1
by: Dan | last post by:
I wnat to see in browser an status from an device connected on rs232 port The java class for read from serial port is: //Serial.java import java.io.*; import java.util.*; import...
2
by: Jim Dabell | last post by:
I'm in the middle of writing a small app for Linux that needs to create directories that take their names from untrusted data. If possible, I'd like to preserve special characters rather than...
21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
1
by: Patrick | last post by:
Hi all, New to .NET, I'm working on an Winforms client application using VS 2005 beta2. My needs considering data storage are the followings: (1) Small files (0 < length < 10 mb), containing...
1
by: panche | last post by:
I'm developing a fairly simple user control that has two textboxes for date/time entry (a from date/time and a to date/time). One of my requirements is that there should be no button that sets...
3
by: Przemo | last post by:
Hi, Do you know some good RS232C class? There is one in VB.NET 101 Examples, but I think it is poor. 1. I can't for e.g. read into my application all data received. I must tell how many...
13
by: jay.dow | last post by:
I want to write to the pins of an RS232 without using the serial protocol. The use would be every pin could act to complete a circuit in customized hardware. I could use python to communicate...
2
by: KCUK | last post by:
I have created a software to receive data from an equipment through RS232 communication. It is a simple application of the RS232 class. The software does receive strings from the equipment every time...
4
by: Dave Harry | last post by:
I found the RS232 class from MS's 101 VB samples. Writing to the port works fine. (I've got hyperterminal on the other comm port and a crossover cable between COM1 and COM2) The port is opened...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.