Exemple #1
0
        private void ReadHandler(HidReport report)
        {
            int    len     = Convert.ToInt32(report.Data[0]);
            string barcode = "";

            for (int i = 4; i < 4 + len; i++)
            {
                barcode += Convert.ToChar(report.Data[i]);
            }

            if (barcode == "Save")
            {
                Save();
            }
            else
            {
                var prefix = barcode.Substring(0, 8);
                if (prefix == PRESSFIT)
                {
                    txtPressfit.Text = barcode;
                }
                else if (prefix == GEAR)
                {
                    txtGear.Text = barcode;
                }
                else if (prefix == PINION)
                {
                    txtPinion.Text = barcode;
                }
            }

            _hidDevice.ReadReport(ReadProcess);
        }
Exemple #2
0
        private void ReadHandler(HidReport report)
        {
            Output.Clear();
            Output.AppendText(String.Join(" ", report.Data.Select(d => d.ToString("X2"))));

            _deviceList[Devices.SelectedIndex].ReadReport(ReadProcess);
        }
Exemple #3
0
        public void WriteCommand(byte[] Command_type, byte[] para_1_in, byte[] para_2_in, bool follow_data)
        {
            byte[] CommandBuffer = new byte[1021];                                           //2+12+1(Report ID)

            CommandBuffer[0]  = 0x01;                                                        //Report ID
            CommandBuffer[1]  = 0x00;
            CommandBuffer[2]  = 0x0C;                                                        //Packet Length Low
            CommandBuffer[3]  = 0x00;                                                        //Packet Length High
            CommandBuffer[4]  = Command_type[0];
            CommandBuffer[5]  = (follow_data) ? Convert.ToByte(0x01) : Convert.ToByte(0x00); //Flags
            CommandBuffer[6]  = 0x00;                                                        //Reserved
            CommandBuffer[7]  = 0x02;                                                        //Para_count
            CommandBuffer[8]  = para_1_in[3];
            CommandBuffer[9]  = para_1_in[2];
            CommandBuffer[10] = para_1_in[1];
            CommandBuffer[11] = para_1_in[0];
            CommandBuffer[12] = para_2_in[3];
            CommandBuffer[13] = para_2_in[2];
            CommandBuffer[14] = para_2_in[1];
            CommandBuffer[15] = para_2_in[0];
            for (int c = 16; c < CommandBuffer.Length; c++)
            {
                CommandBuffer[c] = 0x00;
            }
            HidReport report = new HidReport(CommandBuffer.Length, new HidDeviceData(CommandBuffer, HidDeviceData.ReadStatus.Success));

            _hid_handler.WriteReport(report);
        }
Exemple #4
0
        static void Main()
        {
            _device = HidDevices.Enumerate(0x0483, 0x5750).FirstOrDefault();

            if (_device == null)
            {
                Console.WriteLine("Could not find a dev, press any key to exit.");
                Console.ReadKey();
            }


            _device.OpenDevice();

            _device.Inserted += DeviceAttachedHandler;
            _device.Removed  += DeviceRemovedHandler;

            _device.MonitorDeviceEvents = true;
            _device.ReadReport(OnReport);

            Console.WriteLine("dev found, press Escape to exit.");
            var keypr = Console.ReadKey().Key;

            while (keypr != ConsoleKey.Escape)
            {
                keypr = Console.ReadKey().Key;
                if (keypr != ConsoleKey.Escape)
                {
                    HidReport report = _device.CreateReport();
                    report.ReportId = 1;
                    report.Data[0]  = Convert.ToByte(keypr);
                    _device.WriteReport(report);
                }
            }
            _device.CloseDevice();
        }
Exemple #5
0
        private void ReceiveReport(HidReport report)
        {
            ChronState state = new ChronState();

            if (report.Data.Length > 2)
            {
                if (report.Data[0] == 0 && report.Data[1] == 2)
                {
                    state.Diagnostics      = "Received Chron Entry " + cron_entries_received + ": ";
                    state.Read_MoreToParse = true;
                    cron_entries_received++;
                    //this.GetCronDataContinuation();
                }

                if (report.Data[0] == 0 && report.Data[1] == 3)
                {
                    state.Diagnostics     = "Chron Entry Comms Ended: ";
                    cron_entries_received = 0;
                }

                if (debugPrintRawMessages)
                {
                    for (int i = 0; i < report.Data.Length; i++)
                    {
                        state.Diagnostics += report.Data[i] + ", ";
                    }

                    System.Diagnostics.Debug.WriteLine(state.Diagnostics);
                }

                this.OnEntryReceived(state);
            }
        }
