View Full Version : problem working with director + basic stamp 2
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.
stamptrol
08-30-2011, 02:13 PM
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,
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 G
08-30-2011, 03:24 PM
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.
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 :
global theXtra
on startMovie
put "movie started available ports "
set theXtra to new ( xtra "SerialXtra" )
put theXtra.FindPorts()
if objectP(theXtra) then
theXtra.OpenPort("COM4")
put theXtra.IsPortOpen()
end if
end if
end startMovie
on stopMovie
theXtra.closePort()
put theXtra.IsPortOpen()
set theXtra to 0
end
working Director script 2:
global theXtra
on exitFrame me
put "frame exited"
if theXtra.IsPortOpen() then
reply = theXtra.ReadString()
put reply
end if
end