EMS Manual

Retrieving Event Messages Programmatically
EMS Manual426909-005
4-15
Obtaining an Event Message (GETEVENT)
END
ELSE
! Command completed without event message
BEGIN
! An error occurred on the command
END;
! Move context into spibuffer^image
spi^error := SSMOVETKN(ZSPI^TKN^CONTEXT,
spibuffer, 1,
spibuffer^image, 1);
! Handle any error from SPI procedure
IF spi^error <> ZSPI^ERR^OK THEN ...
! Build a GETEVENT command message that includes EOFSTOP
! and CONTEXT.
spibuffer ':=' spibuffer^image for ZEMS^VAL^BUFLEN Bytes;
! Determine how many bytes of spibuffer have been used
spi^error := SSGETTKN(spibuffer,
ZSPI^TKN^USEDLEN,
buffer^length);
! Handle any error from SPI procedure
IF spi^error <> ZSPI^ERR^OK THEN ...
! And send the command message
CALL WRITEREAD(fnum,
spibuffer,
buffer^length,
ZEMS^VAL^BUFLEN,
count^read);
IF <> THEN ... ! Handle the error
! The SPI response is now in spibuffer.
! Reset buffer length to what you declared for spibuffer
spi^error := SSPUTTKN(spibuffer,
ZSPI^TKN^RESET^BUFFER,
ZEMS^VAL^BUFLEN);
! See if anything wrong with response buffer
IF spi^error <> ZSPI^ERR^OK THEN ...
! Buffer ok. Was distributor GETEVENT command ok?
spi^error := SSGETTKN(spibuffer,
ZSPI^TKN^RETCODE,
error,
1);
! Handle any error from SPI procedure
IF spi^error <> ZSPI^ERR^OK THEN ...
! Check retcode as appropriate