problem working with director + basic stamp 2
Sang
Posts: 3
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.
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
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,
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 )
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.
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= ][/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]