Example #1
0
        /// <summary>
        /// Enumerates all Xkeys devices currently connected.
        /// </summary>
        /// <returns>Returns the number of devices found.</returns>
        public static int EnumerateDevices()
        {
            deviceIndices = new int[INT_MaxDevices];

            foundDevices = PIEDevice.EnumeratePIE();
            if (foundDevices.Length == 0)
            {
                return(0);
            }

            validDevicesFound = 0;
            for (int i = 0; i < foundDevices.Length; i++)
            {
                if (foundDevices[i].HidUsagePage == 0xc)
                {
                    switch (foundDevices[i].Pid)
                    {
                    case INT_XKeysProfessionalID:
                        deviceIndices[validDevicesFound] = i;
                        validDevicesFound++;
                        foundDevices[i].SetupInterface();
                        break;

                    default:
                        // Unknown Device...
                        break;
                    }
                }
            }

            return(validDevicesFound);
        }
Example #2
0
        private IEnumerable <PIEDevice> ScanForBackingDevices()
        {
            var result = PIEDevice.EnumeratePIE()
                         .Where(x => x.HidUsagePage == 0xc);

            return(result);
        }
Example #3
0
        private void BtnEnumerate_Click(object sender, EventArgs e)
        {
            CboDevices.Items.Clear();
            cbotodevice = new int[128]; //128=max # of devices
            //enumerate and setupinterfaces for all devices
            devices = PIEDevice.EnumeratePIE();
            if (devices.Length == 0)
            {
                toolStripStatusLabel1.Text = "No Devices Found";
            }
            else
            {
                //System.Media.SystemSounds.Beep.Play();
                int cbocount = 0; //keeps track of how many valid devices were added to the CboDevice box
                for (int i = 0; i < devices.Length; i++)
                {
                    //information about device
                    //PID = devices[i].Pid);
                    //HID Usage = devices[i].HidUsage);
                    //HID Usage Page = devices[i].HidUsagePage);
                    //HID Version = devices[i].Version);
                    if (devices[i].HidUsagePage == 0xc)
                    {
                        switch (devices[i].Pid)
                        {
                        case 525:
                            CboDevices.Items.Add("PS2 Host Emulator (" + devices[i].Pid + "), ID: " + i);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;

                        case 514:
                            CboDevices.Items.Add("PS2 Host Emulator (" + devices[i].Pid + "), ID: " + i);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;

                        case 515:
                            CboDevices.Items.Add("PS2 Host Emulator (" + devices[i].Pid + "), ID: " + i);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;

                        default:
                            CboDevices.Items.Add("Unknown Device (" + devices[i].Pid + "), ID: " + i);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;
                        }
                        devices[i].SetupInterface();
                    }
                }
            }
            if (CboDevices.Items.Count > 0)
            {
                CboDevices.SelectedIndex = 0;
                selecteddevice           = cbotodevice[CboDevices.SelectedIndex];
                wData = new byte[devices[selecteddevice].WriteLength];//go ahead and setup for write
            }
        }
Example #4
0
 internal JoystickManager64()
 {
     if (Program.CurrentHost.Platform == HostPlatform.MicrosoftWindows)
     {
         devices = PIEDevice.EnumeratePIE();
     }
 }
        public void HandlePIEHidData(Byte[] _data, PIEDevice sourceDevice, int error)
        {
            //check the sourceDevice and make sure it is the same device as selected in CboDevice
            if (sourceDevice == devices[selecteddevice])
            {
                this._switch   = (byte)(_data[6]) == 8 ? true : false;
                this._buttonNr = 0;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[1] & 1));
                this._buttonNr = this._buttonNr | (long)((byte)(_data[2] & 1)) << 1;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[3] & 1)) << 2;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[4] & 1)) << 3;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[1] & 2)) << 3;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[2] & 2)) << 4;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[3] & 2)) << 5;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[4] & 2)) << 6;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[1] & 4)) << 6;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[2] & 4)) << 7;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[3] & 4)) << 8;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[4] & 4)) << 9;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[1] & 8)) << 9;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[2] & 8)) << 10;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[3] & 8)) << 11;
                this._buttonNr = this._buttonNr | (long)((byte)(_data[4] & 8)) << 12;

                XKeys_EventArgs args = new XKeys_EventArgs {
                    Data = _data, ButtonNr = this._buttonNr, Switch = this._switch
                };
                if (this._old_switch != this._switch)
                {
                    this.OnSwitch?.Invoke(this, args);
                }
                this.OnButton?.Invoke(this, args);
                this._old_switch = this._switch;
            }
        }
Example #6
0
 /// <summary>
 /// Tries to find a RailDriver and initialize it
 /// </summary>
 /// <param name="basePath"></param>
 public UserInputRailDriver(string basePath)
 {
     try
     {
         PIEDevice[] devices = PIEHidDotNet.PIEDevice.EnumeratePIE();
         for (int i = 0; i < devices.Length; i++)
         {
             if (devices[i].HidUsagePage == 0xc && devices[i].Pid == 210)
             {
                 Device = devices[i];
                 Device.SetupInterface();
                 Device.SetErrorCallback(this);
                 Device.SetDataCallback(this, DataCallbackFilterType.callOnChangedData);
                 WriteBuffer = new byte[Device.WriteLength];
                 State       = new RailDriverState();
                 SetLEDs(0x40, 0x40, 0x40);
                 ReadCalibrationData(basePath);
                 break;
             }
         }
     }
     catch (Exception error)
     {
         Device = null;
         Trace.WriteLine(error);
     }
 }
Example #7
0
 internal JoystickManager()
 {
     if (!Program.CurrentlyRunningOnWindows)
     {
         return;
     }
     devices = PIEDevice.EnumeratePIE();
 }
        public void HandlePIEHidError(int error, PIEDevice sourceDevices)
        {
            // Error 301 happens when the device is unplugged. We need a strategy for disconnecting and reconnecting.

            // Error 1001 occurs when an exception is thrown during the data changed handler (e.g., trying to access controls or control properties that otherwise must be accessed on the UI thread could throw this exception).

            //throw new NotImplementedException();
        }
