示例#1
0
        /// <summary>
        /// function for all detected thing
        /// </summary>
        private void USBDetected()
        {
            mCyUSBDev = mUSBDevList[0x04b4, 0x1004] as CyUSBDevice;
            if (mCyUSBDev == null)
            {
                MessageBox.Show("No Such Device!");
            }
            else
            {
                //mCyUSBInEP = mCyUSBDev.BulkInEndPt;
                mCyUSBOutEP = mCyUSBDev.BulkOutEndPt;

                foreach (CyUSBEndPoint ept in mCyUSBDev.EndPoints)
                {
                    if (ept.bIn && (ept.Attributes == 2))
                    {
                        mCyUSBInEP = ept as CyBulkEndPoint;
                    }
                }
            }
        }
示例#2
0
        public Form1()
        {
            InitializeComponent();

            usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
            USBDevice dev = usbDevices[0];

            if (dev != null)
            {
                MyDevice = (CyUSBDevice)dev;

                GetEndPoint(MyDevice.Tree);
            }

            foreach (CyUSBEndPoint ep in EndPointList)
            {
                if (ep.Address == 0x86)
                    inEndPoint = ep;
                if (ep.Address == 0x2)
                    outEndPoint = ep;
            }
        }
示例#3
0
 /*Summary
    This is the event handler for device removal. This method resets the device count and searches for the device with
    VID-PID 04b4-1003
 */
 void usbDevices_DeviceRemoved(object sender, EventArgs e)
 {
     MyDevice = null;
     EndPoint = null;
     SetDevice();
 }
示例#4
0
        public void SetEndpoint(int index)
        {
            //string temp = EndPointsComboBox.SelectedValue.ToString();
            //string EndPointCBValue="";
            //System.Windows.Controls.ComboBoxItem curItem=((System.Windows.Controls.ComboBoxItem)EndPointsComboBox.SelectedItem);
            //EndPointCBValue = curItem.Content.ToString();

            // Get the Alt setting
            string sAlt = EndpointList[index].Substring(4, 1);
            //string sAlt = EndPointsComboBox.Text.Substring(4, 1);
            byte a = Convert.ToByte(sAlt);
            MyDevice.AltIntfc = a;

            // Get the endpoint
            //int aX = EndPointsComboBox.Text.LastIndexOf("0x");
            //string sAddr = EndPointsComboBox.Text.Substring(aX, 4);
            int aX = EndpointList[index].LastIndexOf("0x");
            string sAddr = EndpointList[index].Substring(aX, 4);
            byte addr = (byte)Util.HexToInt(sAddr);

            EndPoint = MyDevice.EndPointOf(addr);

            // Ensure valid PPX for this endpoint
            //PpxBox_SelectionChanged(sender, null);
        }
示例#5
0
 /* Summary
     Event handler for device removal
 */
 void usbDevices_DeviceRemoved(object sender, EventArgs e)
 {
     USBEventArgs usbEvent = e as USBEventArgs;
     curEndpt = null; // reinitialize
     RefreshDeviceTree();
 }
