public override async Task <int> Run() { try { YModule m; await YAPI.RegisterHub(HubURL); m = YModule.FindModule(Target); // use serial or logical name if (await m.isOnline()) { if (!YAPI.CheckLogicalName(LogicalName)) { WriteLine("Invalid name (" + LogicalName + ")"); return(-1); } await m.set_logicalName(LogicalName); await m.saveToFlash(); // do not forget this Write("Module: serial= " + await m.get_serialNumber()); WriteLine(" / name= " + await m.get_logicalName()); } else { Write("not connected (check identification and USB cable"); } } catch (YAPI_Exception ex) { WriteLine("RegisterHub error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
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); }
static void Main(string[] args) { string errmsg = ""; // configure the API to contact any networked device if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (YAPI.RegisterHub("net", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } // each time a new device is connected/discovered // arrivalCallback will be called. YAPI.RegisterDeviceArrivalCallback(arrivalCallback); // each time a device is disconnected/removed // removalCallback will be called. YAPI.RegisterDeviceRemovalCallback(removalCallback); Console.WriteLine("Waiting for hubs to signal themselves..."); while (true) { YAPI.UpdateDeviceList(ref errmsg); YAPI.Sleep(1000, ref errmsg); showNetwork(); } }
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 :)"); }
static void Main(string[] args) { string errmsg = ""; string target; YSerialPort serialPort; if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (args.Length > 0 && args[0] != "any") { target = args[0]; serialPort = YSerialPort.FindSerialPort(target + ".serialPort"); if (!serialPort.isOnline()) { Console.WriteLine("No module connected (check cable)"); Environment.Exit(0); } } else { serialPort = YSerialPort.FirstSerialPort(); if (serialPort == null) { Console.WriteLine("No module connected (check USB cable)"); Environment.Exit(0); } } Console.WriteLine("****************************"); Console.WriteLine("* make sure voltage levels *"); Console.WriteLine("* are properly configured *"); Console.WriteLine("****************************"); serialPort.set_serialMode("9600,8N1"); serialPort.set_protocol("Line"); serialPort.reset(); string line; do { YAPI.Sleep(500, ref errmsg); do { line = serialPort.readLine(); if (line != "") { Console.WriteLine("Received: " + line); } } while (line != ""); Console.WriteLine("Type line to send, or Ctrl-C to exit: "); line = Console.ReadLine(); serialPort.writeLine(line); } while (line != ""); YAPI.FreeAPI(); }
/// <summary>Calls RegisterHub. Doesn't call again once it has succeeded once (although Yocto doesn't seem to mind). Returns true on success (or previous success) /// throwException is used if it fails - if false MessageBox.Show, if true throws exception. There is no silent failure option</summary> public static bool RegisterYocto(bool throwException) { if (g_RegisteredOK) { return(true); } string error = ""; int result = YAPI.RegisterHub("usb", ref error); if (result == YAPI.SUCCESS) { error = null; // leave field as null for OK (maybe Yocto returns an OK or something in the error) } if (error != null) { if (throwException) { throw new UserException(error); } MessageBox.Show(error); return(false); } g_RegisteredOK = true; return(true); }
public MedicalCabinet(RfidReader currenRfidReader, string strPortBadgeAndLCD, bool isSchroff = false) : base(currenRfidReader, strPortBadgeAndLCD) { EventThread = new Thread(EventThreadProc) { Name = "SmartCabinet event", IsBackground = true }; EventThread.Start(); if (currenRfidReader.HardwareVersion.StartsWith("13")) { this._isSchroff = true; Rs232Display = new Rs232Module("COM2"); InitLCD(); HideCursor(); if (YAPI.RegisterHub("usb", ref errmsg) == YAPI.SUCCESS) { bTempReady = true; } else { ErrorMessage.ExceptionMessageBox.Show("error init YAPI", null); } } Clock.Interval = 1000; Clock.Elapsed += Timer_Tick; Clock.Start(); }
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é."); } }
public TempFridgeThreadPT100() { if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { ErrorMessage.ExceptionMessageBox.Show("Unable to register PT100 Module :" + errmsg, "Information"); } }
private async void Button_Click(object sender, RoutedEventArgs e) { if (!started) { string url = this.url.Text; try { YAPI.RegisterLogFunction(yoctoLog); await YAPI.RegisterHub(url); YAPI.RegisterDeviceArrivalCallback(deviceArrival); YAPI.RegisterDeviceRemovalCallback(deviceRemoval); } catch (YAPI_Exception ex) { Output.Text = "Error:" + ex.Message + "\n"; return; } timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 100); // 100 Milliseconds timer.Tick += new EventHandler <object>(Each_Tick); timer.Start(); initButton.Content = "Stop"; started = true; } else { timer.Stop(); YAPI.FreeAPI(); initButton.Content = "Start"; started = false; } }
static void Main(string[] args) { string errmsg = ""; string target; YVoltage sensor; YVoltage sensorDC = null; YVoltage sensorAC = null; YModule m = null; 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") { // retreive any voltage sensor (can be AC or DC) sensor = YVoltage.FirstVoltage(); if (sensor == null) { die("No module connected"); } } else { sensor = YVoltage.FindVoltage(target + ".voltage1"); } // we need to retreive both DC and AC voltage from the device. if (sensor.isOnline()) { m = sensor.get_module(); sensorDC = YVoltage.FindVoltage(m.get_serialNumber() + ".voltage1"); sensorAC = YVoltage.FindVoltage(m.get_serialNumber() + ".voltage2"); } else { die("Module not connected"); } while (m.isOnline()) { Console.Write("DC: " + sensorDC.get_currentValue().ToString() + " v "); Console.Write("AC: " + sensorAC.get_currentValue().ToString() + " v "); Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); }
static void Main(string[] args) { string errmsg = ""; string target; YGenericSensor 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 = YGenericSensor.FirstGenericSensor(); if (sensor == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } Console.WriteLine("Using: " + sensor.get_module().get_serialNumber()); } else { sensor = YGenericSensor.FindGenericSensor(target + ".genericSensor1"); } // retreive module serial string serial = sensor.get_module().get_serialNumber(); // retreive both channels YGenericSensor ch1 = YGenericSensor.FindGenericSensor(serial + ".genericSensor1"); string unitSensor1 = ""; if (ch1.isOnline()) { unitSensor1 = ch1.get_unit(); } while (ch1.isOnline()) { Console.Write("Value: " + ch1.get_currentValue().ToString() + unitSensor1); Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); }
static void Main(string[] args) { string errmsg = ""; string target; YCurrentLoopOutput loop; double value; if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (args.Length < 2) { usage(); } target = args[0].ToUpper(); value = Convert.ToDouble(args[1]); if (target == "ANY") { loop = YCurrentLoopOutput.FirstCurrentLoopOutput(); if (loop == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } } else { loop = YCurrentLoopOutput.FindCurrentLoopOutput(target + ".currentLoopOutput"); } if (loop.isOnline()) { loop.set_current(value); int loopPower = loop.get_loopPower(); if (loopPower == YCurrentLoopOutput.LOOPPOWER_NOPWR) { Console.WriteLine("Current loop not powered"); Environment.Exit(0); } if (loopPower == YCurrentLoopOutput.LOOPPOWER_LOWPWR) { Console.WriteLine("Insufficient voltage on current loop"); Environment.Exit(0); } Console.WriteLine("current loop set to " + value.ToString() + " mA"); } else { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); } YAPI.FreeAPI(); }
static void Main(string[] args) { string errmsg = ""; string target; YWeighScale 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 = YWeighScale.FirstWeighScale(); if (sensor == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } Console.WriteLine("Using: " + sensor.get_module().get_serialNumber()); } else { sensor = YWeighScale.FindWeighScale(target + ".weighScale1"); } if (sensor.isOnline()) { string unit = ""; // On startup, enable excitation and tare weigh scale Console.WriteLine("Resetting tare weight..."); sensor.set_excitation(YWeighScale.EXCITATION_AC); YAPI.Sleep(3000, ref errmsg); sensor.tare(); unit = sensor.get_unit(); // Show measured weight continuously while (sensor.isOnline()) { Console.Write("Weight : " + sensor.get_currentValue().ToString() + unit); Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } } YAPI.FreeAPI(); Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); }
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); YSerialPort serialPort; if (Target.ToLower() == "any") { serialPort = YSerialPort.FirstSerialPort(); if (serialPort == null) { WriteLine("No module connected (check USB cable) "); return(-1); } YModule ymod = await serialPort.get_module(); WriteLine("Using: " + await ymod.get_serialNumber()); } else { serialPort = YSerialPort.FindSerialPort(Target + ".serialPort"); } await serialPort.set_serialMode("9600,8N1"); await serialPort.set_protocol("Line"); await serialPort.reset(); string line; do { if (ToSend != "") { await serialPort.writeLine(ToSend); ToSend = ""; } await YAPI.Sleep(500); do { line = await serialPort.readLine(); if (line != "") { WriteLine("Received: " + line); } } while (line != ""); } while (line != ""); } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
static void Main(string[] args) { string errmsg = ""; string target; YGps gps; 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") { gps = YGps.FirstGps(); if (gps == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } } else { gps = YGps.FindGps(target + ".gps"); } if (!gps.isOnline()) { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); Environment.Exit(0); } while (gps.isOnline()) { if (gps.get_isFixed() != YGps.ISFIXED_TRUE) { Console.WriteLine("fixing... "); } else { Console.WriteLine(gps.get_latitude() + " " + gps.get_longitude()); } Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); }
static void Main(string[] args) { Console.WriteLine("Console dotNET Application 0.1.0"); Console.WriteLine("--------------------------------"); Console.WriteLine(""); Console.WriteLine("Using Yoctopuce lib " + YAPI.GetAPIVersion()); string errsmg = ""; if (YAPI.RegisterHub("usb", ref errsmg) != YAPI.SUCCESS) { Console.WriteLine("Unable to register the USB port :" + errsmg); return; } YSensor sensor = YSensor.FirstSensor(); if (sensor == null) { Console.WriteLine("No Yoctopuce sensor find on USB."); return; } YDisplay display = YDisplay.FirstDisplay(); if (display == null) { Console.WriteLine("No Yoctopuce display find on USB."); return; } // display clean up display.resetAll(); YDisplayLayer l1 = display.get_displayLayer(1); l1.hide(); // L1 is hidden, l2 stay visible int w = display.get_displayWidth(); int h = display.get_displayHeight(); while (sensor.isOnline() && display.isOnline()) { string value = sensor.get_currentValue() + " " + sensor.get_unit(); string name = sensor.get_friendlyName(); // display a text in the middle of the screen l1.clear(); l1.selectFont("Large.yfm"); l1.drawText(w / 2, h / 2, YDisplayLayer.ALIGN.CENTER, value); l1.selectFont("Small.yfm"); l1.drawText(w - 1, h - 1, YDisplayLayer.ALIGN.BOTTOM_RIGHT, name); display.swapLayerContent(0, 1); Console.WriteLine(name + " ->" + value); YAPI.Sleep(500, ref errsmg); } 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); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YPwmOutput pwmoutput1; YPwmOutput pwmoutput2; int frequency; double dutyCycle; frequency = Convert.ToInt32(RequestedFrequency); dutyCycle = Convert.ToDouble(RequestedDutyCycle); if (Target.ToLower() == "any") { pwmoutput1 = YPwmOutput.FirstPwmOutput(); if (pwmoutput1 == null) { WriteLine("No module connected (check USB cable) "); return(-1); } Target = await(await pwmoutput1.get_module()).get_serialNumber(); } pwmoutput1 = YPwmOutput.FindPwmOutput(Target + ".pwmOutput1"); pwmoutput2 = YPwmOutput.FindPwmOutput(Target + ".pwmOutput2"); if (await pwmoutput1.isOnline()) { // output 1 : immediate change await pwmoutput1.set_frequency(frequency); await pwmoutput1.set_enabled(YPwmOutput.ENABLED_TRUE); await pwmoutput1.set_dutyCycle(dutyCycle); // output 2 : smooth change await pwmoutput2.set_frequency(frequency); await pwmoutput2.set_enabled(YPwmOutput.ENABLED_TRUE); await pwmoutput2.dutyCycleMove(dutyCycle, 3000); WriteLine("done"); } else { WriteLine("Module not connected (check identification and USB cable)"); } } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
static void Main(string[] args) { string errmsg = ""; string target; YWatchdog watchdog; string state; if (args.Length < 2) { usage(); } target = args[0].ToUpper(); state = args[1].ToUpper(); if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { watchdog = YWatchdog.FirstWatchdog(); if (watchdog == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } } else { watchdog = YWatchdog.FindWatchdog(target + ".watchdog1"); } if (watchdog.isOnline()) { if (state == "ON") { watchdog.set_running(YWatchdog.RUNNING_ON); } if (state == "OFF") { watchdog.set_running(YWatchdog.RUNNING_OFF); } if (state == "RESET") { watchdog.resetWatchdog(); } } else { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); } YAPI.FreeAPI(); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YGenericSensor tsensor; if (Target.ToLower() == "any") { tsensor = YGenericSensor.FirstGenericSensor(); if (tsensor == null) { WriteLine("No module connected (check USB cable) "); return(-1); } YModule m = await tsensor.get_module(); Target = await m.get_serialNumber(); } // retreive module serial WriteLine("Using: " + Target); // retreive both channels YGenericSensor ch1, ch2; ch1 = YGenericSensor.FindGenericSensor(Target + ".genericSensor1"); ch2 = YGenericSensor.FindGenericSensor(Target + ".genericSensor2"); string unitSensor1 = "", unitSensor2 = ""; if (await ch1.isOnline()) { unitSensor1 = await ch1.get_unit(); } if (await ch2.isOnline()) { unitSensor2 = await ch2.get_unit(); } while (await ch1.isOnline() && await ch2.isOnline()) { Write("Channel 1 : " + await ch1.get_currentValue() + unitSensor1); Write(" Channel 2 : " + await ch2.get_currentValue() + unitSensor2); WriteLine(" (press Ctrl-C to exit)"); 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 static bool RegisterHub() { String errorMessage = null; if (YAPI.RegisterHub("usb", ref errorMessage) != YAPI.SUCCESS) { throw new Exception("Could not register hub: " + errorMessage); } return(true); }
static void Main(string[] args) { string errmsg = ""; string target; YPwmOutput pwmoutput1; YPwmOutput pwmoutput2; int frequency; double dutyCycle; if (args.Length < 3) { usage(); } target = args[0].ToUpper(); frequency = Convert.ToInt32(args[1]); dutyCycle = Convert.ToDouble(args[2]); if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { pwmoutput1 = YPwmOutput.FirstPwmOutput(); if (pwmoutput1 == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } target = pwmoutput1.get_module().get_serialNumber(); } pwmoutput1 = YPwmOutput.FindPwmOutput(target + ".pwmOutput1"); pwmoutput2 = YPwmOutput.FindPwmOutput(target + ".pwmOutput2"); if (pwmoutput1.isOnline()) { // output 1 : immediate change pwmoutput1.set_frequency(frequency); pwmoutput1.set_enabled(YPwmOutput.ENABLED_TRUE); pwmoutput1.set_dutyCycle(dutyCycle); // output 2 : smooth change pwmoutput2.set_frequency(frequency); pwmoutput2.set_enabled(YPwmOutput.ENABLED_TRUE); pwmoutput2.dutyCycleMove(dutyCycle, 3000); } else { Console.WriteLine("Module not connected"); Console.WriteLine("check identification and USB cable"); } YAPI.FreeAPI(); }
static void Main(string[] args) { int i; List <string> hubs = new List <string>(); List <string> shield = new List <string>(); List <string> devices = new List <string>(); string errmsg = ""; if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error : " + errmsg); Environment.Exit(0); } for (i = 0; i < args.Length; i++) { Console.WriteLine("Update module connected to hub " + args[i]); if (YAPI.RegisterHub(args[i], ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(1); } } //fist step construct the list of all hub /shield and devices connected YModule module = YModule.FirstModule(); while (module != null) { string product = module.get_productName(); string serial = module.get_serialNumber(); if (product == "YoctoHub-Shield") { shield.Add(serial); } else if (product.StartsWith("YoctoHub")) { hubs.Add(serial); } else if (product != "VirtualHub") { devices.Add(serial); } module = module.nextModule(); } // fist upgrades all Hubs... upgradeSerialList(hubs); // ... then all shield.. upgradeSerialList(shield); // ... and finaly all devices upgradeSerialList(devices); Console.WriteLine("All devices are now up to date"); 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 override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YAnButton input1; YAnButton input5; if (Target.ToLower() == "any") { input1 = YAnButton.FirstAnButton(); if (input1 == null) { WriteLine("No module connected (check USB cable) "); return(-1); } Target = await(await input1.get_module()).get_serialNumber(); } input1 = YAnButton.FindAnButton(Target + ".anButton1"); input5 = YAnButton.FindAnButton(Target + ".anButton5"); while (await input1.isOnline()) { if (await input1.get_isPressed() == YAnButton.ISPRESSED_TRUE) { Write("Button 1: pressed "); } else { Write("Button 1: not pressed "); } WriteLine("- analog value: " + await input1.get_calibratedValue()); if (await input5.get_isPressed() == YAnButton.ISPRESSED_TRUE) { Write("Button 5: pressed "); } else { Write("Button 5: not pressed "); } WriteLine("- analog value: " + await input5.get_calibratedValue()); 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); YColorLed led1; int color; ColorStr = ColorStr.ToUpper(); if (ColorStr == "RED") { color = 0xFF0000; } else if (ColorStr == "GREEN") { color = 0x00FF00; } else if (ColorStr == "BLUE") { color = 0x0000FF; } else { color = Convert.ToInt32("0x" + ColorStr, 16); } if (Target.ToLower() == "any") { led1 = YColorLed.FirstColorLed(); if (led1 == null) { WriteLine("No module connected (check USB cable) "); return(-1); } } else { led1 = YColorLed.FindColorLed(Target + ".colorLed1"); } if (await led1.isOnline()) { WriteLine("smooth transition to " + color.ToString("x")); await led1.rgbMove(color, 1000); } else { WriteLine("Module not connected (check identification and USB cable)"); } } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
static void Main(string[] args) { YModule m; string errmsg = ""; if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (args.Length < 1) { usage(); } m = YModule.FindModule(args[0]); // use serial or logical name if (m.isOnline()) { if (args.Length >= 2) { if (args[1].ToUpper() == "ON") { m.set_beacon(YModule.BEACON_ON); } if (args[1].ToUpper() == "OFF") { m.set_beacon(YModule.BEACON_OFF); } } Console.WriteLine("serial: " + m.get_serialNumber()); Console.WriteLine("logical name: " + m.get_logicalName()); Console.WriteLine("luminosity: " + m.get_luminosity().ToString()); Console.Write("beacon: "); if (m.get_beacon() == YModule.BEACON_ON) { Console.WriteLine("ON"); } else { Console.WriteLine("OFF"); } Console.WriteLine("upTime: " + (m.get_upTime() / 1000).ToString() + " sec"); Console.WriteLine("USB current: " + m.get_usbCurrent().ToString() + " mA"); Console.WriteLine("Logs:\r\n" + m.get_lastLogs()); } else { Console.WriteLine(args[0] + " not connected (check identification and USB cable)"); } YAPI.FreeAPI(); }
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(); }