コード例 #1
0
ファイル: HID.cs プロジェクト: sam210723/moRFctrl
        /// <summary>
        /// Begin communication with moRFeus
        /// </summary>
        private void ConfigDevice()
        {
            // Report stream opened
            if (moRFeusDevice.TryOpen(out moRFeusStream))
            {
                moRFeusStream.ReadTimeout = Timeout.Infinite;

                // HIDSharp setup
                reportBuffer = new byte[moRFeusDevice.GetMaxInputReportLength()];
                ReportDescriptor reportDescriptor = moRFeusDevice.GetReportDescriptor();
                reportReceiver = reportDescriptor.CreateHidDeviceInputReceiver();

                // Receive event handling
                //reportReceiver.Received += ReportReceived;
                reportReceiver.Start(moRFeusStream);

                // Disconnect event handling
                moRFeusStream.Closed += new EventHandler(Disconnected);

                // Indicate successful connection
                Tools.Debug("Connected to moRFeus");
                Program.MainClass.StatusMessage = "Connected to moRFeus";
                Program.MainClass.EnableUI();
                moRFeusOpen = true;

                // Initial polling of device values
                Task.Delay(10).ContinueWith(t => Program.MainClass.PollDevice());
            }
        }
コード例 #2
0
ファイル: HID.cs プロジェクト: N5FPP/moRFctrl
        /// <summary>
        /// Begin communication with moRFeus
        /// </summary>
        private void ConfigDevice()
        {
            HidStream hidStream;

            if (moRFeusDevice.TryOpen(out hidStream))
            {
                moRFeusStream = hidStream;
                Console.WriteLine("Connected to moRFeus");
                Program.MainClass.StatusMessage = "Connected to moRFeus";
                moRFeusStream.ReadTimeout       = Timeout.Infinite;


                byte[]           inputReportBuffer = new byte[moRFeusDevice.GetMaxInputReportLength()];
                ReportDescriptor reportDescriptor  = moRFeusDevice.GetReportDescriptor();
                HidSharp.Reports.Input.HidDeviceInputReceiver inputReceiver = reportDescriptor.CreateHidDeviceInputReceiver();

                inputReceiver.Received += (sender, e) =>
                {
                    Report report;
                    while (inputReceiver.TryRead(inputReportBuffer, 0, out report))
                    {
                        moRFeus.ParseReport(inputReportBuffer);
                    }
                };
                inputReceiver.Start(hidStream);

                moRFeusStream.Closed += new EventHandler(Disconnected);
                moRFeusOpen           = true;

                // Initial polling of device values
                Task.Delay(10).ContinueWith(t => Program.MainClass.PollDevice());
            }
        }
コード例 #3
0
ファイル: ReportRepository.cs プロジェクト: xixiky/xms
        private string GetChartDataSqlString(ReportDescriptor report, IQueryResolver queryTranslator)
        {
            //drillthrough, aggregation
            var columnField = report.CustomReport.Chart.ColumnAxis.Field;
            var nameField   = GetFieldValueName(queryTranslator, columnField);

            if (!columnField.IsCaseInsensitiveEqual(nameField))
            {
                nameField = "," + nameField;
            }
            else
            {
                nameField = string.Empty;
            }
            columnField = GetGroupingName(report, queryTranslator, columnField);
            var sql     = "SELECT ";
            var orderby = "";

            if (report.CustomReport.Filter != null)
            {
                sql    += " TOP " + report.CustomReport.Filter.Value;
                orderby = " ORDER BY " + report.CustomReport.Filter.Field + (report.CustomReport.Filter.Operator == FilterOperator.TopN ? " DESC" : "");
            }
            sql += columnField + " AS " + report.CustomReport.Chart.ColumnAxis.Field + nameField;
            foreach (var item in report.CustomReport.Chart.ValueAxes)
            {
                var column = report.CustomReport.Columns.Find(n => n.Field.IsCaseInsensitiveEqual(item.Field));
                sql += string.Format(",{0} AS {1}", DataFieldExpressionHelper.GetAggregationExpression(column.SummaryValue.Value, item.Field), item.Field);
            }
            sql += string.Format(" FROM ({0}) a GROUP BY {1} {2}", queryTranslator.ToSqlString(), columnField + nameField, orderby);
            return(sql);
        }
