beautypg.com

H-4271, 9 example sleep&sniff host driver, 8 installation and maintenance – Xylem H-4271 User Manual

Page 18

background image

2.9 Example Sleep&Sniff Host Driver

/*
* **************************************************************
* Subroutine: SDI_Send_Command_RS232(int port, int radio)
*
* Description: Send an SDI-12 command out the selected serial port
* This is an upper level routine that
* handles sending breaks and retries.
*
* Inputs: port = com port 1, 2, or 3
* radio = yes or no
* Changes the time outs and
* wakes up the radios
*
* Return: char 0 = error
* !0 = ok, sensor address
*
* **************************************************************
*/

@far char SDI_Send_Command_RS232(int port, int radio)
{
char Data;
char c;
int Timeout;
int i;
char buffer[50];
char retry;

if(port == MainPort) // Port is in use for the menu or command mode
return(0); // so just return with an error

//
// start of retry loop
//

Data = 0; // default to no response
retry = SDIBreakRetry + 1; // each retry will cause a break on the H-4191

do
{
EnableComPort(port,9600); // Turn on the RS232 drivers

if(radio) // if a radio connection is selected
{ // then send radio preamble
putcharX(port,0xFF); // It may take up to 4 to wake the remote 4191
putcharX(port,0xFF); // the first few chars are lost because 4191
putcharX(port,0xFF); // is waking up during first few chars
putcharX(port,0xFF);
putcharX(port,0xFF);
putcharX(port,0xFF);
putcharX(port,0xFF);
}

// send the command

printstringX(port,SDI_Out_buffer);

// wait xx seconds for the command
// Use a little longer delay for the radio mode
// The delay is not exact as overhead extends the loop

if(radio)
Timeout = 6500; // 6.5 second delay between retries
else
Timeout = 1500; // 1.5 second delay

do
{
msdelay(1);

if(port == 1)
if(COM1_LastChar == 0x0A) // CR LF terminates the response
Timeout = 0;

2-8 Installation And Maintenance

H-4271