Example #9
0
        public void HandlePIEHidError(int error, PIEDevice sourceDevice)
        {
            if (sourceDevice != BackingObject)
            {
                return;
            }

            HandleDeviceConnected(error != 301 && BackingObject.Connected);
        }
 public void SetActiveDevice(PIEDevice activeDevice)
 {
     this.activeDevice = activeDevice;
     if (activeDevice == null)
     {
         return;
     }
     activeDevice.SetDataCallback(this, DataCallbackFilterType.callOnChangedData);
 }
Example #11
0
        public void HandlePIEHidError(int error, PIEDevice sourceDevice)
        {
            if (sourceDevice != BackingObject)
            {
                return;
            }

            HandleDeviceConnected(error != 301 && BackingObject.Connected);
        }
Example #12
0
        public PiEngineeringDevice(Network network, PIEDevice device)
            : base(network, DeviceType.Keypad)
        {
            BackingObject = device;
            _keypad       = new PiEngineeringKeypad(this);

            BackingObject.SetErrorCallback(this);

            Reconnect();
        }
Example #13
0
 private RailDriverDevice()
 {
     device = PIEDevice.EnumeratePIE().Where(dev => dev.HidUsagePage == 0xc && dev.Pid == 210).FirstOrDefault();
     if (null != device)
     {
         device.SetupInterface();
         device.SuppressDuplicateReports = true;
         writeBuffer = new byte[WriteBufferSize];
     }
 }
Example #14
0
        internal RailDriver32(PIEDevice device)
        {
            myDevice = device;
            for (int i = 0; i < Calibration.Length; i++)
            {
                Calibration[i] = new AxisCalibration();
            }

            LoadCalibration(OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "RailDriver.xml"));
        }
Example #15
0
        public PiEngineeringDevice(Network network, PIEDevice device)
            : base(network, DeviceType.Keypad)
        {
            BackingObject = device;
            _keypad = new PiEngineeringKeypad(this);

            BackingObject.SetErrorCallback(this);

            Reconnect();
        }
Example #16
0
 /// <summary>Callback function from the PI Engineering DLL, raised each time the device pushes a data packet</summary>
 /// <param name="data">The callback data</param>
 /// <param name="sourceDevice">The source device</param>
 /// <param name="error">The last error generated (if any)</param>
 public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice, int error)
 {
     if (myDevice == sourceDevice)
     {
         for (int r = 0; r < sourceDevice.ReadLength; r++)
         {
             currentState[r] = data[r];
         }
     }
 }
Example #17
0
        //data callback
        public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice, int error)
        {
            //check the sourceDevice and make sure it is the same device as selected in CboDevice
            if (sourceDevice == devices[selecteddevice])
            {
                //check the switch byte
                byte val2 = (byte)(data[2] & 1);
                if (val2 == 0)
                {
                    c = this.LblSwitchPos;
                    this.SetText("switch up");
                }
                else
                {
                    c = this.LblSwitchPos;
                    this.SetText("switch down");
                }
                //read the unit ID
                c = this.LblUnitID;
                this.SetText(data[1].ToString());

                //write raw data to listbox1
                String output = "Callback: " + sourceDevice.Pid + ", ID: " + selecteddevice.ToString() + ", data=";
                for (int i = 0; i < sourceDevice.ReadLength; i++)
                {
                    output = output + BinToHex(data[i]) + " ";
                }
                this.SetListBox(output);

                //time stamp info 4 bytes
                long absolutetime  = 16777216 * data[14] + 65536 * data[15] + 256 * data[16] + data[17]; //ms
                long absolutetime2 = absolutetime / 1000;                                                //seconds
                c = this.label19;
                this.SetText("absolute time: " + absolutetime2.ToString() + " s");
                long deltatime = absolutetime - saveabsolutetime;
                c = this.label20;
                this.SetText("delta time: " + deltatime + " ms");
                saveabsolutetime = absolutetime;

                c = label16;
                SetText("Touch Pad");
                c = TxtZ;
                SetText(data[7].ToString());
                sbyte deltax = (sbyte)data[8];
                c = TxtX;
                SetText(deltax.ToString());
                sbyte deltay = (sbyte)data[9];
                c = TxtY;
                SetText(deltay.ToString());
                c = LblX;
                SetText("dX:");
                c = LblY;
                SetText("dY:");
            }
        }
        /// <summary>
        /// Get Devices
        /// </summary>
        /// <returns>
        /// True, they are exist
        /// </returns>
        public bool GetDevices()
        {
            _cboDevices.Items.Clear();
            cbotodevice = new int[128]; //128=max # of devices
            //enumerate and setupinterfaces for all devices
            devices = PIEDevice.EnumeratePIE();
            if (devices.Length == 0)
            {
                //No Devices Found
                return(false);
            }
            else
            {
                int cbocount = 0; //keeps track of how many valid devices were added to the CboDevice box
                for (int i = 0; i < devices.Length; i++)
                {
                    //information about device
                    //PID = devices[i].Pid);
                    //HID Usage = devices[i].HidUsage);
                    //HID Usage Page = devices[i].HidUsagePage);
                    //HID Version = devices[i].Version);
                    long hidusagepg = devices[i].HidUsagePage;
                    long hidusage   = devices[i].HidUsage;
                    if (devices[i].HidUsagePage == 0xc)
                    {
                        switch (devices[i].Pid)
                        {
                        case 693:
                            _cboDevices.Items.Add(devices[i].ProductString + "16 MWII (" + devices[i].Pid + ") - " + devices[i].ManufacturersString);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;

                        default:
                            _cboDevices.Items.Add(devices[i].ProductString + "(" + devices[i].Pid + ") " + devices[i].ManufacturersString);
                            cbotodevice[cbocount] = i;
                            cbocount++;
                            break;
                        }
                        devices[i].SetupInterface();
                        // true = No continues check, false = keep checking
                        devices[i].suppressDuplicateReports = true;
                    }
                }
            }
            if (_cboDevices.Items.Count > 0)
            {
                _cboDevices.SelectedIndex = 0;
                selecteddevice            = cbotodevice[_cboDevices.SelectedIndex];
                wData = new byte[devices[selecteddevice].WriteLength];//go ahead and setup for write
            }
            return(true);
        }
        public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice)
        {
            if (sourceDevice != activeDevice)
            {
                return;
            }

            byte[] readData = null;
            while (sourceDevice.ReadData(ref readData) == 0) // Continue to read data as long as we have it.
            {
                ProcessData(readData);
            }
        }
        /// <summary>
        /// Data callback, called when RailDriver data is available
        /// </summary>
        /// <param name="data"></param>
        /// <param name="sourceDevice"></param>
        public void HandleHidData(byte[] data, PIEDevice sourceDevice, int error)
        {
            if (sourceDevice != Device)
            {
                return;
            }
            State.SaveButtonData();

            State.DirectionPercent = Percentage(data[1], FullReversed, Neutral, FullForward);

            State.ThrottlePercent = Percentage(data[2], ThrottleIdle, FullThrottle);

            State.DynamicBrakePercent = Percentage(data[2], ThrottleIdle, DynamicBrakeSetup, DynamicBrake);
            State.TrainBrakePercent   = Percentage(data[3], AutoBrakeRelease, FullAutoBrake);
            State.EngineBrakePercent  = Percentage(data[4], IndependentBrakeRelease, IndependentBrakeFull);
            float a      = .01f * State.EngineBrakePercent;
            float calOff = (1 - a) * BailOffDisengagedRelease + a * BailOffDisengagedFull;
            float calOn  = (1 - a) * BailOffEngagedRelease + a * BailOffEngagedFull;

            State.BailOff = Percentage(data[5], calOff, calOn) > 50;
            if (State.TrainBrakePercent >= 100)
            {
                State.Emergency = Percentage(data[3], FullAutoBrake, EmergencyBrake) > 50;
            }

            State.Wipers = (int)(.01 * Percentage(data[6], Rotary1Position1, Rotary1Position2, Rotary1Position3) + 2.5);
            State.Lights = (int)(.01 * Percentage(data[7], Rotary2Position1, Rotary2Position2, Rotary2Position3) + 2.5);
            State.AddButtonData(data);

            if (State.IsPressed(4, 0x30))
            {
                State.Emergency = true;
            }
            if (State.IsPressed(1, 0x40))
            {
                Active = !Active;
                EnableSpeaker(Active);
                if (Active)
                {
                    SetLEDs(0x80, 0x80, 0x80);
                    LEDSpeed          = -1;
                    UserInput.RDState = State;
                }
                else
                {
                    SetLEDs(0x40, 0x40, 0x40);
                    UserInput.RDState = null;
                }
            }
            State.Changed = true;
        }
