#include /* Tattletale Model 8 Definitions */ #include /* definitions and prototypes for Model 8 library */ #include #include #include #include "lobo.h" /************************************************************************/ /* Function : sampleSBE16 */ /* Purpose : Function to sample SBE16 CTD and return the data (buf) */ /* Inputs : None */ /* Outputs : None */ /************************************************************************/ /* This routine is called on EVERY sample loop of the logger. It is up */ /* to the sample routine to determine whether it's time to actually run */ /* the device. This is normally done by simply counting calls, and */ /* running every Nth call. */ /* This routine should put the resulting data in *datap */ /************************************************************************/ short SampleSBE16(FILE *fptr, ushort mode) { extern ushort WrLatch2Val; char buf[200]; ushort relays; short tsret; int year; float tstamp; long ctdret; if( (mode != SAMPLE) && (mode != CONNECT) ) return( -1 ); tstamp = GetDOYtime(&year); if( ((RdLatch1() >> 8) & KON(SBE16_CHAN) ) != FALSE) Set_K1_K8_State( KOFF(SBE16_CHAN) ); /* Turn comms relay for CTD OFF */ if( tsret=tserOpen(SBE16_CHAN, (long)SBE16_BAUD, SBE16_PARITY, SBE16_DATABITS, SBE16_STOPBITS) == tsOK ){ Sleep(0); Sleep(TICKS_PER_SECOND/10); if((WrLatch2Val & RS232_RX_DISABLE ) != FALSE) Clear_Bit_WrLatch2(RS232_RX_DISABLE); if((WrLatch2Val & RS232_TX1_ENABLE) == FALSE) Set_Bit_WrLatch2(RS232_TX1_ENABLE); Sleep(0); Sleep(TICKS_PER_SECOND/2); relays = Set_K1_K8_State( KON(SBE16_CHAN) ); /* Turn comms relay for CTD ON */ Sleep(0); Sleep(TICKS_PER_SECOND/2); tserInFlush(SBE16_CHAN); if(mode == SAMPLE){ if((ctdret=GetCtdData(SBE16_CHAN, buf, sizeof(buf), SBE16_TIMEOUT)) <= 0) fprintf(fptr, ", %04d.%010f, SBE16 GetCtdData() ret = %ld\n", year, tstamp, ctdret); else fprintf(fptr, ", %04d.%010f, %s\n", year, tstamp, buf); } else if(mode == CONNECT){ if( WakeUpCtd(SBE16_CHAN, SBE16_TIMEOUT) == TRUE ){ printf("\nConnected... CTRL_D to Exit.\n"); InstrumentConnect(SBE16_CHAN); tserPuts(SBE16_CHAN, "QS\r"); // Put CTD back to sleep } else{ printf("\nInstrument Not Responding!\n"); if( QueryYesNo("\n Force Connect", FALSE) ){ printf("\nConnecting... CTRL_D to Exit.\n"); InstrumentConnect(SBE16_CHAN); tserPuts(SBE16_CHAN, "QS\r"); // Put CTD back to sleep } } } Set_K1_K8_State( KOFF(SBE16_CHAN) ); /* Turn comms relay for CTD OFF */ Clear_Bit_WrLatch2(RS232_TX1_ENABLE); Set_Bit_WrLatch2(RS232_RX_DISABLE); tserClose(SBE16_CHAN); return(TRUE); } else{ fprintf(fptr,", %04d.%010f, SEB16 tserOpen() ret = %d\n", year, tstamp, tsret); return(FALSE); } } /* SampleSBE16() */ /************************************************************************/ /* Function : sampleSBE37 */ /* Purpose : Function to sample SBE37 CTD and return the data (buf) */ /* Inputs : None */ /* Outputs : None */ /************************************************************************/ /* This routine is called on EVERY sample loop of the logger. It is up */ /* to the sample routine to determine whether it's time to actually run */ /* the device. This is normally done by simply counting calls, and */ /* running every Nth call. */ /* This routine should put the resulting data in *datap */ /************************************************************************/ short SampleSBE37(FILE *fptr, ushort mode) { extern ushort WrLatch2Val; char buf[200]; ushort relays; short tsret; int year; float tstamp; long ctdret; if( (mode != SAMPLE) && (mode != CONNECT) ) return( -1 ); tstamp = GetDOYtime(&year); if( ((RdLatch1() >> 8) & KON(SBE37_CHAN) ) != FALSE) Set_K1_K8_State( KOFF(SBE37_CHAN) ); /* Turn comms relay for CTD OFF */ if( tsret=tserOpen(SBE37_CHAN, (long)SBE37_BAUD, SBE37_PARITY, SBE37_DATABITS, SBE37_STOPBITS) == tsOK ){ Sleep(0); Sleep(TICKS_PER_SECOND/10); if((WrLatch2Val & RS232_RX_DISABLE ) != FALSE) Clear_Bit_WrLatch2(RS232_RX_DISABLE); if((WrLatch2Val & RS232_TX1_ENABLE) == FALSE) Set_Bit_WrLatch2(RS232_TX1_ENABLE); Sleep(0); Sleep(TICKS_PER_SECOND/2); relays = Set_K1_K8_State( KON(SBE37_CHAN) ); /* Turn comms relay for CTD ON */ Sleep(0); Sleep(TICKS_PER_SECOND/2); tserInFlush(SBE37_CHAN); if(mode == SAMPLE){ if((ctdret=GetCtdData(SBE37_CHAN, buf, sizeof(buf), SBE37_TIMEOUT)) <= 0) fprintf(fptr, ", %04d.%010f, SBE37 GetCtdData() ret = %ld\n", year, tstamp, ctdret); else fprintf(fptr, ", %04d.%010f, %s\n", year, tstamp, buf); } else if(mode == CONNECT){ if( WakeUpCtd(SBE37_CHAN, SBE37_TIMEOUT) == TRUE ){ printf("\nConnected... CTRL_D to Exit.\n"); InstrumentConnect(SBE37_CHAN); tserPuts(SBE37_CHAN, "QS\r"); // Put CTD back to sleep } else{ printf("\nInstrument Not Responding!\n"); if( QueryYesNo("\n Force Connect", FALSE) ){ printf("\nConnecting... CTRL_D to Exit.\n"); InstrumentConnect(SBE37_CHAN); tserPuts(SBE37_CHAN, "QS\r"); // Put CTD back to sleep } } } Set_K1_K8_State( KOFF(SBE37_CHAN) ); // Turn comms relay for CTD OFF Clear_Bit_WrLatch2(RS232_TX1_ENABLE); Set_Bit_WrLatch2(RS232_RX_DISABLE); tserClose(SBE37_CHAN); return(TRUE); } else{ fprintf(fptr,", %04d.%010f, SEB37 tserOpen() ret = %d\n", year, tstamp, tsret); return(FALSE); } } /* SampleSBE37() */ /************************************************************************/ /* Function : WakeUpCtd */ /* Purpose : Look for CTD prompt */ /* Inputs : Timeout in seconds */ /* Outputs : TRUE or FALSE */ /************************************************************************/ short WakeUpCtd(ushort chan, ushort tmout) { #define NCHARS 30 register char c; short i, j; tserInFlush(chan); for(i = 10; i; i--){ // if(i != 10) // tserPutc(chan, CTRL_C); Sleep(0); tserPutc(chan, '\r'); Sleep(TICKS_PER_SECOND/4); for (j = NCHARS; j && ((c = tserGetcTmout(chan, tmout)) != ERROR); j--){ if( c == '>' ){ tserInFlush(chan); return( TRUE ); } } } return(FALSE); /* If timeout or loop finished */ } /************************************************************************/ /* Function : GetCtdData */ /* Purpose : Make one attempt to get CTD data */ /* Inputs : Buffer, size of Buffer */ /* Outputs : Number of bytes received from CTD */ /************************************************************************/ long GetCtdData(ushort chan, char *buf, ushort buflen, ushort tmout) { register long nchars; if (WakeUpCtd(chan, tmout) != TRUE) // Look for the CTD prompt return( -1L ); tserPuts(chan, "SL\r"); // Send Last Sample command nchars = (long) tserGetsTmout(chan, buf, buflen, tmout); if(nchars > 0){ // If CTD is not in LOGGING MODE the SL command will be echoed if (strstr(buf, "SL") != NULL){ // therefore, we need to go get the real CTD data now nchars = (long) tserGetsTmout(chan, buf, buflen, tmout); } tserPuts(chan, "QS\r"); // Put CTD back to sleep return ( nchars ); } else return ( -2L ); }