예제 #1
0
        public HidReport(int reportSize, HidDeviceData deviceData)
        {
            _status = deviceData.Status;

            Array.Resize(ref _data, reportSize - 1);

            if ((deviceData.Data != null))
            {

                if (deviceData.Data.Length > 0)
                {
                    _reportId = deviceData.Data[0];
                    Exists = true;

                    if (deviceData.Data.Length > 1)
                    {
                        var dataLength = reportSize - 1;
                        if (deviceData.Data.Length < reportSize - 1) dataLength = deviceData.Data.Length;
                        Array.Copy(deviceData.Data, 1, _data, 0, dataLength);
                    }
                }
                else Exists = false;
            }
            else Exists = false;
        }
예제 #2
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
            }
        }
예제 #3
0
        public HidReport(int reportSize, HidDeviceData deviceData)
        {
            _status = deviceData.Status;

            Array.Resize(ref _data, reportSize - 1);

            if ((deviceData.Data != null))
            {
                if (deviceData.Data.Length > 0)
                {
                    _reportId = deviceData.Data[0];
                    Exists    = true;

                    if (deviceData.Data.Length > 1)
                    {
                        var dataLength = reportSize - 1;
                        if (deviceData.Data.Length < reportSize - 1)
                        {
                            dataLength = deviceData.Data.Length;
                        }
                        Array.Copy(deviceData.Data, 1, _data, 0, dataLength);
                    }
                }
                else
                {
                    Exists = false;
                }
            }
            else
            {
                Exists = false;
            }
        }
예제 #4
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            LastReadStatus = HidDeviceData.ReadStatus.Success;
            if (string.IsNullOrEmpty(cboDevices.Text))
            {
                txtConsole.Text += Environment.NewLine + "Please choose device";
            }
            else
            {
                if (btnConnect.Content.ToString() == "Connect")
                {
                    if (ConnectHidDevie(cboDevices.Text))
                    {
                        btnConnect.Content          = "Disconnect";
                        cboDevices.IsHitTestVisible = false;
                        cboDevices.Focusable        = false;

                        btnSendData.IsEnabled = true;
                        btnReadData.IsEnabled = true;
                    }
                }
                else
                {
                    if (DisconnectHidDevie(cboDevices.Text))
                    {
                        btnConnect.Content          = "Connect";
                        cboDevices.IsHitTestVisible = true;
                        cboDevices.Focusable        = true;

                        btnSendData.IsEnabled = false;
                        btnReadData.IsEnabled = false;
                    }
                }
            }
        }
예제 #5
0
        private void btnReadData_Click(object sender, RoutedEventArgs e)
        {
            var chosenDev = CurrentHIDs[cboDevices.Text];
            var reading   = chosenDev.Read(100);

            LastReadStatus = reading.Status;

            if (reading.Status == HidDeviceData.ReadStatus.Success)
            {
                txtConsole.Text += Environment.NewLine + "Read successful";

                var dataList = reading.Data.ToList();
                dataList.RemoveAt(0);

                if (chk.IsChecked == true)
                {
                    txtReadData.Text = BitConverter.ToString(dataList.ToArray());
                }
                else
                {
                    txtReadData.Text = Encoding.ASCII.GetString(dataList.ToArray(), 0, dataList.Count);
                }
            }
            else if (reading.Status == HidDeviceData.ReadStatus.NoDataRead)
            {
                txtConsole.Text += Environment.NewLine + "No data to read";
            }
        }
        public Report(HidReport hidReport)
        {
            _status  = hidReport.ReadStatus;
            ReportId = hidReport.ReportId;
            Exists   = hidReport.Exists;

            _data = hidReport.Data;
        }
예제 #7
0
        public Report(HidReport hidReport)
        {
            _status  = hidReport.ReadStatus;
            ReportId = hidReport.ReportId;
            Exists   = hidReport.Exists;

            if (hidReport.Data.Length > 0)
            {
                Length = hidReport.Data[0];
            }
            if (hidReport.Data.Length > 1)
            {
                AimSymbologyId0 = hidReport.Data[1];
            }
            if (hidReport.Data.Length > 2)
            {
                AimSymbologyId1 = hidReport.Data[2];
            }
            if (hidReport.Data.Length > 3)
            {
                AimSymbologyId2 = hidReport.Data[3];
            }

            if (hidReport.Data.Length > Length + 3)
            {
                Array.Resize(ref _data, Length);
                Array.Copy(hidReport.Data, 4, _data, 0, Length);
            }

            if (hidReport.Data.Length > 60)
            {
                HhpSymbologyId = hidReport.Data[60];
            }
            if (hidReport.Data.Length > 61)
            {
                Reserved = hidReport.Data[61];
            }
            if (hidReport.Data.Length > 62)
            {
                MoreData = hidReport.Data[62] == 1;
            }
        }
