Shop OBEX P1 Docs P2 Docs Learn Events
Realbasic to PSC help please — Parallax Forums

Realbasic to PSC help please

CJCJ Posts: 470
edited 2006-01-18 00:09 in General Discussion
Hello, and thank you for checking this post.

I am trying to get my programs to talk to the PSC, but am having trouble getting the integers in my program
into a coherent dataset that the PSC can understand.

my integers are defined as

pulse as unsigned 16bit
ramp as unsigned 8bit
channel as unsigned 8bit

aparently the serial port will only accept strings,

so, how to convert bytes to characters and how to send the pulse bytes in the correct order?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?

I've killed a fly with my bare mind.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-17 15:12
    You can convert bytes to characters with Chr(x).· For your larger variables, you should be able to do something like this:

    · portStr = Chr(servoPos Mod 256) & Chr(servoPos \ 256)

    This is low-byte, then high-byte.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • CJCJ Posts: 470
    edited 2006-01-17 17:32
    That is exactly what I needed, works perfectly now, thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-17 17:59
    You're welcome.· As it turns out, I'm working on a little VB program that lets one parse the data out of a BS1 DEBUG stream -- so I've been dealing with serial stuff as strings for a couple days.· Here's what my program looks like at the moment:

    attachment.php?attachmentid=40122

    Unfortunately, it's a one-way (BS1-to-PC) deal; unlike the BS2, the BS1 cannot take serial data from its programming port.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    386 x 485 - 130K
  • CJCJ Posts: 470
    edited 2006-01-17 18:28
    Nice, looks good

    no offence but, have you thought of using a graphical representation for the pin values as well? kinda like the memory map in the editor or even just
    binary representation

    trying to extract bit values makes my head hurt

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-17 22:03
    None taken.· Notice the View menu... you can select Decimal, Hexadecimal, or Binary format for the numeric display.· Here's what binary view looks like:

    attachment.php?attachmentid=40126

    And in case you're interested, here's the code that converts a value to a binary string:

    Private Function BinStr(value As Long, width As Byte) As String

    · Dim idx As Byte
    · Dim testBit As Long
    · Dim tmpBin As String
    ·
    · testBit = 2 ^ width
    · value = value Mod testBit
    · tmpBin = "%"
    · For idx = 1 To width
    ··· testBit = testBit·\ 2
    ··· If (value >= testBit) Then
    ····· tmpBin = tmpBin & "1"
    ····· value = value - testBit
    ··· Else
    ····· tmpBin = tmpBin & "0"
    ··· End If
    · Next
    · BinStr = tmpBin


    End Function

    Please note that I don't claim to be a great VB programmer -- I just make simple programs that work.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 1/17/2006 10:11:29 PM GMT
    386 x 485 - 190K
  • SN96SN96 Posts: 318
    edited 2006-01-17 22:59
    Jon,

    You are truly a master at this stuff.

    In addtition to your fantastic knowledge, all your articles are very well written and easy to understand as well.

    When I grow up, I want to be just like you.· turn.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike

    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-18 00:09
    Be careful what you wish for, Mike! tongue.gif

    Here's the end target of that exercise -- I wanted to use the BS1-USB as a front-end for a PC program.· In my case I made it very easy by attaching a DS1620 to the BS1-USB (I'll upload a photo when the camera battery is charged).· It turns out the VB integers "understand" BASIC Stamp negative numbers so there is nothing tricky at all about the VB code: just capture, covert to degrees C (by dividing by 2), then convert to F.· After I got the DEBUG stream capture licked the rest was very easy.

    attachment.php?attachmentid=40129

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 1/18/2006 1:07:58 AM GMT
    407 x 244 - 71K
    640 x 480 - 101K
Sign In or Register to comment.