public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YLightSensor sensor; if (Target.ToLower() == "any") { sensor = YLightSensor.FirstLightSensor(); if (sensor == null) { WriteLine("No module connected (check USB cable) "); return(-1); } } else { sensor = YLightSensor.FindLightSensor(Target + ".lightSensor"); } while (await sensor.isOnline()) { WriteLine("Ambient light: " + await sensor.get_currentValue() + " lx"); await YAPI.Sleep(1000); } WriteLine("Module not connected (check identification and USB cable)"); } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
// link the instance to a real YoctoAPI object internal override void linkToHardware(string hwdName) { YLightSensor hwd = YLightSensor.FindLightSensor(hwdName); // first redo base_init to update all _func pointers base_init(hwd, hwdName); // then setup Yocto-API pointers and callbacks init(hwd); }
static void Main(string[] args) { string errmsg = ""; string target; YLightSensor ir, al; YProximity p; if (args.Length < 1) { usage(); } target = args[0].ToUpper(); // Setup the API to use local USB devices if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { p = YProximity.FirstProximity(); if (p == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } target = p.get_module().get_serialNumber(); } else { p = YProximity.FindProximity(target + ".proximity1"); } if (!p.isOnline()) { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); Environment.Exit(0); } al = YLightSensor.FindLightSensor(target + ".lightSensor1"); ir = YLightSensor.FindLightSensor(target + ".lightSensor2"); while (p.isOnline()) { Console.Write(" Proximity: " + p.get_currentValue().ToString()); Console.Write(" Ambiant: " + al.get_currentValue().ToString()); Console.Write(" IR: " + ir.get_currentValue().ToString()); Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); }
static void Main(string[] args) { string errmsg = ""; string target; YRangeFinder rf; YLightSensor ir; YTemperature tmp; if (args.Length < 1) { usage(); } target = args[0].ToUpper(); // Setup the API to use local USB devices if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { rf = YRangeFinder.FirstRangeFinder(); if (rf == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } target = rf.get_module().get_serialNumber(); } else { rf = YRangeFinder.FindRangeFinder(target + ".rangefinder1"); } if (!rf.isOnline()) { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); Environment.Exit(0); } ir = YLightSensor.FindLightSensor(target + ".lightSensor1"); tmp = YTemperature.FindTemperature(target + ".temperature1"); while (rf.isOnline()) { Console.WriteLine("Distance : " + rf.get_currentValue().ToString()); Console.WriteLine("Ambiant IR : " + ir.get_currentValue().ToString()); Console.WriteLine("Temperature : " + tmp.get_currentValue().ToString()); Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); }
public static YLightSensorProxy FindLightSensor(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YLightSensor func = null; YLightSensorProxy res = (YLightSensorProxy)YFunctionProxy.FindSimilarUnknownFunction("YLightSensorProxy"); if (name == "") { if (res != null) { return(res); } res = (YLightSensorProxy)YFunctionProxy.FindSimilarKnownFunction("YLightSensorProxy"); if (res != null) { return(res); } func = YLightSensor.FirstLightSensor(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YLightSensorProxy)func.get_userData()); } } } else { func = YLightSensor.FindLightSensor(name); if (func.get_userData() != null) { return((YLightSensorProxy)func.get_userData()); } } if (res == null) { res = new YLightSensorProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
static void Main(string[] args) { string errmsg = ""; string target; YLightSensor sensor; if (args.Length < 1) { usage(); } target = args[0].ToUpper(); // Setup the API to use local USB devices if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { sensor = YLightSensor.FirstLightSensor(); if (sensor == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } } else { sensor = YLightSensor.FindLightSensor(target + ".lightSensor"); } if (!sensor.isOnline()) { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); Environment.Exit(0); } while (sensor.isOnline()) { Console.WriteLine("Current ambient light: " + sensor.get_currentValue().ToString() + " lx"); Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YRangeFinder rf; YLightSensor ir; YTemperature tmp; if (Target.ToLower() == "any") { rf = YRangeFinder.FirstRangeFinder(); if (rf == null) { WriteLine("No module connected (check USB cable) "); return(-1); } Target = await(await rf.get_module()).get_serialNumber(); } else { rf = YRangeFinder.FindRangeFinder(Target + ".rangefinder1"); } ir = YLightSensor.FindLightSensor(Target + ".lightSensor1"); tmp = YTemperature.FindTemperature(Target + ".temperature1"); while (await rf.isOnline()) { WriteLine("Distance : " + await rf.get_currentValue()); WriteLine("Ambiant IR : " + await ir.get_currentValue()); WriteLine("Temperature : " + await tmp.get_currentValue()); await YAPI.Sleep(1000); } WriteLine("Module not connected (check identification and USB cable)"); } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YLightSensor ir, al; YProximity p; if (Target.ToLower() == "any") { p = YProximity.FirstProximity(); if (p == null) { WriteLine("No module connected (check USB cable) "); return(-1); } Target = await(await p.get_module()).get_serialNumber(); } else { p = YProximity.FindProximity(Target + ".proximity1"); } al = YLightSensor.FindLightSensor(Target + ".lightSensor1"); ir = YLightSensor.FindLightSensor(Target + ".lightSensor2"); while (await p.isOnline()) { Write("Proximity: " + await p.get_currentValue()); Write("\tAmbiant: " + await al.get_currentValue()); WriteLine("\tIR: " + await ir.get_currentValue()); await YAPI.Sleep(1000); } WriteLine("Module not connected (check identification and USB cable)"); } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
/*setup timers, connections and variables*/ public UI_NetStatusPanel() { string errmsg = ""; InitializeComponent(); //Setup scalers and controls that must be scaled UIsetup(); _cmdUpdate = Update_CommandUI; _iofeedback = Update_IO_Displays; // Setup the API to use local USB devices if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { set_display1("error: " + errmsg); Logging.Add("Cant initiaet Yocto API, do you have another instance running?"); } else { Logging.Add("Yapi Initiated"); } //Set Sensors 1 and 2 sensor1 = YLightSensor.FindLightSensor("L1" + ".lightSensor"); if (sensor1 == null) { set_display1("no L1 sensor"); } else { set_display1("L1 Ok"); } sensor2 = YLightSensor.FindLightSensor("L2" + ".lightSensor"); if (sensor2 == null) { set_display2("no L2 sensor"); Logging.Add("L1 not connected"); } else { set_display2("L2 Ok"); } /*delegates for ui updates*/ _updatedisplay1 = (set_display1); _updatedisplay2 = (set_display2); _updatefeedback = (Update_feedback); _ipConfig = Update_IP_Config; Logic.Initialise_Cameras(); Servlet.Userinterface = this; ///assigning treference to ui for the servlets to conduct updates. This needs to be changed! Logic.Start(); //start a timer _UsbLightReading = new System.Threading.Timer(Lsensor_Tick, null, 0, 1000); //start a timer _NetworkTimer = new System.Threading.Timer(Nmanager.Tick, null, 0, 1000); }