public Duel_Mode() //contructor that is called when class is intantiated { try { cwObj = CwUSB.FCWInitObject(); int devCount = CwUSB.FCWOpenCleware(cwObj); // Please note that OpenCleware should be called only once in the // initialisation of your programm, not every time a function is called Console.WriteLine("Found " + devCount + " Cleware devices"); int devType = CwUSB.FCWGetUSBType(cwObj, 0); Console.WriteLine(devType); if (devType == (int)CwUSB.USBtype_enum.SWITCH1_DEVICE) { //CwUSB.FCWSetLED(cwObj, 8, (int)CwUSB.LED_IDs.LED_1, 1); int state = CwUSB.FCWGetSwitch(cwObj, 0, (int)CwUSB.SWITCH_IDs.SWITCH_1); // for debugging Console.WriteLine(state); //0 is off, 1 is on and -1 is a failure } if (devCount < 1) { MessageBox.Show("No device connected!"); Environment.Exit(1); } } catch (Exception e) { MessageBox.Show(e.Message); Environment.Exit(1); } }
public async Task CloseConnection() { await Task.Run(() => { int devCount = CwUSB.FCWOpenCleware(cwObj); if (devCount >= 1) { CwUSB.FCWCloseCleware(cwObj); CwUSB.FCWUnInitObject(cwObj); } }); }
public async Task <string> ResetMode() { await Task.Run(() => { int devCount = CwUSB.FCWOpenCleware(cwObj); if (devCount >= 1) { CwUSB.FCWSetSwitch(cwObj, 0, (int)CwUSB.SWITCH_IDs.SWITCH_0, 0); CwUSB.FCWSetSwitch(cwObj, 0, (int)CwUSB.SWITCH_IDs.SWITCH_1, 0); CwUSB.FCWSetSwitch(cwObj, 0, (int)CwUSB.SWITCH_IDs.SWITCH_2, 0); } }); return("reset done"); }