示例#6
0
        /* Summary
            Executes the script loaded
        */
        private void play_button_Click(object sender, EventArgs e)
        {
            FxDev = FxDevDeviceSelected();

            if (FxDev == null)
            {
                return;
            }

            if (playscriptfile.Length == 0)
            {
                MessageBox.Show("Load a script before playing it.", "Load script");
                return;
            }

            StatLabel.Text = "Playing Script " + FOpenDialog.FileName + " in Outputbox";
            Refresh();

            FileStream stream = new FileStream(playscriptfile, FileMode.Open, FileAccess.Read);

            if (stream.Length > 0)
            {
                try
                {
                    Xaction.ReadFromStream(stream);

                    if (FxDev.Config != Xaction.ConfigNum)
                        FxDev.Config = Xaction.ConfigNum;

                    if (FxDev.AltIntfc != Xaction.AltIntfc)
                        FxDev.AltIntfc = Xaction.AltIntfc;

                    stream.Close();

                    stream = new FileStream(playscriptfile, FileMode.Open, FileAccess.Read);

                    long totalFileSize = stream.Length;
                    long file_bytes_read = 0;

                    do
                    {
                        Xaction.ReadFromStream(stream);
                        file_bytes_read += 32;

                        if (Xaction.Tag == 0xFF)
                        {
                            Thread.Sleep(100);
                        }
                        else
                        {
                            byte[] buffer = new byte[Xaction.DataLen];
                            int len = (int)Xaction.DataLen;

                            curEndpt = FxDev.EndPointOf(Xaction.EndPtAddr);

                            if (curEndpt != null)
                            {
                                if (curEndpt.Attributes == 0)
                                {
                                    /* Control transfer */
                                    CyControlEndPoint ctlEpt = curEndpt as CyControlEndPoint;

                                    byte tmp = Xaction.bReqType;

                                    ctlEpt.Target = (byte)(tmp & TTransaction.ReqType_TGT_MASK);
                                    ctlEpt.ReqType = (byte)(tmp & TTransaction.ReqType_TYPE_MASK);
                                    ctlEpt.Direction = (byte)(tmp & TTransaction.ReqType_DIR_MASK);
                                    ctlEpt.ReqCode = Xaction.CtlReqCode;
                                    ctlEpt.Value = Xaction.wValue;
                                    ctlEpt.Index = Xaction.wIndex;

                                    if (Xaction.Tag == 0)
                                    {
                                        Xaction.ReadToBuffer(stream, ref buffer, ref len);
                                        file_bytes_read += len;
                                    }

                                    if (Xaction.Tag == 1)
                                    {
                                        /* Read from device saving to file */

                                        string tmpSFilter = FSave.Filter;
                                        string tmpSTitle = FSave.Title;
                                        string file;

                                        FSave.Title = "Save Data as:";
                                        FSave.Filter = "All Files(*.*) | *.*";

                                        if (FSave.ShowDialog() == DialogResult.OK)
                                        {
                                            file = FSave.FileName;
                                            Refresh();
                                        }
                                        else
                                        {
                                            FSave.Filter = tmpSFilter;
                                            FSave.Title = tmpSTitle;
                                            return;
                                        }

                                        FSave.FileName = "";
                                        FSave.Filter = tmpSFilter;
                                        FSave.Title = tmpSTitle;

                                        PerformCtlFileTransfer(file, ref buffer, ref len);
                                    }
                                    else
                                    {
                                        PerformCtlTransfer(ref buffer, ref len);
                                    }
                                }
                                else
                                {
                                    /* Non Ep0 transfer */
                                    if (Xaction.Tag == 0)
                                    {
                                        Xaction.ReadToBuffer(stream, ref buffer, ref len);
                                        file_bytes_read += len;
                                    }

                                    if (Xaction.Tag == 1)
                                    {
                                        /* Read from device saving to file */
                                        string tmpSFilter = FSave.Filter;
                                        string tmpSTitle = FSave.Title;
                                        string file;

                                        FSave.Title = "Save Data as:";
                                        FSave.Filter = "All files(*.*) | *.*";

                                        if (FSave.ShowDialog() == DialogResult.OK)
                                        {
                                            file = FSave.FileName;
                                            Refresh();
                                        }
                                        else
                                        {
                                            FSave.Filter = tmpSFilter;
                                            FSave.Title = tmpSTitle;
                                            return;
                                        }

                                        FSave.FileName = "";
                                        FSave.Filter = tmpSFilter;
                                        FSave.Title = tmpSTitle;

                                        PerformNonEP0FileXfer(file, ref buffer, ref len);
                                    }
                                    else
                                    {
                                        PerformNonEP0Xfer(ref buffer, ref len);
                                    }
                                }
                            }
                        }
                    } while ((totalFileSize - file_bytes_read) >= 32);
                }
                catch (Exception esc)
                {
                    MessageBox.Show(esc.Message, "Invalid file data");
                }
            }
            else
                MessageBox.Show("Script Loaded is empty", "Invalid file");

            stream.Close();
        }
示例#7
0
        /* Summary
            Initialize global variables defined
        */
        private void Initialize()
        {
            scriptfile = "";
            playscriptfile = "";
            Resetreg = 0xE600;
            Maxaddr = 0x4000;
            Max_Ctlxfer_size = 0x1000;
            bRecording = false;
            Xaction = new TTransaction();
            list = new ArrayList();
            list1 = new ArrayList();

            curEndpt = null;
            curCyUsbDev = null;
            curHidDev = null;
            curHidReport = null;
        }