Example #21
0
        /// <summary>
        /// Activates the device (among all the devices discovered by a previous
        /// call to EnumerateDevices) based on the specified index.
        /// </summary>
        /// <param name="deviceIndex">The index of the device to select.</param>
        public static void ActivateDevice(int deviceIndex)
        {
            if (deviceIndex < 0 || deviceIndex >= foundDevices.Length)
            {
                throw new ArgumentException(String.Format("deviceIndex ({0}) is out of bounds", deviceIndex));
            }

            selectedDeviceIndex = deviceIndex;
            activeDevice        = foundDevices[deviceIndex];
            writeDataBuffer     = new byte[activeDevice.WriteLength]; // initialize the write data buffer for this device

            xkeysErrorHandler.SetActiveDevice(activeDevice);
            xkeysDataHandler.SetActiveDevice(activeDevice);
        }
Example #22
0
        private static DeviceModelEnum GetDeviceModel(PIEDevice device)
        {
            switch (device.Pid)
            {
            case 1029:
                return(DeviceModelEnum.Xk24);

            case 1062:
                return(DeviceModelEnum.Xk12JogAndShuttle);

            default:
                return(DeviceModelEnum.Unsupported);
            }
        }
Example #23
0
 public XKeysDevice(PIEDevice pieDevice)
 {
     PieDevice   = pieDevice;
     DeviceModel = GetDeviceModel(pieDevice);
     if (DeviceModel == DeviceModelEnum.Unsupported)
     {
         Logger.Error("This plugin does not support the {0} device in mode {1}", pieDevice.ProductString, pieDevice.Pid);
         return;
     }
     pieDevice.SetupInterface();
     pieDevice.SetDataCallback(this);
     pieDevice.SetErrorCallback(this);
     _oldData = new byte[pieDevice.ReadLength];
     GreenIndicatorLight(pieDevice);
     Dim();
     UnitId = ReadUnitId();
 }
Example #24
0
 /// <summary>Callback function from the PI Engineering DLL, raised each time the device pushes a data packet</summary>
 /// <param name="data">The callback data</param>
 /// <param name="sourceDevice">The source device</param>
 /// <param name="error">The last error generated (if any)</param>
 public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice, int error)
 {
     for (int i = 0; i < devices.Length; i++)
     {
         if (devices[i] == sourceDevice)
         {
             //Source device found, so map it
             if (AttachedJoysticks.ContainsKey(Raildriver.Guid))
             {
                 for (int r = 0; r < sourceDevice.ReadLength; r++)
                 {
                     AttachedJoysticks[Raildriver.Guid].currentState[r] = data[r];
                 }
             }
         }
     }
 }
