상속: IDisposable
예제 #1
0
        public UsbStream(UsbK usb,
                         byte pipeId,
                         int maxTransferSize,
                         int maxPendingTransfers,
                         int maxPendingIo,
                         bool useTimeout,
                         UInt16 timeout)
        {
            mUsb = usb;
            mPipeId = pipeId;

            if (UseCallbacks)
            {
                mCallbacks.Complete = StmComplete;
                if (((mPipeId & AllKConstants.USB_ENDPOINT_DIRECTION_MASK) > 0))
                {
                    mCallbacks.Submit = StmSubmitRead;
                }
                else
                {
                    mCallbacks.Submit = StmSubmitWrite;
                }
            }
            KSTM_FLAG flags = useTimeout ? KSTM_FLAG.USE_TIMEOUT | (KSTM_FLAG) timeout : KSTM_FLAG.NONE;

            mStm = new StmK(mUsb.Handle,
                            pipeId,
                            maxTransferSize,
                            maxPendingTransfers,
                            maxPendingIo,
                            ref mCallbacks,
                            flags);
        }
예제 #2
0
        //! Custom vendor requests that must be implemented in the benchmark firmware.


        #region Public Members
        public static bool Configure(UsbK usb,
                                     BM_COMMAND command,
                                     byte interfaceNumber,
                                     ref BM_TEST_TYPE testType)
        {
            int transferred;
            WINUSB_SETUP_PACKET pkt;
            byte[] data = new byte[1];

            pkt.RequestType = (1 << 7) | (2 << 5);
            pkt.Request = (byte) command;

            pkt.Value = (ushort) testType;
            pkt.Index = interfaceNumber;
            pkt.Length = 1;

            bool success = usb.ControlTransfer(pkt,
                                               Marshal.UnsafeAddrOfPinnedArrayElement(data,
                                                                                      0),
                                               1,
                                               out transferred,
                                               IntPtr.Zero);
            testType = (BM_TEST_TYPE) data[0];
            return success;
        }
