/// <summary> /// Open connection to Plathosys device /// </summary> private void OpenPlathosys() { // choose specific USB ID or 0 for first Device found int vendorID = 0; int productID = 0; // Stringbuilder instances to store DeviceName and SerialNumber with max. 200 characters StringBuilder deviceName = new StringBuilder(200); StringBuilder serialNumber = new StringBuilder(200); try { if (Plathosys.Opendevice(vendorID, productID, out int selectedVendorID, out int selectedProductID, deviceName, serialNumber) == false) { throw new Exception("No Plathosys device detected!"); } } catch (DllNotFoundException ex) { _timerInitPlathosys.Change(Timeout.Infinite, Timeout.Infinite); MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }
/// <summary> /// Opens connection to Plathosys device and /// initialize it to get correct hook status /// </summary> /// <param name="sender"></param> private void TimerInitPlathosys_Tick(object sender) { try { OpenPlathosys(); // If initializing the Plathosys device to get correct hook status // and turning off all accessories is successful if (InitPlathosys() && Plathosys.SetHeadsetActive(false) && Plathosys.SetByListening(false) && Plathosys.SetHeadsetEar(2)) { // Stop this timmer _timerInitPlathosys.Change(Timeout.Infinite, Timeout.Infinite); // Start timer to monitor hook status _timerHook.Change(10, 100); _deviceWorking = true; // Raise PlathosysDeviceRead Event OnPlathosysDeviceReady(); } } catch (Exception) { // Try again in one second } }
/// <summary> /// Reset and try to reconnet to Plathosys device /// </summary> private void ReconnectDevice() { _timerHook.Change(Timeout.Infinite, Timeout.Infinite); _deviceWorking = false; OnNoDeviceFound(); Plathosys.Closedevice(); _timerInitPlathosys.Change(10, 1000); }
/// <summary> /// Set speaker port to given state /// </summary> /// <param name="activate">true for on an false for off</param> public void SetSpeaker(bool activate) { if (_deviceWorking == false) { throw new Exception("No Plathosys device detected!"); } if (Plathosys.SetByListening(activate) == false) { ReconnectDevice(); throw new Exception("Setting speaker port failed! Please check if Plathosys device is attached and try again."); } }
/// <summary> /// Set training function to given state /// </summary> /// <param name="activate">true for on and false for off</param> public void SetTraining(bool activate) { if (_deviceWorking == false) { throw new Exception("No Plathosys device detected!"); } if ((Plathosys.SetHeadsetActive(false) && Plathosys.SetHeadsetEar((activate) ? 1 : 2)) == false) { ReconnectDevice(); throw new Exception("Setting training function failed! Please check if Plathosys device is attached and try again."); } }
/// <summary> /// Set headset port to given state /// </summary> /// <param name="activate">true for on an false for off</param> public void SetHeadset(bool activate) { if (_deviceWorking == false) { throw new Exception("No Plathosys device detected!"); } if ((Plathosys.SetHeadsetEar(2) && Plathosys.SetHeadsetActive(activate) == false)) { ReconnectDevice(); throw new Exception("Setting headset port failed! Please check if Plathosys device is attached and try again."); } }
/// <summary> /// Read hook info /// </summary> /// <param name="hookOff"></param> /// <returns>succesful?</returns> private bool ReadHookPlathosys(out bool hookOff) { int hookAndPttInfo; try { // If reading the hook info succeeds if (Plathosys.ReadHookAndPTT(out hookAndPttInfo)) { hookOff = ((hookAndPttInfo & 1) == 1) ? true : false; return(true); } } catch { Plathosys.Closedevice(); } hookOff = false; return(false); }