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 = ""; constants.init(args); if (constants.CheckMonoVersion(out errmsg)) { int res = YAPI.FILE_NOT_FOUND; res = YAPI.InitAPI(0, ref errmsg); YAPI.RegisterLogFunction(LogManager.APIlog); if (res == YAPI.SUCCESS) { YAPI.SetDeviceListValidity(3600); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (Debugger.IsAttached) { Application.Run(new StartForm(true)); } else { try { Application.Run(new StartForm(false)); } catch (OutOfMemoryException) { string msg = ("Yocto-Visualization ran out of memory"); Console.Write(msg, "Oops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); MessageBox.Show(msg); } }
static void Main(String[] args) { constants.init(args); string errsmg = ""; YAPI.RegisterLogFunction(LogManager.APIlog); if (YAPI.InitAPI(YAPI.DETECT_NONE, ref errsmg) == YAPI.SUCCESS) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } else { MessageBox.Show("Yoctopuce API init error:" + errsmg); } }
public Form1() { string errmsg = ""; InitializeComponent(); card_exp.Text = ""; card_extra.Text = ""; // Setup Yoctopuce API YAPI.DisableExceptions(); if (DEBUG) { YAPI.RegisterLogFunction(this.Log); } if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Log("Cannot connect to USB devices:"); Log(errmsg); } YAPI.RegisterDeviceArrivalCallback(this.ArrivalCallback); }
static void Main(string[] args) { string errmsg = ""; YAPI.RegisterLogFunction(log); if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error : " + errmsg); Environment.Exit(0); } YAPI.RegisterDeviceArrivalCallback(deviceArrival); YAPI.RegisterDeviceRemovalCallback(deviceRemoval); Console.WriteLine("Hit Ctrl-C to Stop "); while (true) { YAPI.UpdateDeviceList(ref errmsg); // traps plug/unplug events YAPI.Sleep(500, ref errmsg); // traps others events } }
public static bool initYoctopuceLibrary(ref string errmsg, bool silent) { if (LibraryAPIInitialized) { return(true); } log(".NET Proxy library initialization"); apiMutex.WaitOne(); LibraryAPIInitialized = YAPI.InitAPI(YAPI.DETECT_NONE, ref errmsg) == YAPI.SUCCESS; YAPI.RegisterLogFunction(apilog); apiMutex.ReleaseMutex(); if (!silent) { string msg = "Yoctopuce low-level API initialization failed (" + errmsg + ")"; throw new YoctoApiProxyException(msg); } if (LibraryAPIInitialized) { //InternalStuff.log("registering arrival/removal"); YAPI.RegisterDeviceArrivalCallback(YFunctionProxy.deviceArrival); YAPI.RegisterDeviceRemovalCallback(YFunctionProxy.deviceRemoval); } new Thread(() => { Thread.CurrentThread.IsBackground = true; InternalStuff.log("Starting inner processing thread..."); string err = ""; while (!InnerThreadMustStop) { //InternalStuff.log("YAPI processing..."); try { if (LibraryAPIInitialized) { YAPI.UpdateDeviceList(ref err); } } catch (Exception e) { InternalStuff.log("YUpdateDeviceList error !!(" + e.Message + ")"); } for (int i = 0; i < 20 & !InnerThreadMustStop; i++) { try { if (LibraryAPIInitialized) { YAPI.Sleep(100, ref err); } } catch (Exception e) { InternalStuff.log("YSleep error (" + e.Message + ")"); } } } InternalStuff.log("Stopping inner processing thread..."); InnerThreadMustStop = false; }).Start(); return(LibraryAPIInitialized); }
public static bool initYoctopuceLibrary(ref string errmsg, bool silent) { if (LibraryAPIInitialized) { return(true); } log(".NET Proxy library initialization"); apiMutex.WaitOne(); YAPI.RegisterLogFunction(apilog); LibraryAPIInitialized = YAPI.InitAPI(YAPI.DETECT_NONE, ref errmsg) == YAPI.SUCCESS; apiMutex.ReleaseMutex(); if (LibraryAPIInitialized) { InternalStuff.log("yapi.dll version is " + YoctoProxyManager.DllVersion); InternalStuff.log("yapi.dll file is " + YAPI.GetYAPIDllPath()); InternalStuff.log("yapi.dll architecture is " + YoctoProxyManager.DllArchitecture); } if (!silent) { string msg = "Yoctopuce low-level API initialization failed (" + errmsg + ")"; throw new YoctoApiProxyException(msg); } if (LibraryAPIInitialized) { //InternalStuff.log("registering arrival/removal"); YAPI.RegisterDeviceArrivalCallback(YFunctionProxy.deviceArrival); YAPI.RegisterDeviceRemovalCallback(YFunctionProxy.deviceRemoval); new Thread(() => { Thread.CurrentThread.IsBackground = true; InternalStuff.log("Starting inner processing thread..."); bool aborting = false; string err = ""; while (!InnerThreadMustStop && !aborting) { //InternalStuff.log("YAPI processing..."); try { if (LibraryAPIInitialized) { YAPI.UpdateDeviceList(ref err); } } catch (System.Threading.ThreadAbortException) { InternalStuff.log("Inner processing thead is aborting during UpdateDeviceList!"); aborting = true; YAPI.FreeAPI(); LibraryAPIInitialized = false; InternalStuff.log("API has been freed in a hurry"); } catch (Exception e) { InternalStuff.log("YUpdateDeviceList error !!(" + e.Message + ")"); } for (int i = 0; i < 20 & !InnerThreadMustStop & !aborting; i++) { try { if (LibraryAPIInitialized) { YAPI.Sleep(100, ref err); } } catch (System.Threading.ThreadAbortException) { InternalStuff.log("Inner processing thead is aborting during ysleep!"); aborting = true; YAPI.FreeAPI(); LibraryAPIInitialized = false; InternalStuff.log("API has been freed in a hurry"); } } catch (Exception e) { InternalStuff.log("YSleep error (" + e.GetType().ToString() + " " + e.Message + ")! "); } } InternalStuff.log("Stopping inner processing thread..."); InnerThreadMustStop = false; }).Start();