Shop OBEX P1 Docs P2 Docs Learn Events
Microsoft and the Propeller — Parallax Forums

Microsoft and the Propeller

I know there is a way for the Stamp to communicate using Visual Basic and Visual C but has anyone accomplished this with the Propeller yet? I have some project ideas that would really benefit from the use of VB and VC but have not found any info on this subject.

Comments

  • It's just serial data so the process is the same. In fact, it's easier with the Propeller because every serial driver buffers data in and out (the Stamp does not). I believe Chris Savage did a VB project with the Propeller a couple years ago -- you might search for that.
  • Do you have an example of BS2 code which outputs/receives data appropriately?

    I think it would be pretty easy to translate PBASIC serial interface code to Spin.

    As JonnyMac points out, this sort of thing should be easier with the Propeller than it was with a BS2.
  • I'm pretty sure I do. I just need to figure out where.
  • This series of snippets may help... I have used it to query information on the web from the VB side and pass along certain results to a propeller for processing. The fastest I could get it to run reliably was 38.4kbps so that is what the snippets use. You'll need some meat around the bones of the propeller snippet to see any results. It is using the programming port pins for transmission.

    ON THE PROPELLER
    CON
      _CLKMODE = XTAL1 + PLL16X   'Setting up the clock mode
      _XINFREQ = 5_000_000        'Setting up the frequency
    
      MCU_PROGRX    = 30                 
      MCU_PROGTX    = 31                 
    VAR
      byte buffer[30]
    OBJ
      SIO   : "FullDuplexSerial"
    
    PRI ReceiveTest
      SIO.Start(MCU_PROGTX,MCU_PROGRX,%0000,38_400)
      repeat ' forever
        ' fetch and display current vote counts
        GetDelimitedString(@buffer)
        { 
        display string from buffer here: I was using a 4D Systems uLCD32 display
        the code for which has been omitted here for clarity, since you probably 
        dont have one of them anyway.
        }                               
       
    PRI GetDelimitedString(psz) | n
      n := 29
      repeat while (n--)                                                     
        if (byte[psz] := SIO.Rx) == CR
           quit
        psz++
      byte[psz]~ ' zero terminate it
    

    In Visual Basic (6.0 in my case)

    Presuming a form is present containing an MSCOMM control named MSComm1; a ComboBox named cb1; and two CommandButtons named cmdRun and cmdQuit.
    Option Explicit
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Dim cease As Boolean
    
    Private Sub Form_Load()
        SerialEnumerator.EnumSerialPorts cb1
        cease = False
    End Sub
    Private Sub Form_Terminate()
        If MSComm1.PortOpen = True Then
            MSComm1.PortOpen = False ' this incidentally reboots the MCU
        End If
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        cease = True ' cause it to quit, hopefully
    End Sub
    Private Sub cb1_Click()
        cmdRun.Enabled = True
    End Sub
    Private Sub cmdRun_Click()
        If cmdRun.Caption = "Run" Then
            cmdRun.Caption = "Running"
            cease = False
            cmdQuit.Enabled = True
            MSComm1.CommPort = CInt(Right(cb1.List(cb1.ListIndex), Len(cb1.List(cb1.ListIndex)) - 3)) ' Defined COM port available on PC (COM7 for my EEE laptop)
            MSComm1.InputLen = 0
            MSComm1.Settings = "38400, N, 8, 1"
            MSComm1.PortOpen = True '
            Run
        End If
        cmdRun.Caption = "Run"
        cease = True
        cmdQuit.Enabled = False
        If MSComm1.PortOpen = True Then
            MSComm1.PortOpen = False
        End If
    End Sub
    Private Sub cmdQuit_Click()
        cease = True
    End Sub
    Private Sub Run()
        On Error Resume Next    
        While Not cease
            DoEvents
            MSComm1.Output = "Hola Propeller" + vbCr ' forward to MCU for processing
            Sleep 250 'mS
        Wend
    End Sub
    

    And in addition a module named SerialEnumerator containing the following code:
    Option Explicit
    
    '--- for CreateFile
    Private Const GENERIC_READ            As Long = &H80000000
    Private Const GENERIC_WRITE           As Long = &H40000000
    Private Const OPEN_EXISTING           As Long = 3
    Private Const INVALID_HANDLE_VALUE    As Long = -1
    '--- error codes
    Private Const ERROR_ACCESS_DENIED     As Long = 5&
    Private Const ERROR_GEN_FAILURE       As Long = 31&
    Private Const ERROR_SHARING_VIOLATION As Long = 32&
    Private Const ERROR_SEM_TIMEOUT       As Long = 121&
    
    Private Declare Function QueryDosDevice Lib "kernel32" Alias "QueryDosDeviceA" (ByVal lpDeviceName As Long, ByVal lpTargetPath As String, ByVal ucchMax As Long) As Long
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    
    Private Function PrintError(sFunc As String)
        Debug.Print sFunc; ": "; Error
    End Function
    Public Function IsNT() As Boolean
        IsNT = True
    End Function
    Public Function EnumSerialPorts(ByRef cb As ComboBox) As Variant
        Const FUNC_NAME     As String = "EnumSerialPorts"
        Dim sBuffer         As String
        Dim lIdx            As Long
        Dim hFile           As Long
        Dim vRet            As Variant
        Dim lCount          As Long
    
        On Error GoTo EH
        ReDim vRet(0 To 255) As Variant
        If IsNT Then
            sBuffer = String$(100000, 1)
            Call QueryDosDevice(0, sBuffer, Len(sBuffer))
            sBuffer = Chr$(0) & sBuffer
            For lIdx = 1 To 255
                If InStr(1, sBuffer, Chr$(0) & "COM" & lIdx & Chr$(0), vbTextCompare) > 0 Then
                    vRet(lCount) = "COM" & lIdx
                    cb.AddItem ("COM" & lIdx)
                    lCount = lCount + 1
                End If
            Next
        Else
            For lIdx = 1 To 255
                hFile = CreateFile("COM" & lIdx, GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
                If hFile = INVALID_HANDLE_VALUE Then
                    Select Case Err.LastDllError
                    Case ERROR_ACCESS_DENIED, ERROR_GEN_FAILURE, ERROR_SHARING_VIOLATION, ERROR_SEM_TIMEOUT
                        hFile = 0
                    End Select
                Else
                    Call CloseHandle(hFile)
                    hFile = 0
                End If
                If hFile = 0 Then
                    vRet(lCount) = "COM" & lIdx
                    cb.AddItem ("COM" & lIdx)
                    lCount = lCount + 1
                End If
            Next
        End If
        If lCount = 0 Then
            EnumSerialPorts = "" ' Split(vbNullString)
        Else
            ReDim Preserve vRet(0 To lCount - 1) As Variant
            EnumSerialPorts = vRet
        End If
        Exit Function
    EH:
        PrintError FUNC_NAME
        Resume Next
    End Function
    

  • BeanBean Posts: 8,129
    I have had good luck using the FTDI DLL FTD2XX.DLL with VBA (Excel, Access, etc) I'm pretty sure it will work with VB, C++, etc too.

    Details here http://www.ftdichip.com/Support/SoftwareExamples/CodeExamples/VB.htm

    I can post some code is anyone is interested.

    Bean
  • I have been using Visual Studio C# and C++ to communicate and control a propeller using the FTDI serial interface. Works well with Win 7, 8, and 10. I have also used the FTDI DLL to work with the Prop. The FTDI DLL has more control functionality but I'm not sure it provides much of an advantage over the Windows serial interface.

    I use the propeller tool to create the HUB program and download to the prop. On the prop side I use the SPIN FullDuplexSerial. I use a binary protocol to send and receive data.

    Right now I'm looking into a prop loader I can integrate into my C# application.

    BTW. the Propellent DLL works well with VS C# and C++
  • I have code to control a Windows serial port from VB6 without using MSCOMM which works very reliably including with the FTDI interface to Propellers. This is actually more reliable than MSCOMM although it requires buffering your own transmit data and polling both input and output with a timer to keep the data flowing. I've been using it since windows NT 4.0 and it works just as well on every 32-bit version through 10.
Sign In or Register to comment.