public void connectToSensor() { Console.Write("Connecting to sensor..."); AgSalLib.SalError connectionError = AgSalLib.salConnectSensor3(out sensorHandle, default(IntPtr), sensorIp, 0, appName, 0); if (connectionError != AgSalLib.SalError.SAL_ERR_NONE) { Console.WriteLine("***"); Console.WriteLine("Aborting at connectToSensor() : salConnectSensor3 "); Console.WriteLine("-----------------------------------------------"); Console.WriteLine("SensorHandle: " + sensorHandle.ToString()); Console.WriteLine("sensorIp: " + sensorIp.ToString()); Console.WriteLine("appName: " + appName.ToString()); Console.WriteLine("ERROR: " + connectionError); } AgSalLib.SalError abortError = AgSalLib.salAbortAll(sensorHandle); if (abortError != AgSalLib.SalError.SAL_ERR_NONE) { Console.WriteLine("***"); Console.WriteLine("abborting at connectoToSensor() : SalAbortALL"); Console.WriteLine("-----------------------------------------------"); Console.WriteLine("SensorHandle: " + sensorHandle.ToString()); Console.WriteLine("ERROR: " + abortError); } if (connectionError == AgSalLib.SalError.SAL_ERR_NONE && abortError == AgSalLib.SalError.SAL_ERR_NONE) { Console.WriteLine("Connection Sucess!"); } }
public void Sweep(Object source, ElapsedEventArgs e) { Console.WriteLine("SWEEP"); AgSalLib.salGetSensorTime(sensorHandle, out timestamp); AgSalLib.salGetSensorLocation(sensorHandle, out location); if (!firstRow) { tempRow.Add(timestamp.ToString()); tempRow.Add(location.latitude.ToString()); tempRow.Add(location.longitude.ToString()); tempRow.Add(extTime); tempRow.Add(extLat); tempRow.Add(extLon); } spin.Turn(rowCounter, timestamp.ToString(), location.latitude.ToString(), location.longitude.ToString()); AgSalLib.SalError sweepError = AgSalLib.salStartSweep2( out measurementHandle, sensorHandle, ref sweepParams, ref pSegmentTable, ref flowControl, segmentCallback ); getStatus(); }
public void getStatus() { AgSalLib.SalError statusError = AgSalLib.salGetSweepStatus2(sensorHandle, 0, out status, out elapsed); Console.WriteLine("STATUS: " + status.ToString()); if (status == AgSalLib.SweepStatus.SweepStatus_stopped) { Console.WriteLine("STOPPED"); } }
private bool SensorError(AgSalLib.SalError err, string functionName) { string message = ""; if (err != AgSalLib.SalError.SAL_ERR_NONE) { message = functionName + " returned error " + err + " (" + AgSalLib.salGetErrorString(err, AgSalLib.Localization.English) + ")\n"; Utilites.LogMessage(message); return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="ip">ip address in dotted decimal</param> public SensorDriver(string preselectorIp, string sensorName) { this.sensorName = sensorName; preselector = new Preselector(preselectorIp); bool connectionPassed = ConnectSensor(); if (!connectionPassed) { Console.WriteLine("Connecting to sensor failed"); Environment.Exit(0); } AgSalLib.salSensorBeep(sensorHandle); CalcSampleRates(); }
public void getSensorCapibilities() { Console.Write("Getting capabilities..."); AgSalLib.SalError capabilitiesError = AgSalLib.salGetSensorCapabilities(sensorHandle, out sensorCapabilities); if (capabilitiesError != AgSalLib.SalError.SAL_ERR_NONE) { Console.WriteLine("***"); Console.WriteLine("abborting at getSensorCapibilities() : salGetSensorCapabilities"); Console.WriteLine("-----------------------------------------------"); Console.WriteLine("SensorHandle: " + sensorHandle.ToString()); Console.WriteLine("sensorCapabilities: " + sensorCapabilities.ToString()); Console.WriteLine("ERROR: " + capabilitiesError); } else { Console.WriteLine("Capabilities Sucess!"); } }
private bool ConnectSensor() { AgSalLib.SalError err; err = AgSalLib.salOpenSms(out smsHandle, smsHostName, 0, null); if (SensorError(err, "salOpenSms")) { return(false); } err = AgSalLib.salConnectSensor3(out sensorHandle, smsHandle, sensorName, 0, "Radar Sensor", 0); if (SensorError(err, "salConnectSensor3")) { return(false); } err = AgSalLib.salGetSensorCapabilities(sensorHandle, out sensorCapabilities); if (SensorError(err, "salGetSensorCapabilities")) { return(false); } return(true); }
private bool DetectSegment(SweepParams measParams, FFTParams fftParams, List <double> powerList, List <double> frequencies, double cf, uint numFftsToCopy, ref bool overloadFlag) { AgSalLib.SalError err; AgSalLib.SweepParms sweepParams = new AgSalLib.SweepParms(); AgSalLib.FrequencySegment[] fs = new AgSalLib.FrequencySegment[1]; switch (measParams.Window.ToLower()) { case "hanning": sweepParams.window = sweepParams.window = AgSalLib.WindowType.Window_hann; break; case "gauss-top": sweepParams.window = sweepParams.window = AgSalLib.WindowType.Window_gaussTop; break; case "flattop": sweepParams.window = sweepParams.window = AgSalLib.WindowType.Window_flatTop; break; case "rectangular": sweepParams.window = sweepParams.window = AgSalLib.WindowType.Window_uniform; break; default: Utilites.LogMessage("Invalid window type in " + "calibration json file"); return(true); } switch (measParams.TimeOverlap) { case 50: fs[0].overlapType = AgSalLib.OverlapType.OverlapType_on; break; default: fs[0].overlapType = AgSalLib.OverlapType.OverlapType_off; break; } switch (measParams.Detector.ToLower()) { case "rms": fs[0].averageType = fs[0].averageType = AgSalLib.AverageType.Average_rms; break; case "sample": fs[0].averageType = fs[0].averageType = AgSalLib.AverageType.Average_off; break; case "positive": fs[0].averageType = fs[0].averageType = AgSalLib.AverageType.Average_peak; break; default: Utilites.LogMessage("Invalid Detector type in " + "calibration json file"); return(true); } switch (measParams.Antenna) { case 0: fs[0].antenna = AgSalLib.AntennaType.Antenna_Terminated2; break; case 1: fs[0].antenna = AgSalLib.AntennaType.Antenna_1; break; case 2: fs[0].antenna = AgSalLib.AntennaType.Antenna_2; break; default: Utilites.LogMessage("Invalid antenna value " + "in cal json file"); return(true); } sweepParams.numSweeps = 1; sweepParams.numSegments = 1; sweepParams.sweepInterval = 0.0; sweepParams.monitorMode = AgSalLib.MonitorMode.MonitorMode_off; sweepParams.monitorInterval = 0.0; // data return type for sweepParams is always real float32 dbm fs[0].numFftPoints = fftParams.NumFftBins; fs[0].numAverages = fftParams.NumFftsToAvg; fs[0].firstPoint = 0; fs[0].numPoints = fs[0].numFftPoints; fs[0].centerFrequency = cf; fs[0].sampleRate = fftParams.SampleRate; fs[0].preamp = measParams.PreAmp; fs[0].attenuation = measParams.Attenuation; fs[0].dataType = AgSalLib.FftDataType.FftData_db; // Setup pacing AgSalLib.salFlowControl flowControl = new AgSalLib.salFlowControl(); flowControl.pacingPolicy = 1; // wait when full flowControl.maxBacklogMessages = 50; err = AgSalLib.salStartSweep2(out measHandle, sensorHandle, ref sweepParams, ref fs, ref flowControl, null); if (SensorError(err, "salStartSweep")) { if (err == AgSalLib.SalError.SAL_ERR_SENSOR_NOT_CONNECTED) { // lost connection to sensor, kill the process // service will start it again Environment.Exit(1); } return(true); } AgSalLib.SweepStatus status; double elapsed; AgSalLib.salGetSweepStatus2(measHandle, 0, out status, out elapsed); // wait until sweep is finished while (status == AgSalLib.SweepStatus.SweepStatus_running) { AgSalLib.salGetSweepStatus2(measHandle, 0, out status, out elapsed); } // get data from sweep AgSalLib.SegmentData dataHeader = new AgSalLib.SegmentData(); // Agilent DLL requires float array even though it uses double // everywhere else ..... annoying float[] frequencyData = new float[fftParams.NumFftBins]; // how long to read before exiting int maxDataReadMilliSeconds = 1000; DateTime t0 = DateTime.Now; bool dataRetrieved = false; int startIndex = 0; while (!dataRetrieved) { TimeSpan elapsedTime = DateTime.Now.Subtract(t0); if (elapsedTime.Milliseconds > maxDataReadMilliSeconds) { Utilites.LogMessage("Getting segment data timed out, " + "restarting cal"); } err = AgSalLib.salGetSegmentData(measHandle, out dataHeader, frequencyData, (uint)frequencyData.Length * 4); switch (err) { case AgSalLib.SalError.SAL_ERR_NONE: if (dataHeader.errorNum != AgSalLib.SalError.SAL_ERR_NONE) { string message = "Segment data header returned an error: \n\n"; message += "errorNumber: " + dataHeader.errorNum.ToString() + "\n"; message += "errorInfo: " + dataHeader.errorInfo; Utilites.LogMessage(message); return(true); } // get the data // check if need to remove anti aliasing // need startIndex after the while loop so declared outside if (measParams.RemoveAntiAliasing) { startIndex = GetStartIndex(fftParams.SampleRate, (int)fftParams.NumFftBins); } FloatArrayToListOfDoubles(frequencyData, powerList, numFftsToCopy, startIndex); // check if overload occured if (dataHeader.overload != 0) { overloadFlag = true; } else { overloadFlag = false; } dataRetrieved = true; break; case AgSalLib.SalError.SAL_ERR_NO_DATA_AVAILABLE: // data is not available yet ... break; case AgSalLib.SalError.SAL_ERR_SENSOR_NOT_CONNECTED: // lost connection to sensor, kill the process // service will start it again Environment.Exit(1); break; default: SensorError(err, "salGetSegmentData"); break; } } if (frequencies != null) { // calculate frquencies for (int i = 0; i < numFftsToCopy; i++) { frequencies.Add(dataHeader.startFrequency + (startIndex - 1) * dataHeader.frequencyStep + i * dataHeader.frequencyStep); } } return(false); }