Shop OBEX P1 Docs P2 Docs Learn Events
BS2 and Visual Basic....urgent help needed! — Parallax Forums

BS2 and Visual Basic....urgent help needed!

ArchiverArchiver Posts: 46,084
edited 2003-06-20 08:42 in General Discussion
Folks,

i'm trying to finish up a project and i'm having a serious problem:
i'm trying to send a data from a VB application to a BS2, but it
looks like the basic stamp is not receiving the right input from the
VB application for some reason.below are my BS2 code and my VB code.
I would really appreciate any help
Thanks

*******************BS2 code*************************************
'{$STAMP BS2p}

datain var byte 'contains a 0 or a 1
pin con 16 'stamps dedicated serial input pin
baud con $4054 '9600 baud

again:

serin pin,baud, [noparse][[/noparse]datain]
if datain = "1" then on
if datain = "0" then off
if datain > "1" then bob
goto again

bob:

SEROUT 0, 241 + $4000, [noparse][[/noparse]170]

goto bob


on:
high 0 'make pin 0 high
goto on


off:
low 0 'make pin 0 low
goto off
******************************************************************
comments: it is going to the function "bob" all the time, no matter
what i send from the VB application.


****************************VB code********************************

Option Explicit

Private Sub DataGrid1_ButtonClick(ByVal ColIndex As Integer)
If ColIndex = 1 Or ColIndex = 2 Or ColIndex = 3 Or ColIndex = 4 Then
List1.Top = DataGrid1.Top + DataGrid1.RowTop(DataGrid1.Row) +
DataGrid1.RowHeight
List1.Left = DataGrid1.Left + DataGrid1.Columns(ColIndex).Left
' Width and Height properties can be set a design time
' The width of the list does not have to be the same as the
width of the grid column
List1.Width = DataGrid1.Columns(1).Width
List1.Height = 600
List1.Visible = Not List1.Visible
End If

End Sub




Private Sub Exit_Click()
End
End Sub




Private Sub List1_Click()
Dim x As Variant

Dim SerData As Integer

DataGrid1.Text = List1.Text

If DataGrid1.Text = "on" Then

If MSComm2.PortOpen = False Then
'check to see if the commport isn't already open

MSComm2.PortOpen = True
'open the Commport


End If

SerData = 1
MSComm2.Output = Str(SerData) & "!"

MsgBox "Device 1 is being powered on"


ElseIf DataGrid1.Text = "off" Then
If MSComm2.PortOpen = False Then
'check to see if the commport isn't already open

MSComm2.PortOpen = True
'open the Commport
End If

SerData = 0
MSComm2.Output = Str(SerData) & "!"
MsgBox "Device 1 is being powered off"

End If
List1.Visible = False
End Sub




Private Sub DataList1_LostFocus()
List1.Visible = False
End Sub



Private Sub DataGrid1_Scroll(Cancel As Integer)
List1.Visible = False
End Sub



Private Sub Form_Load()
Dim temp As String
Dim ind As Integer

temp = DataGrid1.Columns(1).Text
If temp = "on" Then
ind = 0
ElseIf temp = "off" Then
ind = 1
End If

List1.Visible = False
List1.AddItem ("on")
List1.AddItem ("off")
DataGrid1.Columns(1).Text = List1.List(ind)
DataGrid1.Columns(1).Button = True
DataGrid1.Columns(2).Button = True
DataGrid1.Columns(3).Button = True
DataGrid1.Columns(4).Button = True

End Sub


Private Sub Update_Click()

Adodc1.Recordset.Update

End Sub

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-04-09 06:14
    A couple of things:

    The VB Str() function pads the number with a space, so you might want to use
    this construct instead:

    Trim(Str(myNumber))

    Right now your PBASIC program is receiving the space pad created by Str().

    On your PBASIC side, you might consider doing this:

    SERIN sPin, sBaud, [noparse][[/noparse]DEC myNumber]

    This would actually eliminate the need for Trim(), and you'll have to change
    your code a bit to look for values instead of characters

    One final note: The new compiler is available in Beta and has control
    structures similar to those found if VB. If you switch, you'll have to
    rename your "On" label since that is a keyword in PBASIC 2.5. If you change,
    and use my suggestions, your program would look like this:

    Main:
    DO
    SERIN pin, baud, [noparse][[/noparse]DEC dataIn]
    IF (dataIn = 1) THEN
    HIGH 0
    ELSE
    LOW 0
    ENDIF
    LOOP

    Actually, this version will receive characters and do what you want. Your
    version, should a valid command come in, will hang on that command forever
    because your code goes into an infinite local loop -- your program might turn
    the pin on or off, but never go anywhere after.


    -- Jon Williams
    -- Parallax

    In a message dated 4/9/2003 12:03:13 AM Central Standard Time,
    jagal1979@y... writes:

    > Folks,
    >
    > i'm trying to finish up a project and i'm having a serious problem:
    > i'm trying to send a data from a VB application to a BS2, but it
    > looks like the basic stamp is not receiving the right input from the
    > VB application for some reason.below are my BS2 code and my VB code.
    > I would really appreciate any help
    > Thanks



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-09 18:06
    i developed a visual basic application, through which i will be able to control
    devices in a room(ON/OFF)

    and the problem i'm having is sending a string from the application and receive
    with the basic stamp: what am i exactly sending and what am i exactly receiving?

    anyway, some of the guys provided a solution that i'm gonna look at later on
    today.hopefully it will do it.

    regards,

    mohammad



    Do you Yahoo!?
    Yahoo! Tax Center - File online, calculators, forms, and more

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-20 08:42
    What are you using to communicate with the bs2? I don't even know VB... I
    usually use a mini-DAQ board that plugs into the back of my computer
    (printer port).
Sign In or Register to comment.