Exemple #6
0
        public void WriteCronData(ChronEntries ce)
        {
            if (connectedToDriver && ce.entries.Count() > 0)
            {
                foreach (ChronEntry i in ce.entries)
                {
                    QueuedItems.Enqueue(i);
                }

                byte[] data = new byte[64];
                data[0] = (byte)0x00;                 // required
                data[1] = (byte)0x07;                 // begin writing

                ChronEntry buffer = QueuedItems.Dequeue();

                System.Diagnostics.Debug.WriteLine("Codasyl");
                data[2] = (byte)QueuedItems.Count();                 // inform pic how many left.
                for (int x = 0; x < 21; x++)
                {
                    data[x + 3] = buffer.mEntry[x];
                    System.Diagnostics.Debug.Write(data[x + 3]);
                }

                System.Diagnostics.Debug.WriteLine("");
                HidReport report = new HidReport(63, new HidDeviceData(data, HidDeviceData.ReadStatus.Success));
                device.WriteReport(report);
                //ReceiveReport(report);
            }
        }
        private void ReadReport(HidReport hidReport)
        {
            var report = new Report(hidReport);

            if (report.ReadStatus == HidDeviceData.ReadStatus.Success)
            {
                if (report.Data.Length == 16)
                {
                    StringBuilder sb = new StringBuilder(16);
                    for (int i = 0; i < 16; ++i)
                    {
                        bool newState = report.Data[i] != 0;

                        if (_keyState[i] != newState)
                        {
                            KeyChanged?.Invoke(i, newState);
                        }

                        _keyState[i] = newState;
                        sb.Append(_keyState[i] ? '1' : '0');
                    }

                    Debug.WriteLine($"Keys: {sb.ToString()}");
                }
            }

            if (_attached && report.ReadStatus != HidDeviceData.ReadStatus.NotConnected)
            {
                _hidDevice.ReadReport(ReadReport);
            }
            else
            {
                _isReading = 0;
            }
        }
Exemple #8
0
        public BigRedButtonState?QueryState()
        {
            var statusQuery = new HidReport(1)
            {
                Data = StatusReport
            };

            var isQueryWritten = device.WriteReport(statusQuery);

            if (!isQueryWritten)
            {
                return(null);
            }

            var readReport = device.ReadReport(100);

            var readData = readReport.Data;

            if (readReport.ReadStatus != HidDeviceData.ReadStatus.Success)
            {
                return(null);
            }

            var statusByte = readData[0];

            Debug.WriteLine(Convert.ToString(readData[0], 2));

            var buttonIsPressed = (statusByte & (1 << 0)) == 0;
            var lidIsOpen       = (statusByte & (1 << 1)) != 0;

            return(new BigRedButtonState(buttonIsPressed, lidIsOpen));
        }
Exemple #9
0
        // Fired when received data - or device disconnected
        private void OnReadReport(HidReport report)
        {
            lock (ReadLock)
            {
                // process your data here
                byte len = report.Data[0];

                if (len > 0)
                {
                    byte[] buf = new byte[len];
                    for (int i = 0; i < len; i++)
                    {
                        buf[i] = report.Data[i + 1];
                    }

                    packetsIn.Add(buf);

                    OnNewIncommingData(new EventArgs());
                }

                // we need to start listening again for more data
                if (_selectedDevice != null && _selectedDevice.IsConnected)
                {
                    try { _selectedDevice.ReadReport(OnReadReport); }
                    catch { }
                }
            }
        }
Exemple #10
0
 /// <summary>
 /// Sets the PowerMate's LED pulse speed. The range is  [-255, 255], and the
 /// useful range seems to be approximately [-32, 64]. A value of 0 means default
 /// pulse speed. A negative value is slower than the default, a positive value
 /// is faster.
 /// </summary>
 /// <param name="speed"></param>
 public void SetLedPulseSpeed(int speed)
 {
     if (connectedToDriver)
     {
         byte[] data = new byte[9];
         data[0] = 0x00;
         data[1] = 0x41;
         data[2] = 0x01;
         data[3] = 0x04; // command
         data[4] = 0x00; // Table 0
         if (speed < 0)
         {
             data[5] = 0;
             data[6] = (byte)(-speed);
         }
         else if (speed == 0)
         {
             data[5] = 1;
             data[6] = 0;
         }
         else // speed > 0
         {
             data[5] = 2;
             data[6] = (byte)(speed);
         }
         data[7] = 0x00;
         data[8] = 0x00;
         HidReport report = new HidReport(9, new HidDeviceData(data, HidDeviceData.ReadStatus.Success));
         device.WriteFeatureData(data);
     }
 }