예제 #8
0
        public SDP_Report(HidReport hidReport)
        {
            _status  = hidReport.ReadStatus;
            ReportId = hidReport.ReportId;
            Exists   = hidReport.Exists;

            if (ReportId == 3)
            {
                if (hidReport.Data.Length > 3)
                {
                    if (hidReport.Data[0] == 0x12 && hidReport.Data[1] == 0x34 && hidReport.Data[2] == 0x34 && hidReport.Data[3] == 0x12)
                    {
                        PortStatus = false;
                    }
                    if (hidReport.Data[0] == 0x56 && hidReport.Data[1] == 0x78 && hidReport.Data[2] == 0x78 && hidReport.Data[3] == 0x56)
                    {
                        PortStatus = true;
                    }
                }
            }
            else if (ReportId == 4)
            {
                if (hidReport.Data[0] == 0x88 && hidReport.Data[1] == 0x88 && hidReport.Data[2] == 0x88 && hidReport.Data[3] == 0x88)
                {
                    FileWriteComplete = true;
                }
                else if (hidReport.Data[0] == 0x12 && hidReport.Data[1] == 0x8A && hidReport.Data[2] == 0x8A && hidReport.Data[3] == 0x12)
                {
                    WriteSuccess = true;
                }
                else if (hidReport.Data[0] == 0x89 && hidReport.Data[1] == 0x23 && hidReport.Data[2] == 0x23 && hidReport.Data[3] == 0x89)
                {
                    WriteSuccess = false;
                }
                else
                {
                    Array.Resize(ref _data, hidReport.Data.Length);
                    Array.Copy(hidReport.Data, 0, _data, 0, hidReport.Data.Length);
                }
            }
        }
예제 #9
0
        public Report(HidReport hidReport)
        {
            _status = hidReport.ReadStatus;
            ReportId = hidReport.ReportId;
            Exists = hidReport.Exists;

            if (hidReport.Data.Length > 0) Length = hidReport.Data[0];
            if (hidReport.Data.Length > 1) AimSymbologyId0 = hidReport.Data[1];
            if (hidReport.Data.Length > 2) AimSymbologyId1 = hidReport.Data[2];
            if (hidReport.Data.Length > 3) AimSymbologyId2 = hidReport.Data[3];

            if (hidReport.Data.Length > Length + 3)
            {
                Array.Resize(ref _data, Length);
                Array.Copy(hidReport.Data, 4, _data, 0, Length);
            }

            if (hidReport.Data.Length > 60) HhpSymbologyId = hidReport.Data[60];
            if (hidReport.Data.Length > 61) Reserved = hidReport.Data[61];
            if (hidReport.Data.Length > 62) MoreData = hidReport.Data[62] == 1;
        }
예제 #10
0
        protected HidDeviceData ReadData(int timeout)
        {
            byte[] array = new byte[0];
            HidDeviceData.ReadStatus status = HidDeviceData.ReadStatus.NoDataRead;
            if (_deviceCapabilities.InputReportByteLength > 0)
            {
                uint lpNumberOfBytesRead = 0u;
                array = CreateInputBuffer();
                if (_deviceReadMode != DeviceMode.Overlapped)
                {
                    try
                    {
                        NativeOverlapped lpOverlapped = default(NativeOverlapped);
                        NativeMethods.ReadFile(ReadHandle, array, (uint)array.Length, out lpNumberOfBytesRead, ref lpOverlapped);
                        status = HidDeviceData.ReadStatus.Success;
                    }
                    catch
                    {
                        status = HidDeviceData.ReadStatus.ReadError;
                    }
                }
                else
                {
                    NativeMethods.SECURITY_ATTRIBUTES securityAttributes = default(NativeMethods.SECURITY_ATTRIBUTES);
                    NativeOverlapped lpOverlapped2 = default(NativeOverlapped);
                    int dwMilliseconds             = (timeout <= 0) ? 65535 : timeout;
                    securityAttributes.lpSecurityDescriptor = IntPtr.Zero;
                    securityAttributes.bInheritHandle       = true;
                    securityAttributes.nLength = Marshal.SizeOf((object)securityAttributes);
                    lpOverlapped2.OffsetLow    = 0;
                    lpOverlapped2.OffsetHigh   = 0;
                    lpOverlapped2.EventHandle  = NativeMethods.CreateEvent(ref securityAttributes, Convert.ToInt32(false), Convert.ToInt32(true), string.Empty);
                    try
                    {
                        NativeMethods.ReadFile(ReadHandle, array, (uint)array.Length, out lpNumberOfBytesRead, ref lpOverlapped2);
                        switch (NativeMethods.WaitForSingleObject(lpOverlapped2.EventHandle, dwMilliseconds))
                        {
                        case 0u:
                            status = HidDeviceData.ReadStatus.Success;
                            break;

                        case 258u:
                            status = HidDeviceData.ReadStatus.WaitTimedOut;
                            array  = new byte[0];
                            break;

                        case uint.MaxValue:
                            status = HidDeviceData.ReadStatus.WaitFail;
                            array  = new byte[0];
                            break;

                        default:
                            status = HidDeviceData.ReadStatus.NoDataRead;
                            array  = new byte[0];
                            break;
                        }
                    }
                    catch
                    {
                        status = HidDeviceData.ReadStatus.ReadError;
                    }
                    finally
                    {
                        CloseDeviceIO(lpOverlapped2.EventHandle);
                    }
                }
            }
            return(new HidDeviceData(array, status));
        }