PDA

View Full Version : I have a little project going that has a BS2 sitting between a PC & a digital s



4 yrs later
04-10-2007, 06:08 AM
Please tell me, what am I missing.....
I have a little project going that has a BS2 sitting between a PC & a digital scale (or balance, if you prefer). The balance outputs nice RS232 that's a snap to configure and serin to the stamp, while on the PC I've been working out a VB app to send setpoint values to the stamp, which will compare the weights against and do some simple proportional control.
I'm getting stuck with the data types from the VB app. The setpoints are values from an excel worksheet, grabbed by the VB data object. I believe they are brought into the form as text. I have tried different variable types in VB with the goal of doing some simple math in the stamp, but it would seem that only the values from the pc are giving me fits with wacky results that don't even seem to be ascii values. I even set up a lookup table in the stamp program to convert ascii 48 through 57 to 0 - 9, but the math tha the stamp does afterward is still screwy.
What should I be looking at or thinking of?

Post Edited By Moderator (Chris Savage (Parallax)) : 4/10/2007 12:43:12 AM GMT

Franklin
04-10-2007, 06:23 AM
The stamp does integer math, that might be your problem. Could you show us a peice of your code so we could see if there is a problem you are overlooking. How do you format your numbers when you input them to the stamp for instance.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

4 yrs later
04-10-2007, 07:20 AM
Thanks. I'm aware of the integer limitation with the·stamp - I've done similar projects before and this is the first time I've been stumped like this.
The data contains·byte-size numbers, which I verified by assigning them to string variables and checking length with the Len() function...with numbers > 9 & < 99 I've split the strings into individual bytes, which I can serout from the stamp to a seetron display: I can't add the two back together with or w/o·the dec modifier.

I don't have the code here, or I would have shared it already.

4 yrs later
04-10-2007, 11:35 PM
Here are my rantings and ravings - first the VB code, then the stamp:

Private Sub Command2_Click()
Dim nit As String
Dim nit10s As Byte
Dim nit1s As Byte
Dim wait As Byte
Dim co2_int As String
Dim co2 As String
Dim co21 As String
Dim co22 As String
co2 = Text2.Text
ndigits = Len(Text3.Text)
'If ndigits > 1 Then
nit10s = Left$(Text3.Text, 1)
nit1s = Right$(Text3.Text, 1)

Label5.Caption = Len(Text3.Text)
Label6.Caption = Len(nit1s) ' (nit_int)
Label7.Caption = Len(nit10s)
Label8.Caption = nit
Label12.Caption = nit1s
Label13.Caption = nit10s
'MSComm1.Output = 9 & Val(nit) ' & nit2 'test
'MSComm1.Output = Chr$(255) & nit & Chr$(255) 'last working line 4/9 330 pm
MSComm1.Output = Chr$(255) & nit10s & nit1s & Chr$(255)
End Sub

Hers's what I have been trying in the BS2:

' {$STAMP BS2}
co21 VAR Byte
co22 VAR Byte
co23 VAR Byte
nit VAR Byte
'n2 VAR Byte
f VAR Byte
g VAR Byte
h VAR Byte
junk VAR Byte
i VAR Byte
j VAR Byte
k VAR Byte
l VAR Byte
z VAR Byte
'co2total VAR Word
'n2total VAR Word
n_act VAR Byte
error VAR Byte
proportion CON 10
n2_sp VAR Byte
n10 VAR Byte
n1 VAR Byte
res10 VAR Byte
res1 VAR Byte

OUTPUT 9
OUTPUT 10
OUTPUT 11
OUTPUT 12
begin:
SEROUT 1, 16780, [254, 1]
SEROUT 1, 16780, ["WINSLOW LIFERAFT"]
SEROUT 1, 16780, [254, 192]
SEROUT 1, 16780, [" AUTOMATED"]
PAUSE 1000
SEROUT 1, 16780, [254, 1]
SEROUT 1, 16780, [" CYLINDER FILL"]
SEROUT 1, 16780, [254, 192]
SEROUT 1, 16780, [" COMM TEST"]
'SERIN 16, 16780, [WAIT(255), DEC n2]' n10s, n1s]' , n2]
'SERIN 16, 16780, [junk, DEC n2] ' last working serin from pc 4/9 330 pm
SERIN 16, 16780, [junk, DEC n10, DEC n1]
LOOKUP n10, [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], res10
LOOKUP n1, [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], res1
res10 = res10 * 10
nit = res10 + res1
SEROUT 1, 16780, [254, 1]
SEROUT 1, 16780, [254, 128]
SEROUT 1, 16780, ["SP: "]
SEROUT 1, 16780, [254, 192]
SEROUT 1, 16780, ["ERR: "]
SEROUT 1, 16780, [254, 200]
SEROUT 1, 16780, ["ACT: "]
SEROUT 1, 16780, [254, 132]
SEROUT 1, 16780, [DEC nit]