コード例 #4
0
 public HidDeviceInputReceiver(int maxInputReportLength, ReportDescriptor reportDescriptor = null)
 {
     _maxInputReportLength = maxInputReportLength;
     _buffer           = new byte[_maxInputReportLength * 16];
     _reportDescriptor = reportDescriptor;
     _syncRoot         = new object();
     _waitHandle       = new ManualResetEvent(true);
 }
コード例 #5
0
 public HidDeviceInputReceiver(ReportDescriptor reportDescriptor)
 {
     Throw.If.Null(reportDescriptor, "reportDescriptor");
     _maxInputReportLength = reportDescriptor.MaxInputReportLength;
     _buffer           = new byte[_maxInputReportLength * 16];
     _reportDescriptor = reportDescriptor;
     _syncRoot         = new object();
     _waitHandle       = new ManualResetEvent(true);
 }
コード例 #6
0
            public override void CommOpen(Bsl430NetDevice device)
            {
                try
                {
                    Bsl430NetDevice _device = device;

                    if (device == null)
                    {
                        _device = DefaultDevice;
                    }

                    if (_device == null || _device.Name == "")
                    {
                        throw new Bsl430NetException(461);
                    }

                    if (!devices.ContainsKey(_device.Name.ToLower()))
                    {
                        Status stat = Scan <USB_HID_Device>(out _);
                        if (!stat.OK)
                        {
                            throw new Bsl430NetException(stat.Error);
                        }
                    }

                    if (!devices.TryGetValue(_device.Name.ToLower(), out USB_HID_Device dev))
                    {
                        throw new Bsl430NetException(462);
                    }

                    DeviceList.Local.GetHidDeviceOrNull(dev.Vid,
                                                        dev.Pid)?.TryOpen(out usb);

                    if (usb == null)
                    {
                        throw new Bsl430NetException(610);
                    }
                    else
                    {
                        max_output_len   = usb.Device.GetMaxOutputReportLength();
                        max_input_len    = usb.Device.GetMaxInputReportLength();
                        usb.ReadTimeout  = Timeout.Infinite;
                        reportDescriptor = usb.Device.GetReportDescriptor();
                        inputReceiver    = reportDescriptor.CreateHidDeviceInputReceiver();
                        inputReceiver.Start(usb);
                    }
                }
                catch (Exception ex) { throw new Bsl430NetException(611, ex); }
            }
コード例 #7
0
ファイル: ReportRepository.cs プロジェクト: xixiky/xms
        public DataTable GetData(ReportDescriptor report, IQueryResolver queryTranslator, FilterExpression filter = null)
        {
            if (filter != null)
            {
                //设置过滤条件中特殊字段的名称
                //foreach (var item in filter.Conditions)
                //{
                //    item.AttributeName = GetFieldValueName(queryTranslator, item.AttributeName);
                //}
                report.CustomReport.Query.Criteria = filter;//.AddFilter(filter);
            }
            var sql = queryTranslator.ToSqlString();
            //获取数据
            var ds = new DataVisitor(DbContext).ExecuteQueryDataSet(sql, queryTranslator.Parameters.Args.ToArray());

            return(ds.Tables[0]);
        }
コード例 #8
0
 public RawInputDevice(HidDevice device, ReportDescriptor reportDescriptor, DeviceItem deviceItem, HidStream hidStream, string uniqueId)
 {
     this.device       = device;
     inputReportBuffer = new byte[device.GetMaxInputReportLength()];
     inputReceiver     = reportDescriptor.CreateHidDeviceInputReceiver();
     inputParser       = deviceItem.CreateDeviceItemInputParser();
     inputReceiver.Start(hidStream);
     DisplayName           = device.GetProductName();
     UniqueId              = uniqueId;
     InterfacePath         = device.DevicePath;
     HardwareID            = IdHelper.GetHardwareId(InterfacePath);
     inputChangedEventArgs = new DeviceInputChangedEventArgs(this);
     sources = reportDescriptor.InputReports.SelectMany(ir => ir.DataItems)
               .SelectMany(di => di.Usages.GetAllValues())
               .Select(u => (Usage)u)
               .SelectMany(u => RawInputSource.FromUsage(this, u))
               .ToArray();
     readThreadContext = ThreadCreator.CreateLoop($"{DisplayName} RawInput reader", ReadLoop, 1).Start();
 }
