Shop OBEX P1 Docs P2 Docs Learn Events
Help With Basic Stamp <--> Visual Basic .NET 2005 Express — Parallax Forums

Help With Basic Stamp <--> Visual Basic .NET 2005 Express

DiablodeMorteDiablodeMorte Posts: 238
edited 2006-01-07 05:15 in General Discussion
Alright.. I'm having some problems getting my BS2 to get info from my VB app. Now.. I got this exact vb code to work but I have lost the BASIC code so I hoped this would work.. FOr some reason it does not.. Any ideas?

What happens:
When I send data the power light flashes which I assume means it's reset. This is not soppose to happen. Please help![noparse]:([/noparse]

Basic Stamp Code:
' {$STAMP BS2}
' {$PBASIC 2.5}
command VAR Byte

Main:
command = 0
' Use the programming port to receive
' data at 2400 baud
' Wait for the synch byte (255) and then
' get the PinNumber and PinState
SERIN 16,16780,[noparse][[/noparse]WAIT(255),command]
PAUSE 10000
DEBUG "GOD"
IF command = 2 THEN Laser
PAUSE 500
GOTO Main

Laser:
HIGH 0
PAUSE 2000
LOW 0
GOTO Main




VB CODE:
Public Sub rs232Open()
        moRS232 = New Rs232
        Try
            '// Setup parameters
            With moRS232
                .Port = 1
                .BaudRate = 2400
                .DataBit = 8
                .StopBit = Rs232.DataStopBit.StopBit_1
                .Parity = Rs232.DataParity.Parity_None
                .Timeout = 1500
            End With
            '// Initializes port
            moRS232.Open()
            '// Set state of RTS / DTS
            moRS232.Dtr = 1
            moRS232.Rts = 1
            '//If chkEvents.Checked Then moRS232.EnableEvents()
            '//chkEvents.Enabled = True
        Catch Ex As Exception
            'e.skypeChatMessage.Chat.SendMessageA("Connection Error")
            Call log("||Connection Error")
            'MessageBox.Show(Ex.Message, "Connection Error", MessageBoxButtons.OK)
        Finally
            'btnCloseCom.Enabled = moRS232.IsOpen
            'btnOpenCom.Enabled = Not moRS232.IsOpen
            If (moRS232.IsOpen) Then
                Call log("||Comm Port Opened!")
            End If
            'btnTx.Enabled = moRS232.IsOpen
            'btnRx.Enabled = moRS232.IsOpen
            'btnCheck.Enabled = moRS232.IsOpen
        End Try
    End Sub
    Public Sub rs232Close()
        moRS232.Close()
        If (Not moRS232.IsOpen) Then
            Call log("||Comm Port Closed!")
        End If
    End Sub
    Public Sub rs232Write(ByVal data As Integer)
        If (Not moRS232.IsOpen) Then
            Call log("||Comm Port Not Open")
        End If
        'Call open_comm(e)
        Call log("||Comm Data Sent")
        moRS232.PurgeBuffer(Rs232.PurgeBuffers.TxClear Or Rs232.PurgeBuffers.RXClear)
        moRS232.Write(Chr(255) & Chr(2))
    End Sub

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2006-01-06 12:45
    For testing purposes, use a serial cable with just pins 2, 3, 5 in service. You may have to jumper RTS,DTS at the computer end so your Basic program won't get confused. Sounds like what's happening is that RTS/DTS are changing state and making the Stamp reset.

    Tom
  • DiablodeMorteDiablodeMorte Posts: 238
    edited 2006-01-06 13:15
    Aight. I don't know whhy that would happen but with my new comp anything could happen. Could somebody point me in the right direction for serial cable construction?
  • stamptrolstamptrol Posts: 1,731
    edited 2006-01-06 13:55
    Just go on line to B & B Electronics. They have many application notes available for downloading.

    Cheers,

    Tom
  • DiablodeMorteDiablodeMorte Posts: 238
    edited 2006-01-06 19:40
    Ok. I found db9_pin_name.png

    Now what? I don't see DTS
  • stamptrolstamptrol Posts: 1,731
    edited 2006-01-06 19:55
    On the computer end, jumper 7 and 8 together. Also jumper 4 and 6.

    Then, Run 2, 3, 5 to the Stamp programming port.

    Tom
  • Charlie JohnsonCharlie Johnson Posts: 147
    edited 2006-01-06 19:55
    If you are using the same COM port for the·STAMP and your VB app, it is not going to work. As soon as the STAMP program runs, it ties up the COM port for VB Express 2005 because of the DEBUG command. Try commenting out the DEBUG "GOD" line in your STAMP program and running it again. It also looks like you are running a beta version of VB Express 2005. The non-beta version is available for free, and you should upgrade to it. Using the non-beta version and making the appropriate changes to the VB code where needed because of method/property/object name differences, it ran fine for me.

    Charlie

    Post Edited (dy8coke) : 1/6/2006 7:59:25 PM GMT
  • DiablodeMorteDiablodeMorte Posts: 238
    edited 2006-01-06 21:05
    I think my VB app is non-beta. How can one tell/how did you tell?

    Ok. I've found another problem.. Can Anyboy Help?
    Current Code: (DOES WORK)
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    command VAR Byte
    One:
    HIGH 1
    PAUSE 2000
    LOW 1
    GOTO Main
    Two:
    HIGH 2
    PAUSE 2000
    LOW 2
    GOTO Main
    Zero:
    HIGH 0
    PAUSE 2000
    LOW 0
    GOTO Main
    Main:
    command = 0
    ' Use the programming port to receive
    ' data at 2400 baud
    ' Wait for the synch byte (255) and then
    ' get the PinNumber and PinState
    SERIN 16,16780,[noparse][[/noparse]WAIT(255),command]
    PAUSE 10000
    BRANCH command, [noparse][[/noparse]Zero, One, Two]
    PAUSE 500
    GOTO Main
    
    


    SHOULD WORK BUT DOESN'T CODE:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    command VAR Byte
    
    Main:
    command = 0
    ' Use the programming port to receive
    ' data at 2400 baud
    ' Wait for the synch byte (255) and then
    ' get the PinNumber and PinState
    SERIN 16,16780,[noparse][[/noparse]WAIT(255),command]
    PAUSE 10000
    BRANCH command, [noparse][[/noparse]Zero, One, Two]
    PAUSE 500
    GOTO Main
    One:
    HIGH 1
    PAUSE 2000
    LOW 1
    GOTO Main
    Two:
    HIGH 2
    PAUSE 2000
    LOW 2
    GOTO Main
    Zero:
    HIGH 0
    PAUSE 2000
    LOW 0
    GOTO Main
    
    



    Why does it do that? Also, the branch statmentdoesn't work. It always blinks the One: led. Any help?

    Post Edited (DiablodeMorte) : 1/6/2006 9:20:05 PM GMT
  • Charlie JohnsonCharlie Johnson Posts: 147
    edited 2006-01-06 22:26
    It works for me, the problem may be on the VB side.· You can store the 'command' variable in the EEPROM and check it after the VB program releases the COM port.· The new VB Express requires the .NET Framework 2.0 runtime libraries.· when I created a form with the serialPort control I needed to use the following syntax:

    [color=#008000]'// Setup parameters
    [/color][color=#0000ff]With[/color] moRS232
      .PortName = [/color][color=#800000]"COM1"[/color]
      .BaudRate = 2400
      .DataBits = 8
      .StopBits = IO.Ports.StopBits.One
      .Parity = IO.Ports.Parity.None
      .WriteTimeout = 1500
    [color=#0000ff]End[/color] [color=#0000ff]With[/color]
    
    

    ·as an example.· Also I needed to create a buffer for the output data.

    [color=#0000ff]Dim[/color][color=#000000] buffer [/color][color=#0000ff]As[/color] [color=#0000ff]Byte[/color][color=#000000]() [/color][color=#008000]'This is our serial port output buffer[/color] 
    [color=#0000ff]Dim[/color] offset [color=#0000ff]As[/color] [color=#0000ff]Integer[/color] = 0 [color=#008000]'Index into the output buffer[/color]
    [color=#0000ff]Dim[/color] count [color=#0000ff]As[/color] [color=#0000ff]Integer[/color] = 2 [color=#008000]'Number of bytes we are going to send[/color]
    
    


    then in the rs232Write sub I used..
    ······
    [color=#008000]'Send the data
    [/color]moRS232.Write(buffer, offset, count)
    
    


    Charlie
  • DiablodeMorteDiablodeMorte Posts: 238
    edited 2006-01-07 05:15
    Actaully. FOr some reason it started working.. I really don't know why. .SO a mod can delete this
Sign In or Register to comment.