SPI Programming Manual (G06.24+, H06.03+, J06.03+)

SPI Programming Examples
SPI Programming Manual427506-006
E-35
Example E-9: A Simple SPI Requester in TAL
IF tkn^retcode THEN
BEGIN
sline ':=' "Error returned. RETCODE = (" -> @sp;
IF tkn^retcode < 0 THEN
BEGIN
sp ':=' "-" -> @sp;
@sp := @sp '+' dnumout (sp, $DBL (-tkn^retcode), 10);
END ELSE
BEGIN
@sp := @sp '+' dnumout (sp, $DBL (tkn^retcode), 10);
END;
sp ':=' ")" -> @sp;
CALL writex (term, sline, @sp '-' @sline);
END;
END;
END;
IF NOT err THEN
BEGIN
! retrieve and validate the context, if any
IF (err := ssgettkn (req^buffer, zspi^tkn^context, the^context, 1) =
zspi^err^ok) THEN
BEGIN
! This message has a context. Add it to the original message and
! send it again.
!
! This is what is happening. "sav^buffer" has the original msg sent.
! I will move the "context" token from the "req^buffer" to the
! "sav^buffer". Then, I will move "sav^buffer" to "req^buffer".
! Now "req^buffer" is ready to send, but "sav^buffer" has the
! "context" token added to the original msg sent. Thus, I will
! delete the "context" token from "sav^buffer".
!
source^idx := 1;
dest^idx := 1;
tkn^count := 1;
CALL ssmovetkn (zspi^tkn^context, req^buffer, source^idx,
sav^buffer, dest^idx, tkn^count);
req^buffer ':=' sav^buffer FOR max^bufsize/2 WORDS;
! Now delete the context token from the saved buffer.
tkn^code := zspi^tkn^context;
IF err := ssputtkn (sav^buffer, zspi^tkn^delete,
tkn^code) THEN
CALL display^spi^error (err, zspi^val^ssputtkn,
tkn^code, true);
GOTO SEND^IT;
END;
! No context. Get the string from the COMMENT token
IF err := ssgettkn (req^buffer, zspi^tkn^comment, in^string, 1) THEN
BEGIN
CALL display^spi^error (err, zspi^val^ssgettkn,
zspi^tkn^comment, false);
sline ':=' "Bad SPI buffer returned! Missing TKN^COMMENT." -> @sp;
CALL writex (term, sline, @sp '-' @sline);
END ELSE
BEGIN
sline ':=' in^string.data FOR in^string.len BYTES -> @sp;
CALL writex (term, sline, @sp '-' @sline);
END;
END; -- of IF NOT err
END; -- of WHILE 1=1 DO
END; -- OF PROC requester
Example E-9. TAL File: A Simple SPI Requester (page 8 of 8)