Exemple #11
0
        private void OnReport(HidReport report)
        {
            if (attached == false)
            {
                return;
            }

            if (report.Data.Length >= 6)
            {
                PowerMateState state = ParseState(report.Data);
                if (!state.IsValid)
                {
                    System.Diagnostics.Debug.WriteLine("Invalid PowerMate state");
                }
                else
                {
                    GenerateEvents(state);

                    if (debugPrintRawMessages)
                    {
                        System.Diagnostics.Debug.Write("PowerMate raw data: ");
                        for (int i = 0; i < report.Data.Length; i++)
                        {
                            System.Diagnostics.Debug.Write(String.Format("{0:000} ", report.Data[i]));
                        }
                        System.Diagnostics.Debug.WriteLine("");
                    }
                }
            }

            device.ReadReport(OnReport);
        }
Exemple #12
0
        public void WriteCronDataContinuation()
        {
            if (connectedToDriver)
            {
                if (QueuedItems.Count > 0)
                {
                    byte[] data = new byte[64];
                    data[0] = (byte)0x00;
                    data[1] = (byte)0x04;

                    ChronEntry buffer = QueuedItems.Dequeue();

                    data[2] = (byte)QueuedItems.Count();                     // inform pic how many left.
                    for (int x = 0; x < 21; x++)
                    {
                        data[x + 3] = buffer.mEntry[x];
                    }

                    HidReport report = new HidReport(63, new HidDeviceData(data, HidDeviceData.ReadStatus.Success));
                    device.WriteReport(report);
                    //ReceiveReport(report);
                }
                else
                {
                    // write dummy to end sequence
                    byte[] data = new byte[64];
                    data[0] = (byte)0x00;
                    data[1] = (byte)0x04;
                    data[2] = (byte)0x00;
                    HidReport report = new HidReport(63, new HidDeviceData(data, HidDeviceData.ReadStatus.Success));
                    device.WriteReport(report);
                    //ReceiveReport(report);
                }
            }
        }
        public override void ReadReport(HidReport report)
        {
            var ReadReport = new BL_Report(report);
            var data       = new byte[] { };

            if (ReadReport.ReadStatus == HidDeviceData.ReadStatus.Success)
            {
                LogUpdate("Report ID : " + ReadReport.ReportId, true);
                if (ReadReport.Data != null)
                {
                    Array.Resize(ref data, data.GetUpperBound(0) + ReadReport.Data.Length + 1);
                    Array.Copy(ReadReport.Data, 0, data, 0, ReadReport.Data.Length);
                }
                else if (ReadReport.FollowwithData)
                {
                    LogUpdate("Following with Data, BootLoader Status : " + ReadReport.BL_Status, true);
                }
                else if (ReadReport.Response_Tag == 160)
                {
                    LogUpdate("Command Operated Status : " + ReadReport.BL_Status + " Command : " + ReadReport.Command_Respond_For, true);
                }
                if (IsListening && data.Length > 0 && DataRecieved != null)
                {
                    DataRecieved(data);
                }
            }
            if (ReadReport.ReadStatus != HidDeviceData.ReadStatus.NotConnected)
            {
                _hid_handler.ReadReport(this.ReadReport);
            }
            else
            {
                _isReading = 0;
            }
        }
Exemple #14
0
        private void OnReport(HidReport report)
        {
            //if (IsAttached == false) { return; }

            if (report.Data.Length == 3)
            {
                Array.Copy(_newRadioPanelValue, _oldRadioPanelValue, 3);
                Array.Copy(report.Data, _newRadioPanelValue, 3);
                var hashSet = GetHashSetOfSwitchedKeys(_oldRadioPanelValue, _newRadioPanelValue);
                PZ69KnobChanged(hashSet);
                OnSwitchesChanged(hashSet);
                _isFirstNotification = false;
            }
            try
            {
                if (HIDSkeletonBase.HIDReadDevice != null && !Closed)
                {
                    Common.DebugP("Adding callback " + TypeOfSaitekPanel + " " + GuidString);
                    HIDSkeletonBase.HIDReadDevice.ReadReport(OnReport);
                }
            }
            catch (Exception ex)
            {
                Common.DebugP(ex.Message + "\n" + ex.StackTrace);
            }
        }