示例#8
0
        /* Summary
            Any selection changes in the tree view will trigger this function "at start the first device is always selected leading into this function"
        */
        private void DeviceTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            XferTextBox.Text = "";
            XferDataBox.Text = "";

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(">&&");
            for (int i = 1; i < this.XferTextBox.MaxLength; i++)
            {
                sb.Append(" &&");
            }

            this.XferDataBox.Mask = sb.ToString();

            TreeNode selNode = DeviceTreeView.SelectedNode;
            string nodeText = selNode.Text;

            CyUSBInterfaceContainer curIntfcContainer = selNode.Tag as CyUSBInterfaceContainer;
            CyUSBInterface curIntfc = selNode.Tag as CyUSBInterface;
            CyUSBConfig curConfig = selNode.Tag as CyUSBConfig;

            curEndpt = selNode.Tag as CyUSBEndPoint;
            curCyUsbDev = selNode.Tag as CyUSBDevice;

            curHidDev = null;
            curHidReport = null;

            if (curConfig != null)
            {
                curCyUsbDev = selNode.Parent.Tag as CyUSBDevice;
            }
            else if (curIntfcContainer != null)
            {
                curCyUsbDev = selNode.Parent.Parent.Tag as CyUSBDevice;
            }
            else if (curIntfc != null)
            {
                curCyUsbDev = selNode.Parent.Parent.Parent.Tag as CyUSBDevice;
                curCyUsbDev.AltIntfc = curIntfc.bAlternateSetting;
            }
            else if (curEndpt != null)
            {

                int minXfer = curEndpt.MaxPktSize;

                if (curEndpt.Attributes == 1)
                    minXfer *= 8;

                NumBytesBox.Text = minXfer.ToString();

                // Set the AltSetting
                if (curEndpt.Address != 0) // Only if we're not on the Control Endpoint
                {
                    curCyUsbDev = selNode.Parent.Parent.Parent.Parent.Tag as CyUSBDevice;
                    curIntfc = selNode.Parent.Tag as CyUSBInterface;
                    curCyUsbDev.AltIntfc = curIntfc.bAlternateSetting;
                }
                else
                {
                    curCyUsbDev = selNode.Parent.Parent.Tag as CyUSBDevice;
                }
            }
            else if ((selNode.Tag is CyHidButton) || (selNode.Tag is CyHidValue))
            {
                curHidDev = selNode.Parent.Parent.Tag as CyHidDevice;
                curHidReport = selNode.Parent.Tag as CyHidReport;

                NumBytesBox.Text = curHidReport.RptByteLen.ToString();
                nodeText = selNode.Parent.Text;
            }
            else if (selNode.Tag is CyHidReport)
            {
                curHidDev = selNode.Parent.Tag as CyHidDevice;
                curHidReport = selNode.Tag as CyHidReport;

                NumBytesBox.Text = curHidReport.RptByteLen.ToString();
            }
            else if (selNode.Tag is CyHidDevice)
                curHidDev = selNode.Tag as CyHidDevice;

            ConfigDataXferBtn(nodeText);

            DescText.Text = selNode.Tag.ToString();

            Sync_Form_Resize = 1;
            Form1_Resize(sender, null);
        }
示例#9
0
        /* Summary
            Event handler to handle changes in Check box of Device Class Selection Tabpage and at Start
        */
        private void CyUSBDeviceBox_CheckedChanged(object sender, EventArgs e)
        {
            byte DeviceMask = 0;

            DeviceMask |= CyUSBDeviceBox.Checked ? CyConst.DEVICES_CYUSB : (byte)0;
            DeviceMask |= MSCDeviceBox.Checked ? CyConst.DEVICES_MSC : (byte)0;
            DeviceMask |= HIDDeviceBox.Checked ? CyConst.DEVICES_HID : (byte)0;

            if (usbDevices != null)
            {
                usbDevices.DeviceRemoved -= usbDevices_DeviceRemoved;
                usbDevices.DeviceAttached -= usbDevices_DeviceAttached;
                usbDevices.Dispose();
            }

            usbDevices = new USBDeviceList(DeviceMask);

            usbDevices.DeviceRemoved += new EventHandler(usbDevices_DeviceRemoved);
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);

            curEndpt = null;
            curCyUsbDev = null;
            curHidDev = null;
            curHidReport = null;
            RefreshDeviceTree();
        }
示例#10
0
文件: Form1.cs 项目: arnofan/tesis
        /*Summary
         This is a system event handler, when the selected index changes(end point selection).
        */
        private void EndPointsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Get the Alt setting
            string sAlt = EndPointsComboBox.Text.Substring(4, 1);
            byte a = Convert.ToByte(sAlt);
            MyDevice.AltIntfc = a;

            // Get the endpoint
            int aX = EndPointsComboBox.Text.LastIndexOf("0x");
            string sAddr = EndPointsComboBox.Text.Substring(aX, 4);
            byte addr = (byte)Util.HexToInt(sAddr);

            EndPoint = MyDevice.EndPointOf(addr);

            // Ensure valid PPX for this endpoint
            PpxBox_SelectedIndexChanged(sender, null);
        }