コード例 #9
0
ファイル: ReportRepository.cs プロジェクト: xixiky/xms
        public string GetGroupingName(ReportDescriptor report, IQueryResolver queryTranslator, string field, bool includeAlias = false)
        {
            var groupObj = report.CustomReport.Groupings.Find(n => n.Field.IsCaseInsensitiveEqual(field));

            if (groupObj != null && groupObj.DateGrouping.HasValue)
            {
                if (includeAlias)
                {
                    var alias = queryTranslator.AttributeAliasList.Find(n => n.Alias.IsCaseInsensitiveEqual(field));
                    if (alias != null)
                    {
                        field = alias.EntityAlias + "." + alias.Name;
                    }
                }
                field = DataFieldExpressionHelper.GetDateGroupingExpression(groupObj.DateGrouping.Value, field);
            }
            else if (groupObj != null && !groupObj.DateGrouping.HasValue)
            {
                field = GetFieldValueName(queryTranslator, field);
            }
            return(field);
        }
コード例 #10
0
        public Digitizer(double physicalWidth, double physicalHeight, Vector?dpi = null)
        {
            // 96 DPI is the standard 100% scale
            _dpi    = dpi ?? new Vector(192, 192);
            _scale  = 96 / _dpi.X;
            _width  = physicalWidth * _scale;
            _height = physicalHeight * _scale;

            _prevTappedSlotIndex = -1;
            _prevReports         = new TouchReport[11];
            for (int i = 0; i < 11; i++)
            {
                _prevReports[i] = new TouchReport(0, 32767, false);
            }

            // Discover DFR digitizer device
            _digitizer = DeviceList.Local.GetHidDeviceOrNull(0x05ac, 0x8302);
            if (_digitizer == null)
            {
                throw new Exception("iBridge HID digitizer not found");
            }

            _reportDescr = _digitizer.GetReportDescriptor();
        }
