예제 #1
0
 private void TxDataArrayReset()
 {
     // Tx data 리셋
     for (int i = 0; i < 4096; i++)
     {
         Tx_data[i] = 0x00000000;
     }
     LogListBox.AppendText("Reset Tx data array\n\n");
 }
예제 #2
0
        private void ConstructEndpoints()
        {
            if (loopDevice != null && ConnectCyUsbOutEndpointComboBox.Items.Count > 0 && ConnectCyUsbInEndpointComboBox.Items.Count > 0)
            {
                // string에서 bAlternateSetting 파싱
                string sAltOut         = ConnectCyUsbOutEndpointComboBox.Text.Substring(4, 1);
                byte   outAltInferface = Convert.ToByte(sAltOut);

                string sAltIn         = ConnectCyUsbInEndpointComboBox.Text.Substring(4, 1);
                byte   inAltInferface = Convert.ToByte(sAltIn);

                if (outAltInferface != inAltInferface)
                {
                    // BULK LOOP 인터페이스는 ALT 인터페이스 세팅 코드가 일치하게 되어있음
                    // IN, OUT ENDPOINT가 같은 ALT 인터페이스가 아니면 로그 출력 후 리턴
                    LogListBox.AppendText("Output Endpoint and Input Endpoint should present in the same ALT interface\n\n");

                    return;
                }

                // STRING에서 ENDPOINT 주소 파싱
                int    aX     = ConnectCyUsbInEndpointComboBox.Text.LastIndexOf("0x");
                string sAddr  = ConnectCyUsbInEndpointComboBox.Text.Substring(aX, 4);
                byte   addrIn = (byte)Util.HexToInt(sAddr);

                aX    = ConnectCyUsbOutEndpointComboBox.Text.LastIndexOf("0x");
                sAddr = ConnectCyUsbOutEndpointComboBox.Text.Substring(aX, 4);
                byte addrOut = (byte)Util.HexToInt(sAddr);

                outEndpoint = loopDevice.EndPointOf(addrOut) as CyBulkEndPoint;
                inEndpoint  = loopDevice.EndPointOf(addrIn) as CyBulkEndPoint;

                if ((outEndpoint != null) && (inEndpoint != null))
                {
                    //make sure that the device configuration doesn't contain the other than bulk endpoint

                    if ((outEndpoint.Attributes & 0x03 /*0,1 bit for type of transfer*/) != 0x02 /*Bulk endpoint*/)
                    {
                        LogListBox.AppendText("Device Configuration mismatch\n\n");
                        return;
                    }
                    if ((inEndpoint.Attributes & 0x03) != 0x02)
                    {
                        LogListBox.AppendText("Device Configuration mismatch\n\n");
                        return;
                    }
                    outEndpoint.TimeOut = 1;
                    inEndpoint.TimeOut  = 1;
                }
                else
                {
                    LogListBox.AppendText("Device Configuration mismatch\n\n");
                    return;
                }
            }
        }
예제 #3
0
        public void initDevice()
        {
            usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
            if (usbDevices.Count != 0)
            {
                LogListBox.AppendText("Found " + usbDevices.Count + " USB Devices\n\n");
                setDevice();
            }

            //Adding event handlers for device attachment and device removal
            usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
            usbDevices.DeviceRemoved  += new EventHandler(usbDevices_DeviceRemoved);
        }
예제 #4
0
        void usbDevices_DeviceRemoved(object sender, EventArgs e)
        {
            LogListBox.AppendText("Removed USB Device\n\n");

            //when device is removed, rd/rw thread will be shutdown.
            tXfers_Read.Abort();
            tXfers_Read.Join();
            tXfers_Read = null;
            outEndpoint.Reset();

            tXfers_Write.Abort();
            tXfers_Write.Join();
            tXfers_Write = null;
            inEndpoint.Reset();
            setDevice();
        }