Example #25
0
 public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice, int error)
 {
     try
     {
         lock (_oldData)
         {
             CheckKeys(data[1], 0, data[3], _oldData[3], data);
             CheckKeys(data[1], 1, data[4], _oldData[4], data);
             CheckKeys(data[1], 2, data[5], _oldData[5], data);
             CheckKeys(data[1], 3, data[6], _oldData[6], data);
             Buffer.BlockCopy(data, 0, _oldData, 0, (int)PieDevice.ReadLength);
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Example #26
0
        public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice, int error)
        {
           
            string keyCode = ctx.GetKeyCode(data);
            //for (int i = 3; i < 13; i++)
            //{
            //    Debug.Write(data[i]);
            //}
            //foreach (var d in data)
            //{

            //    Debug.Write(d);
            //}
            //Debug.WriteLine("");
            Debug.WriteLine(keyCode);

                
        }
Example #27
0
        private static void GreenIndicatorLight(PIEDevice device)
        {
            if (device.WriteLength < 4)
            {
                return;
            }
            var wData = new byte[device.WriteLength];

            wData[1] = 179; //0xb3
            wData[2] = 6;   //6 for green, 7 for red
            wData[3] = 1;   //0=off, 1=on, 2=flash
            var result = 404;

            while (result == 404)
            {
                result = device.WriteData(wData);
            }
        }
 /// <summary>Callback function from the PI Engineering DLL, raised each time the device pushes a data packet</summary>
 /// <param name="data">The callback data</param>
 /// <param name="sourceDevice">The source device</param>
 /// <param name="error">The last error generated (if any)</param>
 public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice, int error)
 {
     for (int i = 0; i < devices.Length; i++)
     {
         if (devices[i] == sourceDevice)
         {
             //Source device found, so map it
             for (int j = 0; j < AttachedJoysticks.Length; j++)
             {
                 if (AttachedJoysticks[j] is Raildriver && AttachedJoysticks[j].Handle == i)
                 {
                     for (int r = 0; r < sourceDevice.ReadLength; r++)
                     {
                         AttachedJoysticks[j].currentState[r] = data[r];
                     }
                 }
             }
         }
     }
 }
Example #29
0
        void PIEDataHandler.HandlePIEHidData(byte[] data, PIEDevice sourceDevice)
        {
            if (sourceDevice != _device.BackingObject)
            {
                return;
            }

            while (0 == sourceDevice.ReadData(ref data))
            {
                var state = BinaryConversions.ConvertKeypad(data);
                var changes = state.Buttons.Changes(_history.Last.Value.Buttons);
                _history.AddLast(state);

                Buttons = state.Buttons;

                var @event = DeviceEvent.KeypadStateChanged(_device, null);

                _device.AddEvent(@event);
            }
        }
Example #30
0
        void PIEDataHandler.HandlePIEHidData(byte[] data, PIEDevice sourceDevice)
        {
            if (sourceDevice != _device.BackingObject)
            {
                return;
            }


            while (0 == sourceDevice.ReadData(ref data))
            {
                var state   = BinaryConversions.ConvertKeypad(data);
                var changes = state.Buttons.Changes(_history.Last.Value.Buttons);
                _history.AddLast(state);

                Buttons = state.Buttons;

                var @event = DeviceEvent.KeypadStateChanged(_device, null);

                _device.AddEvent(@event);
            }
        }
Example #31
0
 public Device(PIEDevice pieDevice)
 {
     PieDevice = pieDevice;
     pieDevice.SetupInterface();
     if (!string.Equals(pieDevice.ProductString, "XK-24 HID", StringComparison.Ordinal))
     {
         Logger.Error("This plugin does not support the {0} device", pieDevice.ProductString);
         return;
     }
     if (pieDevice.Pid != 1029)
     {
         Logger.Error("Invalid XKeys device PID mode: {0}, should be 1029 (mode 1)", pieDevice.Pid);
         return;
     }
     pieDevice.SetDataCallback(this);
     pieDevice.SetErrorCallback(this);
     _oldData = new byte[pieDevice.ReadLength];
     GreenIndicatorLight(pieDevice);
     Dim();
     UnitId = ReadUnitId();
 }
Example #32
0
 //data callback
 public void HandleHidData(byte[] data, PIEDevice sourceDevice, int error)
 {
     //check the sourceDevice and make sure it is the same device as selected in CboDevice
     if (sourceDevice == devices[selecteddevice])
     {
         //write raw data to listbox1
         string output = "Callback: " + sourceDevice.Pid + ", ID: " + selecteddevice.ToString() + ", data=";
         for (int i = 0; i < sourceDevice.ReadLength; i++)
         {
             output = output + data[i].ToString() + "  ";
         }
         //Reverser = rdata[1]
         //Throttle = rdata[2]
         //AutoBrake = rdata[3]
         //Ind Brake = rdata[4]
         //Bail Off = rdata[5]
         //Wiper = rdata[6]
         //Lights = rdata[7]
         //buttons = rdata[8] to rdata[13]
         SetListBox(output);
     }
 }
        private static void EnumerationThreadProc()
        {
            var oldDevices = new PIEDevice[0];

            while (true)
            {
                try
                {
                    var devices = PIEDevice.EnumeratePIE();
                    foreach (var pieDevice in devices.Where(d => d.HidUsagePage == 0xC && !oldDevices.Any(od => DeviceEquals(od, d))))
                    {
                        var device = new XKeysDevice(pieDevice);
                        lock (((IList)Devices).SyncRoot)
                            Devices.Add(device);
                        DeviceConnected?.Invoke(null, device);
                        Logger.Info("New device connected {0}:{1}", pieDevice.Pid, pieDevice.Vid);
                    }
                    foreach (var pieDevice in oldDevices.Where(d => d.HidUsagePage == 0xC && !devices.Any(od => DeviceEquals(od, d))))
                    {
                        var device = Devices.FirstOrDefault(d => DeviceEquals(d.PieDevice, pieDevice));
                        if (device == null)
                        {
                            continue;
                        }
                        device.Dispose();
                        lock (((IList)Devices).SyncRoot)
                            Devices.Remove(device);
                        Logger.Info("Device disconnected {0}:{1}", pieDevice.Pid, pieDevice.Vid);
                    }
                    oldDevices = devices;
                    Thread.Sleep(1000);
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }
        }
Example #34
0
        //data callback
        public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice, int error)
        {
            //check the sourceDevice and make sure it is the same device as selected in CboDevice
            if (sourceDevice == devices[selecteddevice])
            {
                //read the unit ID
                c = this.LblUnitID;
                this.SetText(data[1].ToString());

                //write raw data to listbox1 in Hex
                String output = "Callback: " + sourceDevice.Pid + ", ID: " + selecteddevice.ToString() + ", data=";
                for (int i = 0; i < sourceDevice.ReadLength; i++)
                {
                    output = output + BinToHex(data[i]) + " ";
                }
                this.SetListBox(output);



                //time stamp info 4 bytes
                long absolutetime = 0;
                if (sourceDevice.Pid == 1040 || sourceDevice.Pid == 1042)
                {
                    absolutetime = 16777216 * data[27] + 65536 * data[28] + 256 * data[29] + data[30];      //ms
                }
                else if (sourceDevice.Pid == 1043 || sourceDevice.Pid == 1045)
                {
                    absolutetime = 16777216 * data[35] + 65536 * data[36] + 256 * data[37] + data[38]; //ms
                }
                long absolutetime2 = absolutetime / 1000;                                              //seconds
                c = this.label19;
                this.SetText("absolute time: " + absolutetime2.ToString() + " s");
                long deltatime = absolutetime - saveabsolutetime;
                c = this.label20;
                this.SetText("delta time: " + deltatime + " ms");
                saveabsolutetime = absolutetime;
            }
        }
Example #35
0
 public void HandlePIEHidError(Int32 error, PIEDevice sourceDevice)
 {
     XkeysStatusLabel.Text = "Error: " + error.ToString();
 }
Example #36
0
        //data callback
        public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice)
        {
            //check the sourceDevice and make sure it is the same device as selected in CboDevice
            if (sourceDevice == devices[selecteddevice])
            {
                byte[] rdata = null;
                while (0 == sourceDevice.ReadData(ref rdata)) //do this so don't ever miss any data
                {
                    //read the unit ID
                    c = this.LblUnitID;
                    this.SetText(rdata[sourceDevice.ReadLength - 1].ToString());
                    //write raw data to listbox1
                    String output = "Callback: " + this.devices[selecteddevice].Pid + ", ID: " + selecteddevice.ToString() + ", data=";
                    for (int i = 0; i < sourceDevice.ReadLength; i++)
                    {
                        output = output + rdata[i].ToString() + " ";
                    }
                    this.SetListBox(output);
                    //write Analog data to the individual textboxes
                    c = this.textBoxA2;
                    this.SetText(rdata[1].ToString());
                    c = this.textBoxA3;
                    this.SetText(rdata[2].ToString());
                    c = this.textBoxA4;
                    this.SetText(rdata[3].ToString());
                    c = this.textBoxA5;
                    this.SetText(rdata[4].ToString());
                    c = this.textBoxA6;
                    this.SetText(rdata[5].ToString());
                    c = this.textBoxA7;
                    this.SetText(rdata[6].ToString());
                    c = this.textBoxA8;
                    this.SetText(rdata[7].ToString());
                    c = this.textBoxA9;
                    this.SetText(rdata[8].ToString());
                    c = this.textBoxA10;
                    this.SetText(rdata[9].ToString());
                    c = this.textBoxA11;
                    this.SetText(rdata[10].ToString());
                    c = this.textBoxA12;
                    this.SetText(rdata[11].ToString());
                    c = this.textBoxA13;
                    this.SetText(rdata[12].ToString());
                    c = this.textBoxA14;
                    this.SetText(rdata[13].ToString());
                    c = this.textBoxA15;
                    this.SetText(rdata[14].ToString());
                    c = this.textBoxA16;
                    this.SetText(rdata[15].ToString());
                    c = this.textBoxA17;
                    this.SetText(rdata[16].ToString());
                    c = this.textBoxA18;
                    this.SetText(rdata[17].ToString());
                    c = this.textBoxA19;
                    this.SetText(rdata[18].ToString());
                    c = this.textBoxA20;
                    this.SetText(rdata[19].ToString());
                    c = this.textBoxA21;
                    this.SetText(rdata[20].ToString());
                    c = this.textBoxA22;
                    this.SetText(rdata[21].ToString());
                    c = this.textBoxA23;
                    this.SetText(rdata[22].ToString());
                    c = this.textBoxA24;
                    this.SetText(rdata[23].ToString()); //pin 24

                    //write digital 1 data to the individual textboxes
                    c = this.textBoxD12;
                    this.SetText((rdata[24] & 1).ToString());
                    c = this.textBoxD13;
                    this.SetText(((rdata[24] & 2) >> 1).ToString());
                    c = this.textBoxD14;
                    this.SetText(((rdata[24] & 4) >> 2).ToString());
                    c = this.textBoxD15;
                    this.SetText(((rdata[24] & 8) >> 3).ToString());
                    c = this.textBoxD16;
                    this.SetText(((rdata[24] & 16) >> 4).ToString());
                    c = this.textBoxD17;
                    this.SetText(((rdata[24] & 32) >> 5).ToString());
                    c = this.textBoxD18;
                    this.SetText(((rdata[24] & 64) >> 6).ToString());
                    c = this.textBoxD19;
                    this.SetText(((rdata[24] & 128) >> 7).ToString());
                    c = this.textBoxD110;
                    this.SetText((rdata[25] & 1).ToString());
                    c = this.textBoxD111;
                    this.SetText(((rdata[25] & 2) >> 1).ToString());
                    c = this.textBoxD112;
                    this.SetText(((rdata[25] & 4) >> 2).ToString());
                    c = this.textBoxD113;
                    this.SetText(((rdata[25] & 8) >> 3).ToString());
                    c = this.textBoxD114;
                    this.SetText(((rdata[25] & 16) >> 4).ToString());
                    c = this.textBoxD115;
                    this.SetText(((rdata[25] & 32) >> 5).ToString());
                    c = this.textBoxD116;
                    this.SetText(((rdata[25] & 64) >> 6).ToString());
                    c = this.textBoxD117;
                    this.SetText(((rdata[25] & 128) >> 7).ToString());
                    c = this.textBoxD118;
                    this.SetText((rdata[26] & 1).ToString());
                    c = this.textBoxD119;
                    this.SetText(((rdata[26] & 2) >> 1).ToString());
                    c = this.textBoxD120;
                    this.SetText(((rdata[26] & 4) >> 2).ToString());
                    c = this.textBoxD121;
                    this.SetText(((rdata[26] & 8) >> 3).ToString());
                    c = this.textBoxD122;
                    this.SetText(((rdata[26] & 16) >> 4).ToString());
                    c = this.textBoxD123;
                    this.SetText(((rdata[26] & 32) >> 5).ToString());
                    c = this.textBoxD124;
                    this.SetText(((rdata[26] & 64) >> 6).ToString()); //pin 24

                    //write digital 2 data to the individual textboxes
                    c = this.textBoxD22;
                    this.SetText((rdata[27] & 1).ToString());
                    c = this.textBoxD23;
                    this.SetText(((rdata[27] & 2) >> 1).ToString());
                    c = this.textBoxD24;
                    this.SetText(((rdata[27] & 4) >> 2).ToString());
                    c = this.textBoxD25;
                    this.SetText(((rdata[27] & 8) >> 3).ToString());
                    c = this.textBoxD26;
                    this.SetText(((rdata[27] & 16) >> 4).ToString());
                    c = this.textBoxD27;
                    this.SetText(((rdata[27] & 32) >> 5).ToString());
                    c = this.textBoxD28;
                    this.SetText(((rdata[27] & 64) >> 6).ToString());
                    c = this.textBoxD29;
                    this.SetText(((rdata[27] & 128) >> 7).ToString());
                    c = this.textBoxD210;
                    this.SetText((rdata[28] & 1).ToString());
                    c = this.textBoxD211;
                    this.SetText(((rdata[28] & 2) >> 1).ToString());
                    c = this.textBoxD212;
                    this.SetText(((rdata[28] & 4) >> 2).ToString());
                    c = this.textBoxD213;
                    this.SetText(((rdata[28] & 8) >> 3).ToString());
                    c = this.textBoxD214;
                    this.SetText(((rdata[28] & 16) >> 4).ToString());
                    c = this.textBoxD215;
                    this.SetText(((rdata[28] & 32) >> 5).ToString());
                    c = this.textBoxD216;
                    this.SetText(((rdata[28] & 64) >> 6).ToString());
                    c = this.textBoxD217;
                    this.SetText(((rdata[28] & 128) >> 7).ToString());
                    c = this.textBoxD218;
                    this.SetText((rdata[29] & 1).ToString());
                    c = this.textBoxD219;
                    this.SetText(((rdata[29] & 2) >> 1).ToString());
                    c = this.textBoxD220;
                    this.SetText(((rdata[29] & 4) >> 2).ToString());
                    c = this.textBoxD221;
                    this.SetText(((rdata[29] & 8) >> 3).ToString());
                    c = this.textBoxD222;
                    this.SetText(((rdata[29] & 16) >> 4).ToString());
                    c = this.textBoxD223;
                    this.SetText(((rdata[29] & 32) >> 5).ToString());
                    c = this.textBoxD224;
                    this.SetText(((rdata[29] & 64) >> 6).ToString()); //pin 24
                }
            }
        }