コード例 #11
0
        private void HidHandler_DoWork(object sender, DoWorkEventArgs e)
        {
            Console.Write("Opening device...");

            ReportDescriptor reportDescriptor = selectedDevice.GetReportDescriptor();

            foreach (DeviceItem deviceItem in reportDescriptor.DeviceItems)
            {
                HidStream hidStream;
                if (selectedDevice.TryOpen(out hidStream))
                {
                    Console.WriteLine("OK");
                    hidStream.ReadTimeout = Timeout.Infinite;

                    using (hidStream) {
                        var inputReportBuffer = new byte[selectedDevice.GetMaxInputReportLength()];
                        var inputReceiver     = reportDescriptor.CreateHidDeviceInputReceiver();
                        var inputParser       = deviceItem.CreateDeviceItemInputParser();

                        inputReceiver.Start(hidStream);

                        while (!HidHandler.CancellationPending)
                        {
                            if (inputReceiver.WaitHandle.WaitOne(1))
                            {
                                if (!inputReceiver.IsRunning)
                                {
                                    Console.WriteLine("Device disconnected!");
                                    break;
                                }

                                Report report;
                                byte[] buffer = new byte[255];
                                while (inputReceiver.TryRead(inputReportBuffer, 0, out report))
                                {
                                    if (inputParser.TryParseReport(inputReportBuffer, 0, report))
                                    {
                                        AirFrame af = new AirFrame(inputReportBuffer);

                                        string address               = BitConverter.ToString(af.address).Replace("-", ":");
                                        string pid                   = af.pid.ToString();
                                        string ch                    = af.rf_channel.ToString();
                                        string len                   = af.payloadLength.ToString();
                                        string payload               = af.payloadLength != 0 ? BitConverter.ToString(af.payload) : "<EMPTY>";
                                        string decrpytedPayload      = "";
                                        byte[] decryptedPayloadBytes = null;

                                        try {
                                            if (autoDecrypt)
                                            {
                                                af.DecryptKeyboardFrame(deviceKey);
                                                decryptedPayloadBytes = af.decryptedPayload;
                                                decrpytedPayload      = BitConverter.ToString(decryptedPayloadBytes);
                                            }
                                        } catch {
                                            decrpytedPayload = "";
                                        }

                                        frameList.Add(af);

                                        try {
                                            if (autoDecrypt && decryptedPayloadBytes != null)
                                            {
                                                KeyboardLayout kl = new KeyboardLayout();

                                                textBoxKeys.Invoke(new Action(() => {
                                                    textBoxKeys.Text += kl.ToComboKeyPress(decryptedPayloadBytes);
                                                }));
                                            }
                                        } catch {
                                        }


                                        listView1.Invoke(new Action(() => {
                                            listView1.Items.Insert(0, new ListViewItem(new[] { address, pid, ch, len, payload, decrpytedPayload }));
                                        }));
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Fail");
                }
            }
        }
コード例 #12
0
        // ==========================================================================================
        public static void PollReports()
        {
            ReportDescriptor reportDescriptor = device.GetReportDescriptor();

            foreach (DeviceItem deviceItem in reportDescriptor.DeviceItems)
            {
                if (device.TryOpen(out HidStream hidStream))
                {
                    hidStream.ReadTimeout = Timeout.Infinite;

                    using (hidStream)
                    {
                        byte[] inputReportBuffer = new byte[device.GetMaxInputReportLength()];
                        HidSharp.Reports.Input.HidDeviceInputReceiver inputReceiver = reportDescriptor.CreateHidDeviceInputReceiver();
                        HidSharp.Reports.Input.DeviceItemInputParser  inputParser   = deviceItem.CreateDeviceItemInputParser();
                        inputReceiver.Start(hidStream);

                        int startTime = Environment.TickCount;
                        while (true)
                        {
                            if (!inputReceiver.IsRunning)
                            {
                                break;
                            }              // Disconnected?

                            Report report; // Periodically check if the receiver has any reports.
                            while (inputReceiver.TryRead(inputReportBuffer, 0, out report))
                            {
                                bool first = true;
                                // Parse the report if possible.
                                // This will return false if (for example) the report applies to a different DeviceItem.
                                if (inputParser.TryParseReport(inputReportBuffer, 0, report))
                                {
                                    while (inputParser.HasChanged || first)
                                    {
                                        first = false;
                                        int changedIndex = inputParser.GetNextChangedIndex();
                                        try
                                        {
                                            DataValue previousDataValue = inputParser.GetPreviousValue(changedIndex);

                                            DataValue dataValue = inputParser.GetValue(changedIndex);
                                            string    Type      = ((Usage)dataValue.Usages.FirstOrDefault()).ToString();
                                            status    _status   = new status((double)previousDataValue.GetPhysicalValue(),
                                                                             (double)dataValue.GetPhysicalValue());

                                            lock (EventBufferLock)
                                            {
                                                if (Type.Contains("Button"))
                                                {
                                                    int btn = Convert.ToByte(Type.Last()) - 49;
                                                    if (_status.newval == 1)
                                                    {
                                                        CurrentButtons = (byte)(CurrentButtons | (1 << btn));
                                                        lastbtn        = btn;
                                                    }
                                                    else
                                                    {
                                                        CurrentButtons = (byte)(CurrentButtons & ~(1 << btn));
                                                    }
                                                }
                                                try
                                                {
                                                    AxisAndButtons[Type] = _status;
                                                }
                                                catch (Exception)
                                                {
                                                    AxisAndButtons.Add(Type, _status);
                                                }
                                            }
                                        }
                                        catch (Exception)
                                        { }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
ファイル: ReportRepository.cs プロジェクト: xixiky/xms
        public DataTable GetChartData(ReportDescriptor report, IQueryResolver queryTranslator)
        {
            var ds = new DataVisitor(DbContext).ExecuteQueryDataSet(GetChartDataSqlString(report, queryTranslator), queryTranslator.Parameters.Args.ToArray());

            return(ds.Tables[0]);
        }