'Judd Communications Depth Sensor with 'Digital Output option, programming example 'Wiring 'Red +12V 'Black G 'Clear G 'Green C1 'White C4 'Brown Not used '----------------------------------------------- '\\\\\\\\\\\\\\\\\\\\\\\\\ DECLARATIONS ///////////////////////// Public Battery Public DSTempF Public DSTime Public DSDepth Public DSRetries Public DSOutString AS String Public DSOutVal(4) '\\\\\\\\\\\\\\\\\\\\\\\\ OUTPUT SECTION //////////////////////// DataTable(Table101,true,-1) OpenInterval DataInterval(0,1,Min,10) Sample(1, Battery, FP2) Sample(1, DSTempF, FP2) Sample(1, DSTime, FP2) Sample(1, DSDepth, FP2) Sample(1, DSRetries, FP2) EndTable '\\\\\\\\\\\\\\\\\\\\\\\\\ SUBROUTINES ////////////////////////// '\\\\\\\\\\\\\\\\\\\\\\\\\\\ PROGRAM //////////////////////////// BeginProg Scan(5,Sec, 3, 0) SequentialMode Battery(Battery) 'Turn Depth Sensor ON using Control port 1 PortSet(1, 1) 'Wait 3 seconds for ASCII sentence from sensor 'Data is input to Control port 4. Control port 3 'is used by the SerialIn instruction as a TX line. 'Nothing is connected to Control port 3 SerialOpen (Com2,1200,0,0,10000) SerialIn (DSOutString,Com2,300,13,100) SerialClose (Com2) 'Turn Depth Sensor OFF PortSet(1, 0) SplitStr (DSOutVal(),DSOutString,Chr(9),4,0) 'Convert Air Temp from Kelvin x 2, to Farenheit 'From K to C DSTempF = DSOutVal(1) DSTempF = DSTempF * 0.5 DSTempF = DSTempF + -273 'From C to F DSTempF = DSTempF * 1.8 DSTempF = DSTempF + 32 'Get DSTime DSTime = DSOutVal(2) 'Convert Distance measured from millimeters to 'inches, and convert to a negative number DSDepth = DSOutVal(3) DSDepth = DSDepth * 0.0394 'Get number of Retries DSRetries = DSOutVal(4) '------------------------------------------------ 'Log sensor output once an hour CallTable Table101 NextScan EndProg