I have a little project going that has a BS2 sitting between a PC & a digital s
4 yrs later
Posts: 14
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
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
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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.
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, [noparse][[/noparse]254, 1]
SEROUT 1, 16780, [noparse][[/noparse]"WINSLOW LIFERAFT"]
SEROUT 1, 16780, [noparse][[/noparse]254, 192]
SEROUT 1, 16780, [noparse][[/noparse]" AUTOMATED"]
PAUSE 1000
SEROUT 1, 16780, [noparse][[/noparse]254, 1]
SEROUT 1, 16780, [noparse][[/noparse]" CYLINDER FILL"]
SEROUT 1, 16780, [noparse][[/noparse]254, 192]
SEROUT 1, 16780, [noparse][[/noparse]" COMM TEST"]
'SERIN 16, 16780, [noparse][[/noparse]WAIT(255), DEC n2]' n10s, n1s]' , n2]
'SERIN 16, 16780, [noparse][[/noparse]junk, DEC n2] ' last working serin from pc 4/9 330 pm
SERIN 16, 16780, [noparse][[/noparse]junk, DEC n10, DEC n1]
LOOKUP n10, [noparse][[/noparse]48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], res10
LOOKUP n1, [noparse][[/noparse]48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], res1
res10 = res10 * 10
nit = res10 + res1
SEROUT 1, 16780, [noparse][[/noparse]254, 1]
SEROUT 1, 16780, [noparse][[/noparse]254, 128]
SEROUT 1, 16780, [noparse][[/noparse]"SP: "]
SEROUT 1, 16780, [noparse][[/noparse]254, 192]
SEROUT 1, 16780, [noparse][[/noparse]"ERR: "]
SEROUT 1, 16780, [noparse][[/noparse]254, 200]
SEROUT 1, 16780, [noparse][[/noparse]"ACT: "]
SEROUT 1, 16780, [noparse][[/noparse]254, 132]
SEROUT 1, 16780, [noparse][[/noparse]DEC nit]
FOR z = 1 TO 100
SEROUT 2, 16780, [noparse][[/noparse]"P"]
SERIN 0, 16780, [noparse][[/noparse]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, [noparse][[/noparse]254, 136]
SEROUT 1, 16780, [noparse][[/noparse]h]
SEROUT 1, 16780, [noparse][[/noparse]254, 140]
SEROUT 1, 16780, '
SEROUT 1, 16780, [noparse][[/noparse]254, 197]
SEROUT 1, 16780, [noparse][[/noparse]DEC error]
SEROUT 1, 16780, [noparse][[/noparse]254, 205]
SEROUT 1, 16780, [noparse][[/noparse]n_act]
PAUSE 200
NEXT
SEROUT 1, 16780, [noparse][[/noparse]254, 1]
GOTO begin
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,[noparse][[/noparse]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.
I've done scores of MSCOMM apps over the years - this is the most frustrating one by far....
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
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
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,[noparse][[/noparse]DEC mynumber] is enough to·use the integer without any further formatting.
Jeff T.