예제 #5
0
        private void SendDataButton_Click(object sender, RoutedEventArgs e)
        {
            // Tx data 리셋
            for (int i = 0; i < 4096; i++)
            {
                Tx_data[i] = 0x00000000;
            }
            // TxDataListBox 리셋
            TxDataListBox.Clear();

            // SendDataListBox에 기록된 Data를 Tx_data에 16진수 형태로 담음
            for (int i = 0; i < SendDataListBox.Items.Count; i++)                                           // SendDataListBox 아이템 수만큼 반복
            {
                String Databuff = SendDataListBox.Items[i].ToString();                                      // String으로 전환
                TxDataListBox.AppendText(Databuff + "\n");                                                  // TxDataListBox에 추가
                LogListBox.AppendText("Send Data : " + Databuff + "\n\n");                                  // Send Log 추가
                Tx_data[i] = Int32.Parse(Databuff, System.Globalization.NumberStyles.HexNumber);            // String을 16진수 숫자로 변환하여 Tx_data에 저장
            }
            writeflag = true;
        }
예제 #6
0
        public void setDevice()
        {
            int nCurSelection = 0;
            int nDeviceList   = usbDevices.Count;

            // 기존 데이터가 있으면 비우기
            if (ConnectCyUsbComboBox.Items.Count > 0)
            {
                nCurSelection = ConnectCyUsbComboBox.SelectedIndex;

                ConnectCyUsbComboBox.Items.Clear();
                ConnectCyUsbInEndpointComboBox.Items.Clear();
                ConnectCyUsbOutEndpointComboBox.Items.Clear();
            }

            // 기기 리스트 추가
            for (int nCount = 0; nCount < nDeviceList; nCount++)
            {
                USBDevice nDevice  = usbDevices[nCount];
                String    DeviceID = "(0x" + nDevice.ProductID.ToString("X4") + ") MITS_US_BOARD Rev1.0";
                ConnectCyUsbComboBox.Items.Add(DeviceID);
            }

            if (ConnectCyUsbComboBox.Items.Count > 0)
            {
                ConnectCyUsbComboBox.SelectedIndex = nCurSelection;

                loopDevice = usbDevices[ConnectCyUsbComboBox.SelectedIndex] as CyUSBDevice;

                GetEndpointsOfNode(loopDevice.Tree);

                // 아이템이 있으면 인덱스 0
                if (ConnectCyUsbInEndpointComboBox.Items.Count > 0)
                {
                    ConnectCyUsbInEndpointComboBox.SelectedIndex = 0;
                }
                if (ConnectCyUsbOutEndpointComboBox.Items.Count > 0)
                {
                    ConnectCyUsbOutEndpointComboBox.SelectedIndex = 0;
                }

                // Set the IN and OUT endpoints per the selected radio buttons.
                ConstructEndpoints();

                if ((outEndpoint != null) && (inEndpoint != null))
                {
                    if (loopDevice.bSuperSpeed)
                    {
                        xferLen_Write = 16384;
                        xferLen_Read  = 16384;
                    }
                    else if (loopDevice.bHighSpeed)
                    {
                        xferLen_Write = 512;
                        xferLen_Read  = 512;
                    }

                    string str = string.Format("Data Speed Write : {0} / Read {1}", xferLen_Write, xferLen_Read);
                    LogListBox.AppendText(str);

                    tXfers_Read = new Thread(new ThreadStart(ReadThread));
                    tXfers_Read.IsBackground = true;
                    tXfers_Read.Priority     = ThreadPriority.Highest;

                    tXfers_Write = new Thread(new ThreadStart(WriteThread));
                    tXfers_Write.IsBackground = true;
                    tXfers_Write.Priority     = ThreadPriority.Lowest;

                    tXfers_Read.Start();
                    tXfers_Write.Start();
                    LogListBox.AppendText("thstarted");
                }
            }
        }
예제 #7
0
 void usbDevices_DeviceAttached(object sender, EventArgs e)
 {
     LogListBox.AppendText("Connected New USB Device\n\n");
     setDevice();
 }