HA243821
Issue 5 Mar 98
Section5
Page 5 - 57
MODEL 346 INSTALLATION AND OPERATION MANUAL
5.7.9 C PROGRAM LISTING (Cont.)
/**************************************************************************
FUNCTION
:
MAIN
DESCRIPTION
:
Top level of example of 346 comms program
ARGUMENTS
:
None
RETURNS
:
Void
NOTES
:
**************************************************************************/
void main()
{
int i, port, baud;
char address[5], chan[2], command[40];
char reply[40];
port = 0;
baud = 9600;
init_port( port, baud );
(void) printf(“\nEnter group address and unit address(no spaces)
e.g. 2211 :”);
(void) gets( address );
command[0] = ‘_’;
for(;;)
{
(void) printf(“Enter channel number 1 to { : “);
(void) gets( chan );(void) printf(“Enter command and data (no spaces)
e.g. PV12.345 or Q to quit: “);
(void) gets( command );
if ( !strcmp( command, “Q” ) || !strcmp( command, “q” ))
exit(0);
if ( command[2]== NUL )
/* Read */
{
if ((poll_value(port, address, command, chan, reply )) == NUL )
{
if (strlen(reply) != 0 )
(void) printf(“\nChk Sum Failed\n”);
else (void) printf(“\nNo reply\n” );
}
else
{
if ( reply[0] == EOT )
(void) printf(“\nUnrecognised command\n”);
else (void) printf(“\n %s \n\n”, reply );
}
}
else
/* Write */
{
if ((select_cmd( port, address, command, chan, reply )) != ACK)
(void) printf(“\nNo acknowledge\n”);else (void) printf(“\nAcknowledged\n”);
}
}
}