Shop OBEX P1 Docs P2 Docs Learn Events
problem working with director + basic stamp 2 — Parallax Forums

problem working with director + basic stamp 2

SangSang Posts: 3
edited 2011-08-31 01:36 in General Discussion
I have a problem receiving a message from basic stamp 2.
I have very simple code :

BS2 code :

Main:
DEBUG "BLINK "
GOTO Main



Director script (used serialExtra @ http://www.physicalbits.com )

on startMovie
set theXtra to new ( xtra "SerialXtra" )
if objectP(theXtra) then
theXtra.OpenPort("COM1")
if theXtra.IsPortOpen() then
reply = theXtra.ReadString()
put reply
end if
end if
end startMovie

It seems that the port opens correctly, but the message is receives is empty.
Can be a wrong port number or using USB be a problem?
Sorry.. I'm very new to serial communication.

Thanks in advance.

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2011-08-30 07:13
    Hi and welcome to the forums.

    The DEBUG on the stamp will send/receive data using the programming port at 9600, 8, n, 1 I believe. Therefore the computer running Director also has to have the same settings.

    The use of USB shouldn't cause a problem as long as Director can select the proper COM port.

    If you could show us the actual connections you're using, we can make a better attempt at a successful diagnosis. From experience, it is common to have to interchange the connections on pin 2 and 3 of the programmiing port.

    Cheers,
  • SangSang Posts: 3
    edited 2011-08-30 08:08
    Thank you!

    Seems that the default port setting is 9600 8 n 1 already.

    I'm not sure how I may check the actual connections.. Is there a way to check this?
    How may I interchange the pins? ( I'm not clear on what you mean by interchange pins, actually )
  • Mike GMike G Posts: 2,702
    edited 2011-08-30 08:24
    Check the director syntax OpenPort. you can probably add baud, parity...
    theXtra.OpenPort("COM1") 
    

    Are you sure that the STAMP is on COM1?

    Take a look at the Stamp SEROUT command in the help file. SEROUT might be better than the DEBUG command, more options.
  • SangSang Posts: 3
    edited 2011-08-31 01:36
    Thank you everyone!
    Geoff @ serialXtra gave me the solution.
    I had to create 2 separate script. One for movie start/end, and the other for frame exit.
    Frame script allowed me to constantly monitor for incoming messages, becuase once a movie started, it played again and again, letting frame exit be called multiple times. ( am I right? )
    Of course I had to check the port (COM4, for example) manually. Not sure if there's a more elegant way.

    working Director script1 :
    [FONT= ]global [/FONT][FONT= ]theXtra[/FONT][FONT= ] [/FONT]
    [FONT= ][/FONT]
    [FONT= ]on [/FONT][FONT= ]startMovie[/FONT][FONT= ] [/FONT]

    [FONT= ]put "movie started available ports "[/FONT]
    [FONT= ][/FONT]
    [FONT= ]set [/FONT][FONT= ]theXtra[/FONT][FONT= ] to new ( [/FONT][FONT= ]xtra[/FONT][FONT= ] "[/FONT][FONT= ]SerialXtra[/FONT][FONT= ]" )[/FONT]
    [FONT= ]put [/FONT][FONT= ]theXtra.FindPorts[/FONT][FONT= ]()[/FONT]
    [FONT= ] [/FONT]
    [FONT= ]if [/FONT][FONT= ]objectP[/FONT][FONT= ]([/FONT][FONT= ]theXtra[/FONT][FONT= ]) then [/FONT]
    [FONT= ] [/FONT]
    [FONT= ] [/FONT][FONT= ]theXtra.OpenPort[/FONT][FONT= ]("COM4") [/FONT]
    [FONT= ] put [/FONT][FONT= ]theXtra.IsPortOpen[/FONT][FONT= ]() [/FONT]
    [FONT= ] [/FONT][FONT= ] [/FONT]
    [FONT= ] end if [/FONT]
    [FONT= ]end if[/FONT]
    [FONT= ]end [/FONT][FONT= ]startMovie[/FONT][FONT= ] [/FONT]
    [FONT= ][/FONT]
    [FONT= ][/FONT]
    [FONT= ][/FONT]
    [FONT= ]on [/FONT][FONT= ]stopMovie[/FONT][FONT= ] [/FONT]
    [FONT= ] [/FONT][FONT= ]theXtra.closePort[/FONT][FONT= ]() [/FONT]
    [FONT= ] put [/FONT][FONT= ]theXtra.IsPortOpen[/FONT][FONT= ]() [/FONT]
    [FONT= ] set [/FONT][FONT= ]theXtra[/FONT][FONT= ] to 0 [/FONT]
    [FONT= ] [/FONT]
    [FONT= ]end[/FONT]
    [FONT= ][/FONT]
    [FONT= ][/FONT]
    [FONT= ]working Director script 2: [/FONT]
    [FONT= ][/FONT]
    [FONT= ]global theXtra [/FONT]
    [FONT= ]on exitFrame me
    put "frame exited"

    if theXtra.IsPortOpen() then

    reply = theXtra.ReadString()
    put reply
    end if
    end[/FONT]
Sign In or Register to comment.