// Methods /// <summary> /// Get sensor /// </summary> /// <returns></returns> protected override YSensor GetSensor() { string errmsg = ""; if (hardwaredetect == 0) { YAPI.UpdateDeviceList(ref errmsg); } hardwaredetect = (hardwaredetect + 1) % 20; YAPI.HandleEvents(ref errmsg); YTemperature sensor = YTemperature.FirstTemperature(); if (sensor is null) { throw new SensorNotDetectedException(); } else if (!sensor.isOnline()) { throw new SensorOfflineException(); } else { return(sensor); } }
private void button1_Click(object sender, EventArgs e) { YModule m; string errmsg = ""; if (YAPI.RegisterHub("usb", ref errmsg) == YAPI.SUCCESS) { notifyIcon1.ShowBalloonTip(5, "PsymonWeather Beta", "Connection effectuée", ToolTipIcon.Info); timer1.Enabled = true; btnConnexion.Enabled = false; btnDeco.Enabled = true; toolStripStatusLabel1.Text = "Connecté : Oui"; m = YModule.FindModule("PsymonWeather"); lblSerial.Text = m.get_firmwareRelease().ToString(); progressTemp.Minimum = 0; progressTemp.Maximum = 40; YTemperature temp = YTemperature.FindTemperature("temperature"); progressTemp.Value = (int)temp.get_currentValue(); lblTemp.Text = string.Format("{0} °C", temp.get_currentValue()); YHumidity humid = YHumidity.FindHumidity("humidity"); lblHumid.Text = string.Format("{0} % d'humidité", humid.get_currentValue()); YPressure pressure = YPressure.FindPressure("pressure"); lblPressure.Text = string.Format("{0} Bar", pressure.get_currentValue()); notifyIcon1.Text = string.Format("PsymonWeather Beta\nTemp. : {0}\nHumid. : {1}\nPress. : {2}", temp.get_currentValue(), humid.get_currentValue(), pressure.get_currentValue()); } else { toolStripStatusLabel1.Text = "Connecté : Erreur"; MessageBox.Show("Le module n'est pas branché."); } }
static void Main(string[] args) { string errmsg = ""; string target; YTemperature tsensor; 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") { tsensor = YTemperature.FirstTemperature(); if (tsensor == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } Console.WriteLine("Using: " + tsensor.get_module().get_serialNumber()); } else { tsensor = YTemperature.FindTemperature(target + ".temperature1"); } // retreive module serial string serial = tsensor.get_module().get_serialNumber(); // retreive both channels YTemperature ch1 = YTemperature.FindTemperature(serial + ".temperature1"); YTemperature ch2 = YTemperature.FindTemperature(serial + ".temperature2"); if (!ch2.isOnline()) { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); Environment.Exit(0); } while (ch2.isOnline()) { Console.Write("Ambiant: " + ch1.get_currentValue().ToString() + " °C "); Console.Write("Infrared: " + ch2.get_currentValue().ToString() + " °C "); 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); YMotor motor; YCurrent current; YVoltage voltage; YTemperature temperature; if (Target.ToLower() == "any") { // find the serial# of the first available motor motor = YMotor.FirstMotor(); if (motor == null) { WriteLine("No module connected (check USB cable) "); return(-1); } Target = await(await motor.get_module()).get_serialNumber(); } int power = Convert.ToInt32(Power); motor = YMotor.FindMotor(Target + ".motor"); current = YCurrent.FindCurrent(Target + ".current"); voltage = YVoltage.FindVoltage(Target + ".voltage"); temperature = YTemperature.FindTemperature(Target + ".temperature"); // lets start the motor if (await motor.isOnline()) { // if motor is in error state, reset it. if (await motor.get_motorStatus() >= YMotor.MOTORSTATUS_LOVOLT) { await motor.resetStatus(); } await motor.drivingForceMove(power, 2000); // ramp up to power in 2 seconds while (await motor.isOnline()) { // display motor status WriteLine("Status=" + await motor.get_advertisedValue() + " " + "Voltage=" + await voltage.get_currentValue() + "V " + "Current=" + await current.get_currentValue() / 1000 + "A " + "Temp=" + await temperature.get_currentValue() + "deg C"); await YAPI.Sleep(1000); // wait for one second } } } 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) { YTemperature hwd = YTemperature.FindTemperature(hwdName); // first redo base_init to update all _func pointers base_init(hwd, hwdName); // then setup Yocto-API pointers and callbacks init(hwd); }
public void newTempSensorData(YTemperature source, YMeasure data) { pointXY p = new pointXY() { x = data.get_endTimeUTC(), y = data.get_averageValue() }; TempData.Add(p); monitor_tData.AddPoint(p); }
// perform the 2nd stage setup that requires YoctoAPI object protected void init(YTemperature hwd) { if (hwd == null) { return; } base.init(hwd); InternalStuff.log("registering Temperature callback"); _func.registerValueCallback(valueChangeCallback); }
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 void reloadConfig(YModule Source) { _name = _sourceSensor.get_friendlyName();; _serial = _sourceSensor.get_module().get_module().get_serialNumber(); _unit = _sourceSensor.get_unit(); _datalogger = YDataLogger.FindDataLogger(_serial + ".dataLogger"); _tempSensor = YTemperature.FindTemperature(_serial + ".temperature"); string tt = _sourceSensor.get_hardwareId().Replace("weighScale", "genericSensor"); _genSensor = YGenericSensor.FindGenericSensor(tt); }
public static YTemperatureProxy FindTemperature(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YTemperature func = null; YTemperatureProxy res = (YTemperatureProxy)YFunctionProxy.FindSimilarUnknownFunction("YTemperatureProxy"); if (name == "") { if (res != null) { return(res); } res = (YTemperatureProxy)YFunctionProxy.FindSimilarKnownFunction("YTemperatureProxy"); if (res != null) { return(res); } func = YTemperature.FirstTemperature(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YTemperatureProxy)func.get_userData()); } } } else { func = YTemperature.FindTemperature(name); if (func.get_userData() != null) { return((YTemperatureProxy)func.get_userData()); } } if (res == null) { res = new YTemperatureProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
/** * <summary> * Retrieves a temperature sensor for a given identifier. * <para> * The identifier can be specified using several formats: * </para> * <para> * </para> * <para> * - FunctionLogicalName * </para> * <para> * - ModuleSerialNumber.FunctionIdentifier * </para> * <para> * - ModuleSerialNumber.FunctionLogicalName * </para> * <para> * - ModuleLogicalName.FunctionIdentifier * </para> * <para> * - ModuleLogicalName.FunctionLogicalName * </para> * <para> * </para> * <para> * This function does not require that the temperature sensor is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method <c>YTemperature.isOnline()</c> to test if the temperature sensor is * indeed online at a given time. In case of ambiguity when looking for * a temperature sensor by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * </para> * </summary> * <param name="func"> * a string that uniquely characterizes the temperature sensor * </param> * <returns> * a <c>YTemperature</c> object allowing you to drive the temperature sensor. * </returns> */ public static YTemperature FindTemperature(string func) { YTemperature obj; obj = (YTemperature)YFunction._FindFromCache("Temperature", func); if (obj == null) { obj = new YTemperature(func); YFunction._AddToCache("Temperature", func, obj); } return(obj); }
/** * <summary> * Enumerates all functions of type Temperature available on the devices * currently reachable by the library, and returns their unique hardware ID. * <para> * Each of these IDs can be provided as argument to the method * <c>YTemperature.FindTemperature</c> to obtain an object that can control the * corresponding device. * </para> * </summary> * <returns> * an array of strings, each string containing the unique hardwareId * of a device function currently connected. * </returns> */ public static new string[] GetSimilarFunctions() { List <string> res = new List <string>(); YTemperature it = YTemperature.FirstTemperature(); while (it != null) { res.Add(it.get_hardwareId()); it = it.nextTemperature(); } return(res.ToArray()); }
// --- (end of YTemperature implementation) // --- (Temperature functions) /** * <summary> * Retrieves a temperature sensor for a given identifier. * <para> * The identifier can be specified using several formats: * </para> * <para> * </para> * <para> * - FunctionLogicalName * </para> * <para> * - ModuleSerialNumber.FunctionIdentifier * </para> * <para> * - ModuleSerialNumber.FunctionLogicalName * </para> * <para> * - ModuleLogicalName.FunctionIdentifier * </para> * <para> * - ModuleLogicalName.FunctionLogicalName * </para> * <para> * </para> * <para> * This function does not require that the temperature sensor is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method <c>YTemperature.isOnline()</c> to test if the temperature sensor is * indeed online at a given time. In case of ambiguity when looking for * a temperature sensor by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * </para> * </summary> * <param name="func"> * a string that uniquely characterizes the temperature sensor * </param> * <returns> * a <c>YTemperature</c> object allowing you to drive the temperature sensor. * </returns> */ public static YTemperature FindTemperature(string func) { YTemperature res; if (_TemperatureCache.ContainsKey(func)) { return((YTemperature)_TemperatureCache[func]); } res = new YTemperature(func); _TemperatureCache.Add(func, res); return(res); }
static void Main(string[] args) { string errmsg = ""; string target; YTemperature tsensor; 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") { tsensor = YTemperature.FirstTemperature(); if (tsensor == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } } else { tsensor = YTemperature.FindTemperature(target + ".temperature"); } if (!tsensor.isOnline()) { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); Environment.Exit(0); } while (tsensor.isOnline()) { Console.WriteLine("Current temperature: " + tsensor.get_currentValue().ToString() + " °C"); Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); }
private void moduleInventory() { YModule m, currentmodule; YTemperature sensor; int index; comboBox1.Items.Clear(); currentmodule = null; sensor = YTemperature.FirstTemperature(); while (sensor != null) { m = sensor.get_module(); comboBox1.Items.Add(m); sensor = sensor.nextTemperature(); } if (comboBox1.Items.Count == 0) { comboBox1.Enabled = false; Beacon.Enabled = false; label1.Enabled = false; label1.Text = "N/A"; toolStripStatusLabel2.Text = "Connect a device featuring a temperature sensor"; } else { index = 0; comboBox1.Enabled = true; Beacon.Enabled = true; for (int i = 0; i < comboBox1.Items.Count; i++) { if (comboBox1.Items[i].Equals(currentmodule)) { index = i; } } if (comboBox1.Items.Count == 1) { toolStripStatusLabel2.Text = "One device connected"; } else { toolStripStatusLabel2.Text = comboBox1.Items.Count.ToString() + " devices connected"; } comboBox1.SelectedIndex = index; } }
public void reloadInfos() { YTemperature temp = YTemperature.FindTemperature("temperature"); progressTemp.Value = (int)temp.get_currentValue(); lblTemp.Text = string.Format("{0} °C", temp.get_currentValue()); YHumidity humid = YHumidity.FindHumidity("humidity"); lblHumid.Text = string.Format("{0} % d'humidité", humid.get_currentValue()); YPressure pressure = YPressure.FindPressure("pressure"); lblPressure.Text = string.Format("{0} Bar", pressure.get_currentValue()); notifyIcon1.Text = string.Format("PsymonWeather Beta\nTemp. : {0} °C\nHumid. : {1}\nPress. : {2} Bar", temp.get_currentValue(), humid.get_currentValue(), pressure.get_currentValue()); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YTemperature tsensor; if (Target.ToLower() == "any") { tsensor = YTemperature.FirstTemperature(); if (tsensor == null) { WriteLine("No module connected (check USB cable) "); return(-1); } Target = await(await tsensor.get_module()).get_serialNumber(); } WriteLine("Using: " + Target); // retreive all 6 channels YTemperature ch1 = YTemperature.FindTemperature(Target + ".temperature1"); YTemperature ch2 = YTemperature.FindTemperature(Target + ".temperature2"); YTemperature ch3 = YTemperature.FindTemperature(Target + ".temperature3"); YTemperature ch4 = YTemperature.FindTemperature(Target + ".temperature4"); YTemperature ch5 = YTemperature.FindTemperature(Target + ".temperature5"); YTemperature ch6 = YTemperature.FindTemperature(Target + ".temperature6"); while (await ch2.isOnline()) { Write("| 1: " + (await ch1.get_currentValue()).ToString(" 0.0")); Write(" | 2: " + (await ch2.get_currentValue()).ToString(" 0.0")); Write(" | 3: " + (await ch3.get_currentValue()).ToString(" 0.0")); Write(" | 4: " + (await ch4.get_currentValue()).ToString(" 0.0")); Write(" | 5: " + (await ch5.get_currentValue()).ToString(" 0.0")); Write(" | 6: " + (await ch6.get_currentValue()).ToString(" 0.0")); WriteLine("| °C "); 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); }
// called when a device is unplugged public void deviceRemoval(YModule m) { //Cycle on All DropDown gauges for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); int selected = d.SelectedIndex; // cycle on all gauge dropdown items for (int i = d.Items.Count - 1; i >= 0; i--) { //search for function stored in the drop down list MyTemperature mt = (MyTemperature)d.Items[i]; YTemperature t = mt.getYTemperature(); // test if the fucntion parent module is the the one removed // note : it's too late to use get_module on t, so with use // a little trick: with stored the module serial in the function // userdate. if ((string)t.get_userData() == m.get_serialNumber()) { // remove it from the drop down d.Items.RemoveAt(i); // selected index update if (selected == i) { selected--; } if (selected >= d.Items.Count) { selected = d.Items.Count - 1; } } } if (selected >= 0) { d.SelectedIndex = selected; } } // disable empty dropdowns for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); if (d.Enabled && d.Items.Count <= 0) { d.Enabled = false; } } }
private void refreshUI() { YModule m; YTemperature sensor; if (comboBox1.Enabled) { m = (YModule)comboBox1.Items[comboBox1.SelectedIndex]; sensor = YTemperature.FindTemperature(m.get_serialNumber() + ".temperature"); if (sensor.isOnline()) { label1.Enabled = true; label1.Text = sensor.get_currentValue().ToString() + " °C"; } Beacon.Checked = (m.get_beacon() == YModule.BEACON_ON); } }
// poll temperature function for all gauges and // update UI acordingly private void refreshUI() { for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); if (d.Enabled) { if (d.SelectedIndex >= 0) { MyTemperature mt = (MyTemperature)d.Items[d.SelectedIndex]; YTemperature t = mt.getYTemperature(); gauges[j].setValue(t.get_currentValue()); } } gauges[j].refresh(); } }
// Use this for initialization void Start () { string version; if (IntPtr.Size == 4) { version = "Unity: 32 bits"; } else { version = "Unity: 64 bits"; } version += " / Yoctopuce:" + YAPI.GetAPIVersion (); versionText.text = version; string msg = ""; if (YAPI.RegisterHub ("usb", ref msg) != YAPI.SUCCESS) { state = State.ERROR; errmsg = msg; return; } YModule module = YModule.FirstModule (); while (module!=null) { string product = module.get_productName (); string serial = module.get_serialNumber (); if (product == "Yocto-Meteo") { meteoSerial = serial; temperatureSensor = YTemperature.FindTemperature (serial + ".temperature"); humiditySensor = YHumidity.FindHumidity (serial + ".humidity"); pressureSensor = YPressure.FindPressure (serial + ".pressure"); } else if (product == "Yocto-Color") { colorSerial = serial; led1 = YColorLed.FindColorLed (serial + ".colorLed1"); led2 = YColorLed.FindColorLed (serial + ".colorLed2"); } module = module.nextModule (); } if (meteoSerial == null) { errmsg = "No Yocto-Meteo detected"; state = State.ERROR; } else if (colorSerial == null) { errmsg = "No Yocto-color detected"; state = State.ERROR; } else { state = State.HOME; } }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YHumidity hsensor; YTemperature tsensor; YPressure psensor; if (Target.ToLower() == "any") { hsensor = YHumidity.FirstHumidity(); tsensor = YTemperature.FirstTemperature(); psensor = YPressure.FirstPressure(); if ((hsensor == null) || (tsensor == null) || (psensor == null)) { WriteLine("No module connected (check USB cable) "); return(-1); } } else { hsensor = YHumidity.FindHumidity(Target + ".humidity"); tsensor = YTemperature.FindTemperature(Target + ".temperature"); psensor = YPressure.FindPressure(Target + ".pressure"); } while (await hsensor.isOnline()) { WriteLine("Humidity: " + await hsensor.get_currentValue() + " %RH"); WriteLine("Temperature: " + await tsensor.get_currentValue() + " °C"); WriteLine("Pressure: " + await psensor.get_currentValue() + " hPa"); 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); 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); YTemperature tsensor; if (Target.ToLower() == "any") { tsensor = YTemperature.FirstTemperature(); if (tsensor == null) { WriteLine("No module connected (check USB cable) "); return(-1); } Target = await(await tsensor.get_module()).get_serialNumber(); } WriteLine("Using: " + Target); // retreive both channels YTemperature ch1 = YTemperature.FindTemperature(Target + ".temperature1"); YTemperature ch2 = YTemperature.FindTemperature(Target + ".temperature2"); while (await ch2.isOnline()) { Write("Ambiant: " + await ch1.get_currentValue() + " °C "); WriteLine("Infrared: " + await ch2.get_currentValue() + " °C "); 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); }
// called when a device is plugged public void deviceArrival(YModule m) { // new device arrived, lets check if any Ytemperature function are hosted int fctCount = m.functionCount(); YTemperature t; // list the functions availble on the device for (int i = 0; i < fctCount; i++) { string fname = m.functionId(i); if (fname.StartsWith("temperature")) { t = YTemperature.FindTemperature(m.get_serialNumber() + '.' + fname); // used in deviceRemoval t.set_userData(t.get_module().get_serialNumber()); // ok temperature found, lets add it to all gauges control dropdown for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); MyTemperature mt = new MyTemperature(t); d.Items.Add(mt); } } } // enable the dropdowns if not empty for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); if (!d.Enabled && d.Items.Count > 0) { if (j < d.Items.Count) { d.SelectedIndex = j; d.Enabled = true; } } } }
/** * <summary> * Retrieves a temperature sensor for a given identifier. * <para> * The identifier can be specified using several formats: * </para> * <para> * </para> * <para> * - FunctionLogicalName * </para> * <para> * - ModuleSerialNumber.FunctionIdentifier * </para> * <para> * - ModuleSerialNumber.FunctionLogicalName * </para> * <para> * - ModuleLogicalName.FunctionIdentifier * </para> * <para> * - ModuleLogicalName.FunctionLogicalName * </para> * <para> * </para> * <para> * This function does not require that the temperature sensor is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method <c>YTemperature.isOnline()</c> to test if the temperature sensor is * indeed online at a given time. In case of ambiguity when looking for * a temperature sensor by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * </para> * </summary> * <param name="func"> * a string that uniquely characterizes the temperature sensor * </param> * <returns> * a <c>YTemperature</c> object allowing you to drive the temperature sensor. * </returns> */ public static YTemperature FindTemperature(string func) { YTemperature obj; obj = (YTemperature) YFunction._FindFromCache("Temperature", func); if (obj == null) { obj = new YTemperature(func); YFunction._AddToCache("Temperature", func, obj); } return obj; }
public MyTemperature(YTemperature t) { _t = t; }
private void EventThreadProc() { while (!_stop) { IsRunning = true; // attente 30eme seconds DateTime dt = DateTime.Now; if (dt.Second < 15) { Thread.Sleep((15 - dt.Second) * 1000); } else { Thread.Sleep(((59 - dt.Second) + 15) * 1000); } dt = DateTime.Now; if (dt.Minute == 00) { _tempInfoClass = new tempInfo(); } _isTempReceive = false; if (myPT100Probe == null) { myPT100Probe = YTemperature.FirstTemperature(); } if ((myPT100Probe != null) && (myPT100Probe.isOnline())) { TempChamber = TempBottle = myPT100Probe.get_currentValue(); _isTempReceive = true; } if (_isTempReceive) { if (_tempInfoClass == null) { _tempInfoClass = new tempInfo(); } AddTemp(dt, TempBottle); } dt = DateTime.Now; if (dt.Minute == 59) { StoreTemp(); } if (dt.Second < 59) { Thread.Sleep(((59 - dt.Second) + 5) * 1000); } else { Thread.Sleep(5 * 1000); } } IsRunning = false; }
private void Timer_Tick(object sender, EventArgs eArgs) { ambiantTemp = double.MinValue; if (sender != Clock) { return; } if (!DisplayBadge) { if ((!CurrenRfidReader.IsConnected) || (bDoorJustClosed) || ((CurrenRfidReader.IsInScan) || (CurrenRfidReader.Door_Status == Door_Status.Door_Open))) { return; } if (bTempReady) { if (myPT100Probe == null) { myPT100Probe = YTemperature.FirstTemperature(); } if ((myPT100Probe != null) && (myPT100Probe.isOnline())) { ambiantTemp = myPT100Probe.get_currentValue(); } } if (ambiantTemp != double.MinValue) { WriteLCDLine(1, " - WAIT FOR USER -"); WriteLCDLine(2, " " + GetTime() + " - " + ambiantTemp.ToString("00.0") + "C"); } else { WriteLCDLine(1, " - WAIT FOR USER -"); WriteLCDLine(2, " " + GetTime()); } return; } else { Clock.Stop(); DisplayBadge = false; WriteLCDLine(1, " BADGE :"); WriteLCDLine(2, " " + StrBadgeRead); Thread.Sleep(100); if (!CurrenRfidReader.TCPActionPending) { LogToFile.LogMessageToFile("Before check badge in timer"); if (CheckBadge(StrBadgeRead)) { LogToFile.LogMessageToFile("Badge Checked in timer"); OnBadgeReader(StrBadgeRead); badgeset = true; LogToFile.LogMessageToFile("Unlock DOOR event in timer"); OpenDoor(); if (BadgeEvent != null) { BadgeEvent.Set(); LogToFile.LogMessageToFile("Badge event SET in timer"); } } else { LogToFile.LogMessageToFile("Badge not granted"); WriteLCDLine(1, " BADGE :"); WriteLCDLine(2, " BADGE NOT GRANTED!"); Clock.Start(); //Enable TCP Scan CurrenRfidReader.UserActionPending = false; } } else { LogToFile.LogMessageToFile("TCP action pending"); WriteLCDLine(1, " INFO :"); WriteLCDLine(2, " NETWORK QUERY"); Clock.Start(); //Enable TCP Scan CurrenRfidReader.UserActionPending = false; } } }
// --- (end of YTemperature implementation) // --- (Temperature functions) /** * <summary> * Retrieves a temperature sensor for a given identifier. * <para> * The identifier can be specified using several formats: * </para> * <para> * </para> * <para> * - FunctionLogicalName * </para> * <para> * - ModuleSerialNumber.FunctionIdentifier * </para> * <para> * - ModuleSerialNumber.FunctionLogicalName * </para> * <para> * - ModuleLogicalName.FunctionIdentifier * </para> * <para> * - ModuleLogicalName.FunctionLogicalName * </para> * <para> * </para> * <para> * This function does not require that the temperature sensor is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method <c>YTemperature.isOnline()</c> to test if the temperature sensor is * indeed online at a given time. In case of ambiguity when looking for * a temperature sensor by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * </para> * </summary> * <param name="func"> * a string that uniquely characterizes the temperature sensor * </param> * <returns> * a <c>YTemperature</c> object allowing you to drive the temperature sensor. * </returns> */ public static YTemperature FindTemperature(string func) { YTemperature res; if (_TemperatureCache.ContainsKey(func)) return (YTemperature)_TemperatureCache[func]; res = new YTemperature(func); _TemperatureCache.Add(func, res); return res; }
static void Main(string[] args) { string errmsg = ""; string target; int power; YMotor motor; YCurrent current; YVoltage voltage; YTemperature temperature; // parse the command line if (args.Length < 2) { usage(); } target = args[0].ToUpper(); power = Convert.ToInt32(args[1]); if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { // find the serial# of the first available motor motor = YMotor.FirstMotor(); if (motor == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } target = motor.get_module().get_serialNumber(); } motor = YMotor.FindMotor(target + ".motor"); current = YCurrent.FindCurrent(target + ".current"); voltage = YVoltage.FindVoltage(target + ".voltage"); temperature = YTemperature.FindTemperature(target + ".temperature"); // lets start the motor if (motor.isOnline()) { // if motor is in error state, reset it. if (motor.get_motorStatus() >= YMotor.MOTORSTATUS_LOVOLT) { motor.resetStatus(); } motor.drivingForceMove(power, 2000); // ramp up to power in 2 seconds while (motor.isOnline()) { // display motor status Console.WriteLine("Status=" + motor.get_advertisedValue() + " " + "Voltage=" + voltage.get_currentValue() + "V " + "Current=" + current.get_currentValue() / 1000 + "A " + "Temp=" + temperature.get_currentValue() + "deg C"); YAPI.Sleep(1000, ref errmsg); // wait for one second } } YAPI.FreeAPI(); }
// perform the initial setup that may be done without a YoctoAPI object (hwd can be null) internal override void base_init(YFunction hwd, string instantiationName) { _func = (YTemperature)hwd; base.base_init(hwd, instantiationName); }
//--- (end of YTemperature definitions) //--- (YTemperature implementation) internal YTemperatureProxy(YTemperature hwd, string instantiationName) : base(hwd, instantiationName) { InternalStuff.log("Temperature " + instantiationName + " instantiation"); base_init(hwd, instantiationName); }