Example #37
0
        // Data callback
        public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice)
        {
            // Check the sourceDevice and make sure it is the same device as selected in CboDevice
             if (sourceDevice == devices[selectedDevice])
             {
            // byte array used for read data
            byte[] rData = null;

            // I think an MCU would use while(1) here, as an equivalent structure (TB, 11/12/2011)
            while (0 == sourceDevice.ReadData(ref rData)) // do this so don't ever miss any data
            {
               // Read the unit ID
               // TODO: If we do only have one device, then we could simply grab the ID once up above, and load it into an
               //         instance variable on form_load. Need to verify that we are using only one device, and then how
               //         that device is numbered
               c = this.LblUnitID;
               this.SetText(rData[sourceDevice.ReadLength - 1].ToString());

               //write raw data to listbox1
               String output = "Callback: " + this.devices[selectedDevice].Pid + ", ID: " + selectedDevice.ToString() + ", data=";
               for (int i = 0; i < sourceDevice.ReadLength; i++)
               {
                  output = output + rData[i].ToString() + " ";
               }
               this.SetListBox(output);

            // TODO: We'll need to convert THESE data into the correct formats needed by SimConnect (TB, 11/12/2011)
               // Write Analog data from each pin, to the corresponding individual textboxes. Each of these pins
               //   will have specific data assigned (if all are used), and these data will have to be translated
               //   into the proper SimConnect Event calls.

               // TODO: Use the debugger to check the format of these bytes, and how the data changes. I believe
               //         these to be the analog data, and thus it should be a simply matter of writing the values
               //         to the appropriate P3D event/variable.
               c = this.textBoxA2;
               this.SetText(rData[1].ToString());  // pin 0

               c = this.textBoxA3;
               this.SetText(rData[2].ToString());

               c = this.textBoxA4;
               this.SetText(rData[3].ToString());

               c = this.textBoxA5;
               this.SetText(rData[4].ToString());

               c = this.textBoxA6;
               this.SetText(rData[5].ToString());

               c = this.textBoxA7;
               this.SetText(rData[6].ToString());

               c = this.textBoxA8;
               this.SetText(rData[7].ToString());

               c = this.textBoxA9;
               this.SetText(rData[8].ToString());

               c = this.textBoxA10;
               this.SetText(rData[9].ToString());

               c = this.textBoxA11;
               this.SetText(rData[10].ToString());

               c = this.textBoxA12;
               this.SetText(rData[11].ToString());

               c = this.textBoxA13;
               this.SetText(rData[12].ToString());

               c = this.textBoxA14;
               this.SetText(rData[13].ToString());

               c = this.textBoxA15;
               this.SetText(rData[14].ToString());

               c = this.textBoxA16;
               this.SetText(rData[15].ToString());

               c = this.textBoxA17;
               this.SetText(rData[16].ToString());

               c = this.textBoxA18;
               this.SetText(rData[17].ToString());

               c = this.textBoxA19;
               this.SetText(rData[18].ToString());

               c = this.textBoxA20;
               this.SetText(rData[19].ToString());

               c = this.textBoxA21;
               this.SetText(rData[20].ToString());

               c = this.textBoxA22;
               this.SetText(rData[21].ToString());

               c = this.textBoxA23;
               this.SetText(rData[22].ToString());

               c = this.textBoxA24;
               this.SetText(rData[23].ToString()); // pin 24

               //write digital 1 data to the individual textboxes
               c = this.textBoxD12;
               this.SetText((rData[24] & 1).ToString()); // Bitwise AND with 0b00000001
               c = this.textBoxD13;
               this.SetText(((rData[24] & 2) >> 1).ToString());
               c = this.textBoxD14;
               this.SetText(((rData[24] & 4) >> 2).ToString());
               c = this.textBoxD15;
               this.SetText(((rData[24] & 8) >> 3).ToString());
               c = this.textBoxD16;
               this.SetText(((rData[24] & 16) >> 4).ToString());
               c = this.textBoxD17;
               this.SetText(((rData[24] & 32) >> 5).ToString());
               c = this.textBoxD18;
               this.SetText(((rData[24] & 64) >> 6).ToString());
               c = this.textBoxD19;
               this.SetText(((rData[24] & 128) >> 7).ToString());

               c = this.textBoxD110;
               this.SetText((rData[25] & 1).ToString());
               c = this.textBoxD111;
               this.SetText(((rData[25] & 2) >> 1).ToString());
               c = this.textBoxD112;
               this.SetText(((rData[25] & 4) >> 2).ToString());
               c = this.textBoxD113;
               this.SetText(((rData[25] & 8) >> 3).ToString());
               c = this.textBoxD114;
               this.SetText(((rData[25] & 16) >> 4).ToString());
               c = this.textBoxD115;
               this.SetText(((rData[25] & 32) >> 5).ToString());
               c = this.textBoxD116;
               this.SetText(((rData[25] & 64) >> 6).ToString());
               c = this.textBoxD117;
               this.SetText(((rData[25] & 128) >> 7).ToString());

               c = this.textBoxD118;
               this.SetText((rData[26] & 1).ToString());
               c = this.textBoxD119;
               this.SetText(((rData[26] & 2) >> 1).ToString());
               c = this.textBoxD120;
               this.SetText(((rData[26] & 4) >> 2).ToString());
               c = this.textBoxD121;
               this.SetText(((rData[26] & 8) >> 3).ToString());
               c = this.textBoxD122;
               this.SetText(((rData[26] & 16) >> 4).ToString());
               c = this.textBoxD123;
               this.SetText(((rData[26] & 32) >> 5).ToString());
               c = this.textBoxD124;
               this.SetText(((rData[26] & 64) >> 6).ToString()); //pin 24

               //write digital 2 data to the individual textboxes
               c = this.textBoxD22;
               this.SetText((rData[27] & 1).ToString());
               c = this.textBoxD23;
               this.SetText(((rData[27] & 2) >> 1).ToString());
               c = this.textBoxD24;
               this.SetText(((rData[27] & 4) >> 2).ToString());
               c = this.textBoxD25;
               this.SetText(((rData[27] & 8) >> 3).ToString());
               c = this.textBoxD26;
               this.SetText(((rData[27] & 16) >> 4).ToString());
               c = this.textBoxD27;
               this.SetText(((rData[27] & 32) >> 5).ToString());
               c = this.textBoxD28;
               this.SetText(((rData[27] & 64) >> 6).ToString());
               c = this.textBoxD29;
               this.SetText(((rData[27] & 128) >> 7).ToString());

               c = this.textBoxD210;
               this.SetText((rData[28] & 1).ToString());
               c = this.textBoxD211;
               this.SetText(((rData[28] & 2) >> 1).ToString());
               c = this.textBoxD212;
               this.SetText(((rData[28] & 4) >> 2).ToString());
               c = this.textBoxD213;
               this.SetText(((rData[28] & 8) >> 3).ToString());
               c = this.textBoxD214;
               this.SetText(((rData[28] & 16) >> 4).ToString());
               c = this.textBoxD215;
               this.SetText(((rData[28] & 32) >> 5).ToString());
               c = this.textBoxD216;
               this.SetText(((rData[28] & 64) >> 6).ToString());
               c = this.textBoxD217;
               this.SetText(((rData[28] & 128) >> 7).ToString());

               c = this.textBoxD218;
               this.SetText((rData[29] & 1).ToString());
               c = this.textBoxD219;
               this.SetText(((rData[29] & 2) >> 1).ToString());
               c = this.textBoxD220;
               this.SetText(((rData[29] & 4) >> 2).ToString());
               c = this.textBoxD221;
               this.SetText(((rData[29] & 8) >> 3).ToString());
               c = this.textBoxD222;
               this.SetText(((rData[29] & 16) >> 4).ToString());
               c = this.textBoxD223;
               this.SetText(((rData[29] & 32) >> 5).ToString());
               c = this.textBoxD224;
               this.SetText(((rData[29] & 64) >> 6).ToString()); //pin 24
            }
             }
        }
