static void Main(string[] args) { string errmsg = ""; if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(1); } YSensor sensor; if (args.Length == 0 || args[0] == "any") { sensor = YSensor.FirstSensor(); if (sensor == null) { Console.WriteLine("No module connected (check USB cable)"); Environment.Exit(1); } } else { sensor = YSensor.FindSensor(args[0]); if (!sensor.isOnline()) { Console.WriteLine("Sensor " + sensor + " is not connected (check USB cable)"); Environment.Exit(1); } } dumpSensor(sensor); YAPI.FreeAPI(); Console.WriteLine("Done. Have a nice day :)"); }
// link the instance to a real YoctoAPI object internal override void linkToHardware(string hwdName) { YSensor hwd = YSensor.FindSensor(hwdName); // first redo base_init to update all _func pointers base_init(hwd, hwdName); // then setup Yocto-API pointers and callbacks init(hwd); }
public static YSensorProxy FindSensor(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YSensor func = null; YSensorProxy res = (YSensorProxy)YFunctionProxy.FindSimilarUnknownFunction("YSensorProxy"); if (name == "") { if (res != null) { return(res); } res = (YSensorProxy)YFunctionProxy.FindSimilarKnownFunction("YSensorProxy"); if (res != null) { return(res); } func = YSensor.FirstSensor(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YSensorProxy)func.get_userData()); } } } else { func = YSensor.FindSensor(name); if (func.get_userData() != null) { return((YSensorProxy)func.get_userData()); } } if (res == null) { res = new YSensorProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
public static YDataloggerContext init(string name, int start, int stop) { YSensor s = YSensor.FindSensor(name); if (!s.isOnline()) { throw new Exception("sensor " + name + " is offline or does not exist."); } YDataloggerContext ctx = new YDataloggerContext(s, start, stop); return(ctx); }
private void choosenDeviceChanged() { YModule currentDevice; devicesList.Enabled = devicesList.Items.Count > 0; // clear the functions drop down functionsList.Items.Clear(); functionsList.Enabled = devicesList.Enabled; if (!devicesList.Enabled) { unsupported_warning.Visible = false; nosensorfunction.Visible = false; return; // no device at all connected, } if (devicesList.SelectedIndex < 0) { devicesList.SelectedIndex = 0; } currentDevice = (YModule)devicesList.Items[devicesList.SelectedIndex]; // populate the second drop down if (currentDevice.isOnline()) { // device capabilities inventory int fctcount = currentDevice.functionCount(); for (int i = 0; i < fctcount; i++) { string fctName = currentDevice.functionId(i); string fctFullName = currentDevice.get_serialNumber() + '.' + fctName; YSensor fct = YSensor.FindSensor(fctFullName); // add the function in the second drop down if (fct.isOnline()) { functionsList.Items.Add(fct); } } } functionsList.Enabled = functionsList.Items.Count > 0; if (functionsList.Enabled) { functionsList.SelectedIndex = 0; } refreshFctUI(true); }
/** * <summary> * Returns an object holding historical data for multiple * sensors, for a specified time interval. * <para> * The measures will be retrieved from the data logger, which must have been turned * on at the desired time. The resulting object makes it possible to load progressively * a large set of measures from multiple sensors, consolidating data on the fly * to align records based on measurement timestamps. * </para> * <para> * </para> * </summary> * <param name="sensorNames"> * array of logical names or hardware identifiers of the sensors * for which data must be loaded from their data logger. * </param> * <param name="startTime"> * the start of the desired measure time interval, * as a Unix timestamp, i.e. the number of seconds since * January 1, 1970 UTC. The special value 0 can be used * to include any measure, without initial limit. * </param> * <param name="endTime"> * the end of the desired measure time interval, * as a Unix timestamp, i.e. the number of seconds since * January 1, 1970 UTC. The special value 0 can be used * to include any measure, without ending limit. * </param> * <returns> * an instance of <c>YConsolidatedDataSet</c>, providing access to * consolidated historical data. Records can be loaded progressively * using the <c>YConsolidatedDataSet.nextRecord()</c> method. * </returns> */ public static YConsolidatedDataSet Init(List <string> sensorNames, double startTime, double endTime) { int nSensors; List <YSensor> sensorList = new List <YSensor>(); int idx; string sensorName; YSensor s; YConsolidatedDataSet obj; nSensors = sensorNames.Count; sensorList.Clear(); idx = 0; while (idx < nSensors) { sensorName = sensorNames[idx]; s = YSensor.FindSensor(sensorName); sensorList.Add(s); idx = idx + 1; } obj = new YConsolidatedDataSet(startTime, endTime, sensorList); return(obj); }