Shop OBEX P1 Docs P2 Docs Learn Events
Tutorial for interfacing a Propeller to a PC with VB 2008! — Parallax Forums

Tutorial for interfacing a Propeller to a PC with VB 2008!

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2010-05-27 01:01 in Propeller 1
After I had to prowl the internet for information on how to get this "Should be simple" task done, I decided to write a tutorial about it. Now others can learn to interface the Propeller to the PC and make cool PC apps that can continue to help Propeller programmers. I've spent all afternoon on it, so I hope you like it!

Thanks,

Micro

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my new website!!

Use the Propeller icon!! Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

Post Edited (Microcontrolled) : 5/25/2010 5:17:18 PM GMT

Comments

  • ry.davidry.david Posts: 63
    edited 2010-05-25 01:59
    Looks good - Thanks!

    One suggestion - maybe attach it in PDF incase people don't have Office 2007+
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-05-25 02:00
    OK, I will tomorrow. Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my new website!!

    Use the Propeller icon!! Propeller.gif

    Follow me on Twitter! Search "Microcontrolled"
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-05-25 17:15
    PDF file has been uploaded! Now everyone should be able to view it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my new website!!

    Use the Propeller icon!! Propeller.gif

    Follow me on Twitter! Search "Microcontrolled"
  • mikedivmikediv Posts: 825
    edited 2010-05-25 17:28
    This is very decent of you to share this, I was looking for info on this subject thank you
  • jazzedjazzed Posts: 11,803
    edited 2010-05-25 17:38
    Microcontrolled said...
    I've spent all afternoon on it, so I hope you like it!
    Very nice paper with lots of good explanations. Many newcomers will appreciate your effort.

    Cheers [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    May the road rise to meet you; may the sun shine on your back.
    May you create something useful, even if it's just a hack.
  • ratronicratronic Posts: 1,451
    edited 2010-05-25 19:45
    @Microcontrolled -·Thats good now ·lets see your take on receiving in VB2008!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if ain't broke!


    D Rat

    Dave Ratcliff N6YEE

    Post Edited (ratronic) : 5/25/2010 7:50:24 PM GMT
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-05-25 23:10
    @ratronic: Yeah... I still havn't got that working myself. wink.gif
    @jazzed: Thanks! I spent so much time figuring this out myself that I figured I should let everyone else have an easy source.
    @mikediv: Thank you! I hope it helps!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my new website!!

    Use the Propeller icon!! Propeller.gif

    Follow me on Twitter! Search "Microcontrolled"
  • ratronicratronic Posts: 1,451
    edited 2010-05-25 23:23
    Microcontrolled, I haven't really figured it out completly myself either, but this a 'modified' file I found on the internet I use pieces of whenever I need something. I was kinda hoping you did!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if ain't broke!


    D Rat

    Dave Ratcliff N6YEE
  • TtailspinTtailspin Posts: 1,326
    edited 2010-05-26 00:13
    Hey Gang,

    I don't know if this will help..

    I have found that using a timer to "recieve", is very helpfull.

    Set up a timer tick event to ".readexisting", every tick it will "readexisting" Data, and update a Label or a textbox or whatever...

    I set mine up to give a reading for RCtime, and also a Light to freq. converter.. (Wanna see it?)

    Anyways, thanks MicroControlled, for the quick lesson in communicating with the Prop to PC. it was very helpfull to me,
    It confirmed what I had discovered allready.. which is a good thing.

    Also, (for the absolute newbie) make sure when you send a string to the Prop... TERMINATE THE STRING!! With a 0, or..
    Prepare to spend hours hunting down the "bug"..

    Oh and don't forget to put an "@" in front of the string pointer...That drove Me insane for a few hours hunting down that one... sigh...

    This works, (@whatEverDataPointer)... this won't work (WhatEverDataPointer)... You WILL know what I mean...


    All part of the fun I guess..
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-05-26 00:22
    @Ttailspin: Let's see your code! I would like to expand upon the tutorial to include reading as well.
    @ratroinc: Let me check it out.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my new website!!

    Use the Propeller icon!! Propeller.gif

    Follow me on Twitter! Search "Microcontrolled"
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-05-26 02:09
    Nice work microcontrolled. I am sure it will be appreciated.

    Would you like to expand your work???

    In Sphinx there is a simple ftp (file transfer protocol) that mpark has used. I started to split it out to a seperate Sphinx aware program (prop end) just like DIR. Michael has a C PC program that will do the ftp. Would you like to do the protocol in VB to extend SphinxOS ?

    Another app would be to make a VT100 terminal in VB for the prop. Not all codes need to be supported.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • TtailspinTtailspin Posts: 1,326
    edited 2010-05-26 03:12
    Mkay..
    Here is some Working Code as written by a GrandMaster Carpenter...
    Hey, What can I say,..·I can Cut and Paste with the best of them.

    For Visual Basic recieveing, I use this..
    [color=#0000ff][color=#0000ff][color=#0000ff]Private[/color][/color][/color] [color=#0000ff][color=#0000ff][color=#0000ff]Sub[/color][/color][/color][color=#000000] BtnRecieve_Click([/color][color=#0000ff][color=#0000ff][color=#0000ff]ByVal[/color][/color][/color][color=#000000] sender [/color][color=#0000ff][color=#0000ff][color=#0000ff]As[/color][/color][/color][color=#000000] System.[/color][color=#2b91af][color=#2b91af][color=#2b91af]Object[/color][/color][/color][color=#000000], [/color][color=#0000ff][color=#0000ff][color=#0000ff]ByVal[/color][/color][/color][color=#000000] e [/color][color=#0000ff][color=#0000ff][color=#0000ff]As [/color][/color][/color][color=#000000]System.[/color][color=#2b91af][color=#2b91af][color=#2b91af]EventArgs[/color][/color][/color][color=#000000]) [/color][color=#0000ff][color=#0000ff][color=#0000ff]Handles[/color][/color][/color][color=#000000] BtnRecieve.Click[/color]
     
    [color=#0000ff][color=#0000ff][color=#0000ff]If[/color][/color][/color] _port.IsOpen [color=#0000ff][color=#0000ff][color=#0000ff]Then[/color][/color][/color]
        TxtRecieved.Text = _port.ReadExisting
    [color=#0000ff][color=#0000ff][color=#0000ff]Else[/color][/color][/color]
        MsgBox([color=#a31515][color=#a31515][color=#a31515]"NO COMMUNICATION PORT IS DETECTED"[/color][/color][/color] & (Chr(13) & Chr(10)) & (Chr(10)) &[color=#a31515][color=#a31515][color=#a31515]  "PLEASE TRY AGAIN"[/color][/color][/color] & (Chr(13) & Chr(10)) & [color=#a31515][color=#a31515][color=#a31515]"SEE THE OPTIONS MENU"[/color][/color][/color], , [color=#a31515][color=#a31515][color=#a31515]"No Communication Port has been detected"[/color][/color][/color])
    [color=#0000ff][color=#0000ff][color=#0000ff]End[/color][/color][/color] [color=#0000ff][color=#0000ff][color=#0000ff]If[/color][/color][/color]
    [color=#0000ff][color=#0000ff][color=#0000ff]End[/color][/color][/color] [color=#0000ff][color=#0000ff][color=#0000ff]Sub[/color][/color][/color]
    
    

    What Visual Basic Recieves from the Propeller, is this...
    PUB RCtime | time
      ' Configure counter module.
      'COGNEW (RCtime, @RCstack)
      ctra[noparse][[/noparse]30..26] := %01000                     ' Set mode to "POS detector"
      ctra[noparse][[/noparse]5..0] := 20                           ' Set APIN to 20 (P20)
      frqa := 1                                  ' Increment phsa by 1 for each clock tick
     
                      '' Repeatedly takes and displays Pin(20) RC decay measurements.
        
        Pst.RxFlush       
      
               repeat 20                'Set how many measurments before returning            
                         
                                           ' Charge RC circuit.
                 dira[noparse][[/noparse]20] := outa[noparse][[/noparse]20] := 1               ' Set pin to output-high
                 waitcnt(clkfreq/100_000 + cnt)          ' Wait for circuit to charge
          
                                       ' Start RC decay measurement.
                 phsa~                                   ' Clear the phsa register
                 dira[noparse][[/noparse]20]~                               ' Pin to input stops charging circuit
     
             'Optionaldootherthingsduringthemeasurement.                                                     
                    
                 waitcnt(clkfreq/60 + cnt)
                          ' Measurement has been ready for a while.  
                           'Adjust ticks between phsa~ & dira[noparse][[/noparse]20]~. 
                 time := (phsa - 624) #> 0                
                   
                          'Display Result
                 Pst.Str(String(13, "time = "))
                 Pst.Dec(time)
                 waitcnt(clkfreq/2 + cnt)
                 Toggle(16)
    


    I have no idea how to post Visual Basic Code, I will try to just attach the PCommunication Project.

    And The Propeller File, is also named PCommunication..

    IF the Two Programs are ran at the same time, AND the Prop. Pro. Dev. Board IS wired As woefully described.
    It should function in all sorts of fun and entertaining ways, and indeed, the comm port, will "comport"...
    Just Play around with them, and See what You can See, They were written by a Newbie, so a Newbie should
    be able to sort it out..(LOL, I bet the Pro's Might struggle with it, at least, it will be a good laugh for them.)

    As a Disclaimer, the code and comments, are written for Me, and Me alone, REGARD THEM AT YER OWN RISK.
    Please, Feel Free to comment on My comment's, I would love to hear what any Pro would say of them.

    Again, I am a Profesional·Carpenter, My day to day hand tools, are somewhat more Primative than a lap top,
    and communication with a keyboard can be diffucult and awkward at best, at least·for Myself·that is..


    Anyways, I will try My best to Post Up the Two Programs now.. I may need instruction on this.



    Post Edited (Ttailspin) : 5/26/2010 3:28:24 AM GMT
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-05-26 04:34
    This is a great little tute.

    Next step - if you are sending data you will find vb has trouble with bytes 128 to 255, so you have to convert that string into byte values if you want the full range of ascii values. This becomes relevant if you are sending binary files.

    Reading values back can be done in lots of ways but a timer as already suggested is a good system. Check for bytes in the buffer several times a second, and then read in that number of bytes.

    @Cluso, VT100 terminal is already done in visual basic, as is xmodem, and the more basic input and output of bytes.
    @microcontrolled, if you like you can pull to bits the code I have that does all the above - smarthome.viviti.com/propeller down near the bottom just above the picture of wordstar is a link "IDE" and that contains a huge amount of vb code that can do all the things you want. The complicated part is simplifying it. Then of course, once you make it simple, it doesn't do what you want so you have to make it complicated again.

    addit Sorry about that last bit, but I've just finished reading Catch 22 and the writing style is somewhat contagious!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • Mike GMike G Posts: 2,702
    edited 2010-05-26 05:08
    Here's a fairly easy way to read bytes in VB.NET
    Imports System.IO.Ports
    Imports System.Threading
    
    Module Module1
    
        Public WithEvents serial As New SerialPort()
        'Dim handler As New SerialDataReceivedEventHandler(AddressOf SerialDataReceivedEventHandler)
    
        Sub Main()
            Dim portName As String = String.Empty
            Dim baud As Integer
            Dim cki As ConsoleKeyInfo
    
    
            Console.WriteLine("We need to open a serial port!")
            Console.WriteLine("Enter a serial port name in the form of COM1")
            portName = Console.ReadLine()
    
            Console.WriteLine("Enter a baud rate. Integers only, 57600 is a good baud.")
            baud = Integer.Parse(Console.ReadLine())
    
            serial.PortName = portName
            serial.BaudRate = baud
            serial.Open()
    
            If serial.IsOpen() Then
                Console.WriteLine("Port {0} open at {1}", serial.PortName, serial.BaudRate)
                Console.WriteLine("Waiting for serial port DataReceived event.")
    
            End If
    
            Do
                cki = Console.ReadKey(True)
                Thread.Sleep(1)
            Loop While cki.Key <> ConsoleKey.Escape
    
            serial.Close()
    
    
        End Sub
    
    
        Public Sub SerialDataReceivedEventHandler(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles serial.DataReceived
    
            Dim readBuffer(serial.BytesToRead) As Byte
    
            Dim numBytes As Integer = serial.Read(readBuffer, 0, readBuffer.Length)
    
    
            Console.WriteLine(BitConverter.ToString(readBuffer))
    
            'For i As Integer = 0 To numBytes - 1
            '    Console.Write(readBuffer(i) & " ")
            'Next i
    
        End Sub
    
    End Module
    
    



    Propeller Code
    CON
        _clkmode = xtal1 + pll16x
        _xinfreq = 5_000_000
    
    DAT
      message     byte      "Hello World",0
    
    VAR
      byte  command
      byte  temp
        
     
    OBJ
      serial : "Parallax Serial Terminal"
    
      
    PUB Main
      serial.StartRxTx(31, 30, 0, 57600)
      
    
      repeat
    
        { Write Hello World }
        serial.Str(@message)
        serial.NewLine
        waitcnt(1_000_000 + cnt)
    
    



    Timers are good if you need/want to poll the serial port. My opinion, use the DataReceived event.

    Edit added project files

    Post Edited (Mike G) : 5/26/2010 1:21:38 PM GMT
  • Jim FouchJim Fouch Posts: 395
    edited 2010-05-26 11:05
    Here is an example of both sides for send and receive I did in SPIN and VB.Net 2008.

    It was for a project I did a few months ago to control 4 120Vac circuits and cause a power interruption as specific points for very small amounts of time.

    It shows how to use a separate thread to do the receiving·from the COMM port.





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jim Fouch

    FOUCH SOFTWARE
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-05-27 00:15
    I've been reviewing the options above all day. I still can't get one working with my current setup. I wonder what is wrong....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my new website!!

    Use the Propeller icon!! Propeller.gif

    Follow me on Twitter! Search "Microcontrolled"
  • Mike GMike G Posts: 2,702
    edited 2010-05-27 01:01
    I double checked my SerialHelloWorld.zip file. It's all there. Just download and unzip. The prop code is in the spin file and the .NET stuff, well just double click the SerialHelloWorld.sln file. Load SerialHelloWorld.spin in the prop then run the .NET project. That's about it. It's a console app... so you need to enter a com port and baud when prompted. The com port name will be something like "COMx" where x is is the port number. Baud is an integer. Press the "Esc" key to exit.

    If you're having problem integrating in your own project, post your code for help. You have to "New" the serial port for the DataReceived event to wire up.

    Post Edited (Mike G) : 5/27/2010 1:08:22 AM GMT
Sign In or Register to comment.