Example #38
0
        public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice)
        {
            //check the sourceDevice and make sure it is the same device as selected in CboDevice
            if (sourceDevice == devices[selecteddevice])
            {
                byte[] rdata = null;
                while (0 == sourceDevice.ReadData(ref rdata)) //do this so don't ever miss any data
                {
                    //write raw data to listbox1 in HEX
                    //String output = string.Format("Callback: {0}, ID: {1}, UnitID: {2}, data=", sourceDevice.Pid, selecteddevice.ToString(), rdata[1].ToString());
                    //for (int i = 0; i < sourceDevice.ReadLength; i++)
                    //{
                        //output = output + BinToHex(rdata[i]) + " ";
                    //}

                    String output = string.Format("Callback: {0}, ID: {1}, UnitID: {2}, data=", sourceDevice.Pid, selecteddevice.ToString(), rdata[1].ToString());
                    BitArray col1 = new BitArray(new byte[] { rdata[3] });
                    BitArray col2 = new BitArray(new byte[] { rdata[4] });
                    BitArray col3 = new BitArray(new byte[] { rdata[5] });
                    BitArray col4 = new BitArray(new byte[] { rdata[6] });
                    switch (device_type)
                    {
                        case "XK-24":
                        case "XK-60":
                        case "XK-80":
                            for (int i = 0; i < col1.Length; i++)
                            {
                                if (col1[i])
                                {
                                    int key = i;
                                    output = output + " Key pressed: " + key + " " + col1[i].ToString();
                                }
                            }
                            for (int i = 0; i < col2.Length; i++)
                            {
                                if (col2[i])
                                {
                                    int key = i + 8;
                                    output = output + " Key pressed: " + key + " " + col2[i].ToString();
                                }
                            }
                            for (int i = 0; i < col3.Length; i++)
                            {
                                if (col3[i])
                                {
                                    int key = i + 16;
                                    output = output + " Key pressed: " + key + " " + col3[i].ToString();
                                }
                            }
                            for (int i = 0; i < col4.Length; i++)
                            {
                                if (col4[i])
                                {
                                    int key = i + 24;
                                    output = output + " Key pressed: " + key + " " + col4[i].ToString();
                                }
                            }
                            if (device_type == "XK-24")
                            {
                                // XK-24 only has 24 keys
                                break;
                            }
                            BitArray col5 = new BitArray(new byte[] { rdata[7] });
                            BitArray col6 = new BitArray(new byte[] { rdata[8] });
                            BitArray col7 = new BitArray(new byte[] { rdata[9] });
                            BitArray col8 = new BitArray(new byte[] { rdata[10] });
                            BitArray col9 = new BitArray(new byte[] { rdata[11] });
                            BitArray col10 = new BitArray(new byte[] { rdata[12] });
                            for (int i = 0; i < col5.Length; i++)
                            {
                                if (col1[i])
                                {
                                    int key = i + 32;
                                    output = output + " Key pressed: " + key + " " + col1[i].ToString();
                                }
                            }
                            for (int i = 0; i < col6.Length; i++)
                            {
                                if (col2[i])
                                {
                                    int key = i + 40;
                                    output = output + " Key pressed: " + key + " " + col2[i].ToString();
                                }
                            }
                            for (int i = 0; i < col7.Length; i++)
                            {
                                if (col3[i])
                                {
                                    int key = i + 48;
                                    output = output + " Key pressed: " + key + " " + col3[i].ToString();
                                }
                            }
                            for (int i = 0; i < col8.Length; i++)
                            {
                                if (col4[i])
                                {
                                    int key = i + 56;
                                    output = output + " Key pressed: " + key + " " + col4[i].ToString();
                                }
                            }
                            for (int i = 0; i < col9.Length; i++)
                            {
                                if (col3[i])
                                {
                                    int key = i + 64;
                                    output = output + " Key pressed: " + key + " " + col3[i].ToString();
                                }
                            }
                            for (int i = 0; i < col10.Length; i++)
                            {
                                if (col4[i])
                                {
                                    int key = i + 72;
                                    output = output + " Key pressed: " + key + " " + col4[i].ToString();
                                }
                            }
                            break;
                        default:
                            for (int i = 0; i < sourceDevice.ReadLength; i++)
                            {
                                output = output + BinToHex(rdata[i]) + " ";
                            }
                            break;
                    }

                    OnUIThread(() => Diagnostics.Instance.DiagnosticListbox.Items.Add(output));
                }//end while
            }
        }
        private void OpenDevice()
        {
            _device = PIEDevice.EnumeratePIE().FirstOrDefault(p => p.HidUsage == CONSUMER_USAGE_PAGE_INPUT_AND_OUTPUT_HID_USAGE && p.Pid == GetPid());
            if (_device == null) return;

            ResetInterface();
        }
        public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice, int error)
        {
            
            try
            {
                w.OnTop();

               
                if (_ntAccountLocked)
                {
                    MessageBox.Show("locl");
                    return;
                }
                if (Status != XkeysKeyboardDeviceStatus.Opened)
                {
                    return;  // just to make sure Data only go through when both hardware/software are in good condition.
                }

                var kc = GetKeyCode(data);
                //Debug.WriteLine("JQD Handle Data" + kc);
                var ki = GetKeyIndex(data);
                if (_instrumentXAndActionXLightingKeys.Keys.Contains(ki))
                {
                    TurnOnOrOffControlAndPassiveLights(ki);
                }

                if(_productSwitchLightKeys.Contains(ki))
                {
                    TurnOnOrOffNonControlLight(ki);
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #41
0
 private void Button_Click_3(object sender, RoutedEventArgs e)
 {
     _devices = PIEDevice.EnumeratePIE(1523);
     _xkeyPad = _devices[0];
     _xkeyPad.SetupInterface();
     _xkeyPad.SetDataCallback(this);
     _xkeyPad.SetErrorCallback(this);
 }
        public void HandlePIEHidError(PIEDevice sourceDevices, int error)
        {
            if(error==309 || error==307) // e.g unplug
            {
                TryClose();
                Status = XkeysKeyboardDeviceStatus.Closed;
            }

            Debug.WriteLine("JQD Handle Err "+error);
        }
Example #43
0
 public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice)
 {
     MessageBox.Show("");
 }
Example #44
0
 public void HandlePIEHidError(int error, PIEDevice sourceDevices)
 {
      MessageBox.Show("");
 }
Example #45
0
 //error callback
 public void HandlePIEHidError(Int32 error, PIEDevice sourceDevice)
 {
     this.SetToolStrip("Error: " + error.ToString());
     if (error == 307)
         sourceDevice.CloseInterface();
 }
        public void Dispose()
        {
            try
            {
                turnOffAll();
                TryClose();
                Status = XkeysKeyboardDeviceStatus.Closed;
                
                _disposables.Dispose();
                
                _device = null;
            }
            catch (Exception)
            {

            }
        }