FOR z = 1 TO 100
SEROUT 2, 16780, ["P"]
SERIN 0, 16780, [junk, junk, junk, junk, junk, f, g, h, i, j, k, l]
IF h <> 48 THEN continue
n_act = i
GOTO single
continue:
h = h * 10
n_act = h + i
single:
error = nit - n_act 'n2 = set point, n_act = current sensor value
SEROUT 1, 16780, [254, 136]
SEROUT 1, 16780, [h]
SEROUT 1, 16780, [254, 140]
SEROUT 1, 16780, '
SEROUT 1, 16780, [254, 197]
SEROUT 1, 16780, [DEC error]
SEROUT 1, 16780, [254, 205]
SEROUT 1, 16780, [n_act]
PAUSE 200
NEXT
SEROUT 1, 16780, [254, 1]


GOTO begin

Unsoundcode
04-11-2007, 05:28 AM
Hi 4 yrs, I havn't messed with the MScomm control much so I am not 100% on the syntax but you might try just a small program that will recieve one byte and build on it from there.

For VB I would try

MScomm.Output=12·+ Chr(10)· 'keep the format the same but check the syntax

MScomm.Output=12·& Chr(10)· 'this could be an alternative

And for the Stamp

SERIN 16,16780,[DEC mynumber]· 'if you get VB right this will grab your value

x=mynumber

HIGH mynumber

stick an LED on pin 12 and see if it lights.

Jeff T.

4 yrs later
04-11-2007, 06:24 AM
That'll work just fine. I've sent every kind of VB data type through the MSCOMM control to the stamp and can debug on the LCD exactly as expected. The problem is that there's no way to tell what data type is used when grabbing numbers from excel. I can 'debug' by pointing the data at text boxes and labels on the form, but VB automatically makes it look like string output. Also, I can't debug from the stamp since pin 16 is in use.· I think the real problem is the lack of clear documentation on the MS data object and how it types the data from excel....
I've done scores of MSCOMM apps over the years - this is the most frustrating one by far....

Unsoundcode
04-12-2007, 06:22 AM
Hi 4 yrs, sorry I misunderstood what you were looking for. You dont show in your VB code how you are connecting to your database and·Excel is something I have not had a lot of dealings with so I went hunting for a solution that would fit VB Express (so I could check it out) and was also suitable for the older versions of VB (so it says).

I have attached what I found to be the simplest way of doing things, it may be what you already have I dont know. Anyway the data is collected as a string , just as you mentioned , using Val(cell_value) I was able to convert it to an integer and transmit it over the serial line without any further fomatting. The only thing not shown in the txt file is you have to add a COM reference to Microsoft Excel Object Library to your project.

I may still be overlooking something, I am unsure why you·are measuring the string lengths,·is the numeric data mixed with text.

Jeff T.

EDIT....... Doh!!· tens and ones



Post Edited (Unsoundcode) : 4/12/2007 12:55:51 AM GMT

4 yrs later
04-12-2007, 08:39 PM
This is very similar to what I have done with the data object in VB6 Pro. The only difference is in that I needed to provide the object so users can scroll through and select one column of the worksheet and when doing so, the values needed by the stamp would be extracted (and also displayed on screen for verification) for use with the MSCOMM.Output.
Now, I am certain that I can routinely send ascii bytes for the two digit values. I will try to put the lookup tables to use to convert ascii to DEC for the math. Sounds simple, right? Stay tuned!
Thanks!
Chris

4 yrs later
04-12-2007, 08:46 PM
Speaking of *"Doh"* - Lookdown, not lookup for ascii conversion......

Unsoundcode
04-13-2007, 04:29 AM
I will stay tuned Chris, your project has piqued my interest and opened a few possibilities for my own point of view. I am interested in how you will display a row or column to the user, looks like you are using label controls which seems a good way, I thought of maybe a list box. I might also try a VB form with a SQL data object and fill the dataset with the data from Excel and see how that works out.

I am still not sure why you are doing the ASCII conversion. Val(cell_value) is enough to take the string and convert it to an integer and SERIN 16,16780,[DEC mynumber] is enough to·use the integer without any further formatting.

Jeff T.