Exemple #15
0
        private void OnReport(HidReport report)
        {
            if (TypeOfPanel == GamingPanelEnum.TPM && report.Data.Length == 5)
            {
                Array.Copy(NewSaitekPanelValueTPM, OldSaitekPanelValueTPM, 5);
                Array.Copy(report.Data, NewSaitekPanelValueTPM, 5);
                var hashSet = GetHashSetOfChangedKnobs(OldSaitekPanelValueTPM, NewSaitekPanelValueTPM);
                if (hashSet.Count > 0)
                {
                    GamingPanelKnobChanged(!FirstReportHasBeenRead, hashSet);
                    UISwitchesChanged(hashSet);
                }

                FirstReportHasBeenRead = true;
            }
            else if (report.Data.Length == 3)
            {
                Array.Copy(NewSaitekPanelValue, OldSaitekPanelValue, 3);
                Array.Copy(report.Data, NewSaitekPanelValue, 3);
                var hashSet = GetHashSetOfChangedKnobs(OldSaitekPanelValue, NewSaitekPanelValue);
                if (hashSet.Count > 0)
                {
                    GamingPanelKnobChanged(!FirstReportHasBeenRead, hashSet);
                    UISwitchesChanged(hashSet);
                }

                FirstReportHasBeenRead = true;
            }

            StartListeningForPanelChanges();
        }
        static void Main(string[] args)
        {
            /*USBHIDDRIVER.USBInterface usbI = new USBInterface("vid_0483","pid_572b");
             * String[] list = usbI.getDeviceList();
             * Console.WriteLine(bytes.Count());
             * Console.WriteLine(usbI.Connect());
             * Console.ReadKey();
             *
             * Console.WriteLine(usbI.write(bytes));
             * Console.ReadKey();
             * usbI.Disconnect();*/
            _device = HidDevices.Enumerate(VendorId, ProductIds).FirstOrDefault();
            if (_device != null)
            {
                Console.ReadKey();
                _device.OpenDevice();
                HidReport hidReport = new HidReport(10);
                hidReport.ReportId = 4;
                hidReport.Data     = bytes;
                Console.WriteLine("Write Data:");

                hidReport.Data[0] = Byte.Parse(Console.ReadLine().ToString());
                Console.WriteLine("Report Builded");
                Console.ReadKey();

                bool sended = _device.WriteReport(hidReport);
                Console.WriteLine(sended + "");
                _device.ReadReport(OnReport);
                Console.ReadKey();
                _device.CloseDevice();
            }

            Console.WriteLine("Disconected");
            Console.ReadKey();
        }
        private bool WritePacketToBuffer(byte[] PacketData, int ChunkOffset, int ByteCount)
        {
            if (ByteCount > OUT_DATA_PER_PACKET)
            {
                return(false);   // Packet too big
            }
            if ((ChunkOffset + ByteCount) > CHUNK_WRAPPER_SIZE)
            {
                return(false);   // Packet goes past end of chunk
            }
            HidReport outReport = BootloaderDevice.CreateReport();

            outReport.ReportId = 0x00;
            outReport.Data[0]  = CMD_WRITE_TO_BUFFER;
            outReport.Data[1]  = (byte)(ChunkOffset & 0xFF);
            outReport.Data[2]  = (byte)((ChunkOffset >> 8) & 0xFF);
            outReport.Data[3]  = (byte)ByteCount;

            for (int i = 0; i < ByteCount; i++)
            {
                outReport.Data[i + 4] = PacketData[i];
            }

            if (BootloaderDevice.WriteReport(outReport) == false)
            {
                return(false);
            }
            return(WaitForStatus());
        }
