I am posting this in a new thread as it isn't closely tied to the original thread I posted to get specs for the generic serial plugin.
For several years, I have used a basic 8ch parallel driven system. This year I would like to move to a semi-intelligent controller. I have selected the Basic Stamp 2 (Parallax) to form the intelligent part. It recieves commands and I am able to send data to it from vixen (running on my mac [trust me, it works]).
The problem comes when I actually try to use code to drive the relays. I get no voltage on the output pins and no indication the program is functioning. However, am quite sure that the data is being sent (verified by mapping a serial port to hyperterminal). As well as verifying that the data was being sent in the format I specified. The only thing that I can identify as being a line of code that I did not write is the serin statement which an engineer at parallax wrote to grab the incoming data and distribute it into the chan array. That being said, I am 99% sure his code is faulty.
Here is the program:
' {$STAMP BS2}
' {$PBASIC 2.5}
'Program: LightingFirmware
'Version: 1.0.2
'Purpose: Interface with Vixen lighting control
' software and bridge to SSR grid.
'--------------------------------------------resources------------------------------------
'baud CON 16468
baud CON 84
link CON 16
chan VAR BYTE(8)
chanid VAR BYTE
'--------------------------------------------main loop------------------------------------
main:
DO
FOR chanid=1 TO 8
SERIN link, baud, 50,timeout, [WAIT("~!"), DEC` chan(chanid)]
NEXT
FOR chanid=1 TO 8
IF chan(chanid)>0 THEN HIGH chan(chanid)
NEXT
LOOP
'-------------------------------------------serial timout---------------------------------
timeout: 'in the event of a loss of serial comm, turn off all outputs
FOR chanid = 1 TO 8
LOW chanid
NEXT
GOTO main
The program ignores anything above zero and sets the channel to a logic high.
It doesn't look like the chan array is being initialized anywhere. So, when you call HIGH chan(chanid) there is nothing in there to specify which pins are to be set high. All those values in the array will be 0 and therefore, they will not be set. I think the code is right, just the array is not initialized.
In other words, the code does not know which pins to set high since the array in set to all zeros when it is defined.
-- John
I've changed some variable names to make the code make more sense. The array is initialized with all zeros in the level variables. From there, the serin statement is supposed to wait for the "~!" header and then grab the next 8 bytes of data. Below is the revised code.
' {$STAMP BS2}
' {$PBASIC 2.5}
'Program: LightingFirmware
'Version: 1.1.0
'Purpose: Interface with Vixen lighting control
' software and bridge to SSR grid.
'--------------------------------------------resources------------------------------------
'baud CON 16468
baud CON 84
link CON 16
level VAR BYTE(8)
chanid VAR BYTE
'--------------------------------------------main loop------------------------------------
main:
DO
SERIN link, baud, 50,timeout, [WAIT("~!"), STR` level(chanid)\8]
FOR chanid=1 TO 8
IF level(chanid)>0 THEN HIGH level(chanid)
NEXT
LOOP
'-------------------------------------------serial timout---------------------------------
timeout: 'in the event of a loss of serial comm, turn off all outputs
FOR chanid = 1 TO 8
LOW chanid
NEXT
GOTO main
Try changing
SERIN link, baud, 50,timeout, [WAIT("~!"), STR` level(chanid)\8]
to
SERIN link, baud, 50, timeout [WAIT("~!"), STR level(chanid)\8]
Since, from what I can tell from the manual, the ` is an extra character. Since I don't have a basic stamp, I can't test. Best I can do is look for the obvious. See page 409 of that manual.
Also, I don't think the first code snippet would work because of what the manual says about decimal formatted input.
Good Luck -- John
removing that character has somehow caused the code to no longer compile. any more ideas:
' {$STAMP BS2}
' {$PBASIC 2.5}
'Program: LightingFirmware
'Version: 1.0.3
'Purpose: Interface with Vixen lighting control
' software and bridge to SSR grid.
'--------------------------------------------resources------------------------------------
'baud CON 16468
baud CON 84
link CON 16
chan VAR BYTE(8)
chanid VAR BYTE
'--------------------------------------------main loop------------------------------------
main:
DO
SERIN link, baud, 50,timeout, [WAIT("~!"),STR chan(chanid)\8]
FOR chanid=1 TO 8
IF chan(chanid)>0 THEN HIGH chan(chanid)
NEXT
LOOP
'-------------------------------------------serial timout---------------------------------
timeout: 'in the event of a loss of serial comm, turn off all outputs
FOR chanid = 1 TO 8
LOW chanid
NEXT
GOTO main
or perhaps instead of trying to trouble shoot this code, I should write new code. All I need to do is grab the incoming values from the serial plugin. Speaking of which, does anyone have an editable copy of the serial plugin?