예제 #3
0
        public bool InitializeDevice()
        {
            if (deviceList != null)
                deviceList.Free();
            deviceList = null;
            if (usb != null)
                usb.Free();
            usb = null;

            feature_value_dict.Clear();
            feature_value_lookup_dict.Clear();

            foreach (Control ctrl in this.Controls)
            {
                if (ctrl is ComboBox)
                {
                    ComboBox box = (ComboBox)ctrl;
                    box.Items.Clear();
                }
            }

            deviceList = new LstK(KLST_FLAG.NONE);
            KLST_DEVINFO_HANDLE deviceInfo;

            DeviceInfo.Text = "";
            bool success = false;
            deviceList.MoveReset();
            while (deviceList.MoveNext(out deviceInfo))
            {
                if (
                    (deviceInfo.Common.Vid == vendorid1 || deviceInfo.Common.Vid == vendorid2) &&
                    (deviceInfo.Common.Pid == productid1 || deviceInfo.Common.Pid == productid2 || deviceInfo.Common.Pid == productid3 || deviceInfo.Common.Pid == productid4) &&
                     deviceInfo.DeviceInterfaceGUID.ToUpper() == "{D49AB938-53BA-498A-A848-8E2780A4A75F}"
                    )
                {
                    if (deviceInfo.Connected)
                    {
                        success = true;
                        break;
                    }
                }
            }
            if (!success)
            {
                DeviceInfo.Text += String.Format("Audio-Widget device not found!\r\n");
                if (deviceList != null)
                    deviceList.Free();
                deviceList = null;
                return false;
            }
            usb = new UsbK(deviceInfo);
            DeviceInfo.Text += String.Format("Opening usb device OK\r\n");

            usb.GetDescriptor((byte)USB_DESCRIPTOR_TYPE.DEVICE, 0, 0,
                globalBuffer, globalBufferLength, out LengthTransferred);

            USB_DEVICE_DESCRIPTOR deviceDescriptor = ByteToDeviceDescriptor(globalBuffer);

            usb.GetDescriptor((byte)USB_DESCRIPTOR_TYPE.CONFIGURATION, 0, 0,
                globalBuffer, globalBufferLength, out LengthTransferred);
            USB_CONFIGURATION_DESCRIPTOR configurationDescriptor = ByteToConfigDescriptor(globalBuffer);

            string product = GetStringDescriptor(deviceDescriptor.iProduct);
            string manufacturer = GetStringDescriptor(deviceDescriptor.iManufacturer);
            string serial = GetStringDescriptor(deviceDescriptor.iSerialNumber);

            DeviceInfo.Text += String.Format("Device: VID=0x{0:X04}/PID=0x{1:X04}\r\n", deviceDescriptor.idVendor, deviceDescriptor.idProduct);
            DeviceInfo.Text += String.Format("Product: {0}\r\n", product);
            DeviceInfo.Text += String.Format("Manufacturer: {0}\r\n", manufacturer);
            DeviceInfo.Text += String.Format("Serial number: {0}\r\n", serial);

            success = SendUsbControl(interfaceNumber, (byte)BMREQUEST_DIR.DEVICE_TO_HOST, (byte)BMREQUEST_TYPE.VENDOR,
                (byte)BMREQUEST_RECIPIENT.DEVICE, 0x71, 4, 1,
                   globalBuffer, globalBufferLength, out LengthTransferred);

            ushort max_feature_value_index = globalBuffer[0];
            ushort feature_index = 0;
            ComboBox control = null;

            for (ushort i = 0; i < max_feature_value_index; i++)
            {
                success = SendUsbControl(interfaceNumber, (byte)BMREQUEST_DIR.DEVICE_TO_HOST, (byte)BMREQUEST_TYPE.VENDOR,
                    (byte)BMREQUEST_RECIPIENT.DEVICE, 0x71, 8, i,
                       globalBuffer, globalBufferLength, out LengthTransferred);
                if (globalBuffer[0] == 63)
                    break;

                string output_str = "";
                for (int s = (int)LengthTransferred - 1; s >= 0; s--)
                    output_str += (char)globalBuffer[s];

                if (output_str == "end")
                {
                    feature_index++;
                    control = null;
                }
                else
                {
                    if (control == null)
                        control = FindFeatureControl(feature_index);

                    if (control != null)
                    {
                        control.Items.Add(output_str);
                        feature_value_dict[(int)i] = output_str;
                        feature_value_lookup_dict[feature_index.ToString() + output_str] = (int)i;
                    }
                }

                if (i > 100)
                    break;
            }
            foreach (Control ctrl in this.Controls)
            {
                if (ctrl is ComboBox)
                {
                    int index = Convert.ToInt32(ctrl.Tag);
                    ComboBox box = (ComboBox)ctrl;

                    success = SendUsbControl(interfaceNumber, (byte)BMREQUEST_DIR.DEVICE_TO_HOST, (byte)BMREQUEST_TYPE.VENDOR,
                        (byte)BMREQUEST_RECIPIENT.DEVICE, 0x71, 4, (byte)(2 + index),
                           globalBuffer, globalBufferLength, out LengthTransferred);
                    int feature_value_index = (int)globalBuffer[0];
                    if (feature_value_dict.ContainsKey(feature_value_index))
                    {
                        string text = feature_value_dict[feature_value_index].ToString();
                        box.SelectedIndex = box.Items.IndexOf(text);
                    }
                }
            }
            return true;
        }
예제 #4
0
        public ReadIsoTransferQueue(UsbK usb, ref WINUSB_PIPE_INFORMATION pipeInfo, int maxPendingTransfers, int numberOfPackets)
        {
            PipeInfo = pipeInfo;
            Usb = usb;
            OvlPool = new OvlK(usb.Handle, maxPendingTransfers, KOVL_POOL_FLAG.NONE);
            DataBufferSize = (pipeInfo.MaximumPacketSize*numberOfPackets);
            for (int pos = 0; pos < maxPendingTransfers; pos++)
            {
                IsoTransferItem isoTransferItem = new IsoTransferItem();

                isoTransferItem.Buffer = new byte[pipeInfo.MaximumPacketSize*numberOfPackets];
                isoTransferItem.BufferGC = GCHandle.Alloc(isoTransferItem.Buffer, GCHandleType.Pinned);

                isoTransferItem.Iso = new IsoK(numberOfPackets, 0);
                isoTransferItem.Iso.SetPackets(pipeInfo.MaximumPacketSize);

                OvlPool.Acquire(out isoTransferItem.Ovl);

                Master.AddLast(isoTransferItem);
                Completed.AddLast(isoTransferItem);
            }
        }
예제 #5
0
 protected override void Dispose(bool disposing)
 {
     if (!mbDisposed)
     {
         mStm.Dispose();
         mStm = null;
         mUsb = null;
         mbDisposed = true;
     }
     base.Dispose(disposing);
 }