Exemple #18
0
        private void OnReport(HidReport report)
        {
            if (!_isAttached)
            {
                return;
            }

            var data = report.Data;

            PrintOutputLine(string.Format("recv {0} bytes:", data.Length));

            string outputString = string.Empty;

            for (int i = 0; i < data.Length; i++)
            {
                outputString += string.Format("{0:X2} ", data[i]);
                if (i % 16 == 15 && i < data.Length)
                {
                    PrintOutputLine(outputString);
                    outputString = string.Empty;
                }
            }
            PrintOutputLine("\n");

            _device.ReadReport(OnReport);
        }
        public static void ReportToJoystick(ref Joystick joystick, HidReport hr)
        {
            if (hr != null)
            {
                for (int i = 0; i < joystick.Axes.Count; i++)
                {
                    joystick.Axes[i].RawValue = (short)(hr.Data[1 + 2 * i] << 8 | hr.Data[0 + 2 * i]);
                }

                for (int i = 0; i < 64; i++)
                {
                    joystick.PhysicalButtons[hr.Data[16] + i].State = (hr.Data[17 + ((i & 0xF8) >> 3)] & (1 << (i & 0x07))) > 0 ? true : false;
                }

                for (int i = 0; i < 5; i++)
                {
                    joystick.ShiftButtons[i].State = (hr.Data[25] & (1 << i)) > 0 ? true : false;
                }

                for (int i = 0; i < joystick.Axes.Count; i++)
                {
                    joystick.Axes[i].Value = (short)(hr.Data[27 + 2 * i] << 8 | hr.Data[26 + 2 * i]);
                }

                for (int i = 0; i < joystick.Povs.Count; i++)
                {
                    joystick.Povs[i].State = hr.Data[42 + i];
                }

                for (int i = 0; i < joystick.LogicalButtons.Count; i++)
                {
                    joystick.LogicalButtons[i].State = (hr.Data[46 + ((i & 0xF8) >> 3)] & (1 << (i & 0x07))) > 0 ? true : false;
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// Sends a command to the connected Blinky device and receive an answer to that command.
        /// </summary>
        /// <param name="cmd">Command to send.</param>
        /// <param name="args">Arguments to the command.</param>
        /// <returns>Answer to the command or NULL if no answer was received.</returns>
        private byte[] sendAndReceiveReport(Command cmd, params byte[] args)
        {
            bool lockTaken = false;

            if (!sendReport(cmd, false, ref lockTaken, args))
            {
                return(null);
            }

            HidReport receivedReport = new HidReport(reportSize);

            // Ensure that the answer from the device belongs to the previously sent command.
            // This is done by looping until the sync byte received from the device is the same
            // as the sent one.
            do
            {
                receivedReport = this.hidDevice.ReadReport((int)Timeout);
            } while (receivedReport.Data[7] != lastSyncByte);

            if (lockTaken)
            {
                Monitor.Exit(this.lockObject);
            }

            // Cut the answer from the received report. The first byte is the command to which
            // this answer belongs to and the last byte is the sync byte sent with the command.
            byte[] result = new byte[maxArgCount];
            Array.Copy(receivedReport.Data, 1, result, 0, maxArgCount);

            return(result);
        }
Exemple #21
0
        private void HID_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selected = ((ComboBox)sender).SelectedItem.ToString();

            if (selected.Equals(NotUsedText))
            {
                hid = null;
            }


            HidReport report = new HidReport(1);

            byte[] data = new byte[1];
            report.ReportId = 3;

            foreach (HidDevice x in HidDevices.Enumerate(VendorId, ProductId))
            {
                x.OpenDevice();
                x.ReadSerialNumber(out byte[] sb_buf);
                String sn = Encoding.Unicode.GetString(sb_buf);
                if (selected.Equals(sn))
                {
                    hid     = x;
                    data[0] = 7;
                }
                else
                {
                    data[0] = 0;
                }
                report.Data = data;
                x.WriteReportSync(report);
                x.CloseDevice();
            }
        }
Exemple #22
0
        public BL_Report(HidReport hidReport)
        {
            _status          = hidReport.ReadStatus;
            ReportId         = hidReport.ReportId;
            Exists           = hidReport.Exists;
            Valid_Packet_Len = hidReport.Data[1] + hidReport.Data[2] * 256;

            if (ReportId == 3)
            {
                Response_Tag   = hidReport.Data[3];
                FollowwithData = hidReport.Data[4] == 1;
                BL_Status      = hidReport.Data[7] + hidReport.Data[8] * 16 + hidReport.Data[9] * 256 + hidReport.Data[10] * 4096;
                if (Response_Tag == 160)
                {
                    Command_Respond_For = hidReport.Data[11] + hidReport.Data[12] * 16 + hidReport.Data[13] * 256 + hidReport.Data[14] * 4096;
                }
                else if (Response_Tag == 175)
                {
                    Valid_Data_count = hidReport.Data[11] + hidReport.Data[12] * 16 + hidReport.Data[13] * 256 + hidReport.Data[14] * 4096;
                    Array.Resize(ref _data, Valid_Data_count);
                    Array.Copy(hidReport.Data, 15, _data, 0, _data.Length); //BL Packet Has 2 Bytes of Report ID
                }
                else
                {
                    Array.Resize(ref _data, 0);
                }
            }
            else
            {
                Array.Resize(ref _data, Valid_Packet_Len);
                Array.Copy(hidReport.Data, 3, _data, 0, _data.Length); //BL Packet Has 2 Bytes of Report ID
            }
        }
        private bool WaitForStatus()
        {
            HidReport inReport = BootloaderDevice.ReadReport(1000);

            if (inReport.ReadStatus != HidDeviceData.ReadStatus.Success)
            {
                return(false);
            }
            if (inReport.Data.Length != 8)
            {
                return(false);
            }
            if (inReport.Data[0] == STS_BOOTLOADER_INFO)
            {
                BootLoaderVersion   = inReport.Data[1];
                BootLoaderErrorCode = inReport.Data[3];
                if (BootLoaderErrorCode != 0)
                {
                    MsgBox.AppendText("Bootloader reported error:" + BootLoaderErrorCode + "\n");
                    return(false);
                }
            }
            else
            {
                MsgBox.AppendText("Bootloader status packet=" + inReport.Data[0] + "\n");
                return(false);
            }
            return(true);
        }
Exemple #24
0
 private void ReadProcess(HidReport report)
 {
     try
     {
         BeginInvoke(new ReadHandlerDelegate(ReadHandler), new object[] { report });
     }
     catch { }
 }
Exemple #25
0
        public static CardData Create(HidReport report)
        {
            var data  = new CardData();
            var bytes = report.Data.SkipWhile(b => b != 1).Skip(2).TakeWhile(b => b != 27);

            data._bytes = bytes.Take(bytes.Count() - 1).ToArray();
            return(data);
        }
        public Report(HidReport hidReport)
        {
            _status  = hidReport.ReadStatus;
            ReportId = hidReport.ReportId;
            Exists   = hidReport.Exists;

            _data = hidReport.Data;
        }
Exemple #27
0
 private void ReadHandler(HidReport report)
 {
     listBox1.Items.Add("In Report Received: " + ByteToString(report.Data));
     if (SelectedDevice != null && SelectedDevice.IsConnected == true)
     {
         SelectedDevice.ReadReport(ReadcallBack);
     }
 }
Exemple #28
0
        public void PacketReceivedEventHandler(HidReport report)
        {
            HidReport hr = report;

            byte[] fileArray;
            byte[] buffer = new byte[63];

            if (hr.ReportId == (byte)ReportID.FIRMWARE_REPORT)
            {
                ushort cnt = (ushort)(hr.Data[0] << 8 | hr.Data[1]);

                if ((cnt & 0xF000) == 0xF000) // status packet
                {
                    if (cnt == 0xF001)        // firmware size error
                    {
                        SizeError();
                    }
                    else if (cnt == 0xF002) // CRC error
                    {
                        CrcError();
                    }
                    else if (cnt == 0xF003) // flash erase error
                    {
                        EraseError();
                    }
                    else if (cnt == 0xF000) // OK
                    {
                        Finished();
                    }
                }
                else
                {
                    Console.WriteLine("Firmware packet requested: {0}", cnt);

                    fileArray = File.ReadAllBytes(_filepath);

                    buffer[0] = (byte)(cnt >> 8);
                    buffer[1] = (byte)(cnt & 0xFF);
                    buffer[2] = 0;
                    if (cnt * 60 < fileArray.Length)
                    {
                        Array.ConstrainedCopy(fileArray, (cnt - 1) * 60, buffer, 3, 60);
                        UpdatePercent = (((cnt - 1) * 60 * 100 / fileArray.Length));

                        Hid.ReportSend((byte)ReportID.FIRMWARE_REPORT, buffer);
                        Console.WriteLine("Firmware packet sent: {0}", cnt);
                    }
                    else
                    {
                        Array.ConstrainedCopy(fileArray, (cnt - 1) * 60, buffer, 3, fileArray.Length - (cnt - 1) * 60);
                        UpdatePercent = 0;

                        Hid.ReportSend((byte)ReportID.FIRMWARE_REPORT, buffer);
                        Console.WriteLine("Firmware packet sent: {0}", cnt);
                    }
                }
            }
        }
Exemple #29
0
        private void SendData(byte[] data)
        {
            var report = new HidReport(data.Length)
            {
                Data = data
            };

            _device.WriteReport(report);
        }
Exemple #30
0
        static public void ReportSend(HidReport report)
        {
            HidReport hr = report;

            hidDevice.WriteReport(hr, 1000000);

            // raise event
            PacketSent?.Invoke(hr);
        }
        protected override void ProcessReadResult(HidReport result)
        {
            base.ProcessReadResult(result);

            var eventMask = Convert.ToInt32(result.Data.Take(2));

            if (EventFunctionMap.ContainsKey(eventMask))
                EventFunctionMap[eventMask](this, result.Data);

        }
Exemple #32
0
        private void ReportData(HidReport Report)
        {
            clsUSBData CardData = new clsUSBData(Report.Data, 3);
            if (!_CardOpened)
                return;

            if (!CardData.Error)
            {
                // TODO: Add Input
            }
            Card.ReadReport(OnReport);
        }
Exemple #33
0
 private void tmrRequestButtonStatus_Tick(object sender, EventArgs e)
 {
     LogEvent("Requesting Card Input Status", "I001", clsEventLogType.EventLogType.Warning);
     Card.Open();
     HidReport SerialNumber = new HidReport(2);
     SerialNumber.Data[0] = 0xFF;
     SerialNumber.Data[1] = 20;
     Card.WriteReport(SerialNumber);
 }
Exemple #34
0
        private void ReportData(HidReport Report)
        {
            // Check report to see what to do with the data
            clsUSBData CardData = new clsUSBData(Report.Data, 3);
            if (!_CardOpened)
                return;

            if (!CardData.Error)
            {
                byte[] Data = CardData.USBDeviceData;
                switch (Data[0])
                {
                    case 0:  // Button Press
                        int ButtonP = Convert.ToInt32(Data[1]);
                        int ValueP = Convert.ToInt32(Data[2]);
                        bool ButtonValueP;
                        if (ValueP == 0)
                            ButtonValueP = false;
                        else
                            ButtonValueP = true;

                        HandleButtonStatus(ButtonP, ButtonValueP);
                        if (!chkDebugEnabled.Checked)
                            HandleButton(ButtonP, ButtonValueP);
                        break;

                    case 1:  // Button Status
                        int Button = Convert.ToInt32(Data[1]);
                        int Value = Convert.ToInt32(Data[2]);
                        bool ButtonValue;
                        if (Value == 0)
                            ButtonValue = false;
                        else
                            ButtonValue = true;

                        HandleButtonStatus(Button, ButtonValue);
                        tmrRequestButtonStatus.Enabled = false;
                        break;

                    case 253:  // Firmware Version

                        break;

                    case 254:  // Model Revision

                        break;

                    case 255:  // Serial Number

                        break;

                    default:  // oh no...
                        break;
                }
            }
            Card.ReadReport(OnReport);
        }
Exemple #35
0
 private void OnReport(HidReport Report)
 {
     if (InvokeRequired)
         Invoke(new SetReportDataParm(ReportData), Report);
     else
         ReportData(Report);
 }
Exemple #36
0
        private void bbtnRefreshInputs_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            if (chkUSBConnected.Checked)
            {
                LogEvent("Requesting Card Input Status", "I001", clsEventLogType.EventLogType.Warning);

                HidReport SerialNumber = new HidReport(2);
                SerialNumber.Data[0] = 0xFF;
                SerialNumber.Data[1] = 20;
                Card.WriteReport(SerialNumber);
            }
            else
            {
                LogEvent("USB not connected, unable to request input status", "I002", clsEventLogType.EventLogType.Error);
                XtraMessageBox.Show("USB not connected, unable to request input status", "Refresh Inputs", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #37
0
 private void bbtnTurnOnPSU_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
 {
     HidReport SerialNumber = new HidReport(2);
     SerialNumber.Data[0] = 0xFF;
     SerialNumber.Data[1] = 31;
     Card.WriteReport(SerialNumber);
 }
Exemple #38
0
        private void ReportData(HidReport Report)
        {
            // Check report to see what to do with the data
            clsUSBData CardData = new clsUSBData(Report.Data, 3);
            if (!_CardOpened)
                return;

            if (!CardData.Error)
            {
                byte[] Data = CardData.USBDeviceData;
                switch (Data[0])
                {
                    case 0:    // Power Button Pressed
                        int ButtonValueP = Data[2];
                        bool PSUEnabledP;
                        if (ButtonValueP == 0)
                            PSUEnabledP = false;
                        else
                            PSUEnabledP = true;

                        LogEvent("Manual Power Button Pressed, Value: " + PSUEnabledP, "E002", clsEventLogType.EventLogType.Info);
                        break;

                    case 1:    // Power Supply Reported its Status
                        int ButtonValue = Data[2];
                        bool PSUEnabled;
                        if (ButtonValue == 0)
                            PSUEnabled = false;
                        else
                            PSUEnabled = true;

                        LogEvent("Power Supply Value: " + PSUEnabled, "E001", clsEventLogType.EventLogType.Info);
                        tmrRequestPSUStatus.Enabled = false;
                        break;

                    case 253:  // Firmware Version

                        break;

                    case 254:  // Model Revision

                        break;

                    case 255:  // Serial Number

                        break;

                    default:  // oh no...
                        break;
                }
            }
            Card.ReadReport(OnReport);
        }
Exemple #39
0
        private int getUSBDeviceSerial(HidDevice Device)
        {
            int CardSerial = -1;
            HidReport Report;
            Device.Open();

            do
            {
                Application.DoEvents();     // Prevent App Freezing.
            } while (Device.IsConnected == false);

            // Ask for serial number
            HidReport SerialNumber = new HidReport(3);
            SerialNumber.Data[0] = 0xFF;
            SerialNumber.Data[1] = 0x01;
            Device.WriteReport(SerialNumber);

            Report = Device.ReadReport();

            if (Report.Exists)
            {
                int Serial1 = Convert.ToInt32(Report.Data[1]);
                int Serial2 = Convert.ToInt32(Report.Data[2]);

                CardSerial = (255 * Serial1) + Serial2;
            }
            Device.Close();
            return CardSerial;
        }
Exemple #40
0
        private void initLED()
        {
            for (int i = 0; i < 24; i++)
            {
                bool outputenabled = (bool)gridView1.GetRowCellValue(i, "OutputStatus");

                HidReport SetLED = new HidReport(3);
                if (outputenabled)
                    SetLED.Data[0] = 0x0A;
                else
                    SetLED.Data[0] = 0x0B;
                SetLED.Data[1] = Convert.ToByte(i);

                Card.WriteReport(SetLED);

                _dtOutputs.Rows[i]["value"] = outputenabled;
                LogEvent("Updating LED Value - LED #" + (i + 1) + " VALUE: " + outputenabled, "X", clsEventLogType.EventLogType.Info);
            }
        }
        private void tmrCheckUSB_Tick(object sender, EventArgs e)
        {
            //open and send message
            HidDevice[] Devices = HidDevices.Enumerate(_usbVendorID, _usbDeviceID);

            if (Devices != null && Devices.Length > 0)
            {
                foreach (HidDevice SSTCard in Devices)
                {
                    if (!SSTCard.IsOpen)
                    {
                        if (!_parent.usbGUIDExist(SSTCard.DevicePath))
                        {
                            if (!usbGUIDExist(SSTCard.DevicePath))
                            {
                                SSTCard.Open();

                                int tryCount = 0;
                                HidReport Report;
                                do
                                {
                                    // Ask for serial number
                                    HidReport SerialNumber = new HidReport(2);
                                    SerialNumber.Data[0] = 0xFF;
                                    SerialNumber.Data[1] = 0x01;
                                    SSTCard.WriteReport(SerialNumber);

                                    Report = SSTCard.ReadReport();

                                    if (tryCount == 50000)
                                    {
                                        // Prevent Freezing
                                        return;
                                    }

                                    tryCount++;
                                } while (!Report.Exists);

                                //Serial Number Report Returned
                                int Serial1 = Convert.ToInt32(Report.Data[1]);
                                int Serial2 = Convert.ToInt32(Report.Data[2]);
                                if (_CardSerialNumber == (255 * Serial1) + Serial2)
                                {
                                    tmrCheckUSB.Enabled = false;
                                    Card = SSTCard;
                                    EnableCard();
                                }
                                else
                                {
                                    LogEvent("Ignoring Card: " + SSTCard.DevicePath, "X004", clsEventLogType.EventLogType.Warning, false);
                                    usbAddGUID(SSTCard.DevicePath);
                                    SSTCard.Close();
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #42
0
        private void initSelfTest()
        {
            if (chkUSBConnected.Checked)
            {
                if (_selftest == 0)
                {
                    for (int i = 0; i < 24; i++)
                    {
                        HidReport SetLED = new HidReport(3);
                        SetLED.Data[0] = 0x0A;
                        SetLED.Data[1] = Convert.ToByte(i);

                        Card.WriteReport(SetLED);
                    }
                    _selftest = 1;
                }
                else
                {
                    initLED();
                    _selftest = 0;
                }
            }
        }
Exemple #43
0
        private void tmrSetOutputs_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i < 24; i++)
            {
                // Check to see if we need to set the output
                bool oldstatus = (bool)_dtOutputs.Rows[i]["value"];
                bool outputenabled = (bool)gridView1.GetRowCellValue(i, "OutputStatus");

                if (oldstatus != outputenabled)
                {
                    HidReport SetLED = new HidReport(3);
                    if (outputenabled)
                        SetLED.Data[0] = 0x0A;
                    else
                        SetLED.Data[0] = 0x0B;
                    SetLED.Data[1] = Convert.ToByte(i);

                    Card.WriteReport(SetLED);

                    _dtOutputs.Rows[i]["value"] = outputenabled;
                    LogEvent("Updating LED Value - LED #" + (i + 1) + " VALUE: " + outputenabled, "X001", clsEventLogType.EventLogType.Info);

                    // Update database with new value
                    AnalogOutputConfiguration obj = Session.DefaultSession.FindObject<AnalogOutputConfiguration>(CriteriaOperator.Parse(String.Format("CardModel == '{0}' AND CardRevision == '{1}' AND CardSerial == {2} AND Output == {3}", _CardModel, _CardRevision, _CardSerialNumber, i + 1)));
                    obj.OutputStatus = outputenabled;
                    obj.Save();
                }
            }
        }