HA243821
Issue 5 Mar 98
Section5
Page 5 - 55
MODEL 346 INSTALLATION AND OPERATION MANUAL
5.7.9 C PROGRAM LISTING (Cont.)
/**************************************************************************
FUNCTION
:
GET REPLY
DESCRIPTION
:
This routine waits for a message to be returned from the instrument.
Latency delays are allowed for on the first character. The checksum
is tested in messages ending with ETX
ARGUMENTS
:
port
= port offset
reply
= pointer to character buffer for received message.
RETURNS
:
NUL
= failed. Otherwise, last letter of message ETX, EOT, ACK,
NAK.
NOTES
:
**************************************************************************/
char get_reply( int port, char *reply )
{
char bcc = NUL;
/* Initialise BCC */
int i = 25;
/* Wait for first non NUL character of the reply.*/
if ( (*reply = get_byte_filt( port )) == NUL )
return( NUL );
/* Timeout: return NUL */
/****** Receive the rest of the message.******/
while (( *reply != ETX ) && ( *reply !=EOT ) &&( *reply != ACK ) &&
( *reply !=NAK ) &&( —i >=0))
{
if ( *reply == STX ) /* In case another STX arrives */
bcc = NUL; /* Re-initialise BCC */
else bcc ^= *reply;
/* XOR with current character */
*++reply = get_byte(port);
}
/****** Verify the message checksum.******/
if ( *reply == ETX )
{
bcc ^= *reply;
(void) printf(“calculated chsum= %x “,bcc);
*++reply = get_byte(port);(void) printf(“received cksum= %x \n”, *reply );
bcc ^= *reply;
*reply = NUL;
/* Overwrite checksum with NUL */
if ( bcc != NUL )
return( NUL );
/* Checksum error: return NUL */
return( ETX );
/* ETX: Good bcc received. */
}
else
{
*++reply = NUL; /* Write NUL after non ETX character */
return( *—reply );
/* Return with last character received */
}
}