Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.button1.Text == "开始读取")
            {
                this.textBox1.Text = null;
                this.textBox2.Text = null;
                this.textBox3.Text = null;

                this.button1.Text = "停止读取";


                if (USB.MyDeviceList[Data.OnlyId] != null)
                {
                    CyControlEndPoint CtrlEndPt = null;
                    CtrlEndPt = USB.MyDeviceList[Data.OnlyId].ControlEndPt;

                    if (CtrlEndPt != null)
                    {
                        USB.SendCMD(Data.OnlyId, 0x80, 0x01);
                        USB.SendCMD(Data.OnlyId, 0x80, 0x00);

                        USB.MyDeviceList[Data.OnlyId].Reset();

                        Register.Byte80H = (byte)(Register.Byte80H | 0x04);
                        USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);

                        this.btn_80_2.Text = "1:接收";
                    }

                    FileThread = new SaveFile();
                    FileThread.FileInit();
                    FileThread.FileSaveStart();

                    MyLog.Info("开始读取");
                    RecvTag = true;

                    ThisCount = 0;
                    LastCount = 0;

                    new Thread(() => { RecvAllUSB(); }).Start();
                    new Thread(() => { DealWithADFun(); }).Start();
                }
                else
                {
                    MyLog.Error("单元测试仪未连接!");
                }
            }
            else
            {
                this.button1.Text = "开始读取";
                ThisCount         = 0;
                LastCount         = 0;
                RecvTag           = false;
                Thread.Sleep(500);
                if (FileThread != null)
                {
                    FileThread.FileClose();
                }
            }
        }
Example #2
0
        private void button3_Click_1(object sender, EventArgs e)
        {
            String Str_Content = textBox7.Text.Replace(" ", "");
            int    lenth       = (Str_Content.Length) / 2;

            if (lenth >= 0)
            {
                int AddToFour = lenth % 4;
                if (AddToFour != 0)
                {
                    for (int i = 0; i < (4 - AddToFour); i++)
                    {
                        Str_Content += "00";
                    }
                }

                for (int j = 0; j < 8; j++)
                {
                    byte[] temp = StrToHexByte((0x1D00 + j).ToString("x4") + lenth.ToString("x4") + Str_Content + textBox9.Text);
                    temp[4] = (byte)(0x1 + j);
                    USB.SendData(Data.OnlyId, temp);
                }
            }
            else
            {
                MyLog.Error("请至少输入4个Byte的数据");
            }
        }
Example #3
0
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                byte addr = Convert.ToByte(textBox5.Text, 16);

                byte value = Convert.ToByte(textBox6.Text, 16);

                if (addr < 0x80 || addr > 0xff)
                {
                    MessageBox.Show("请输入正确的addr!!");
                }
                else if (value < 0x00 || value > 0x7f)
                {
                    MessageBox.Show("请输入正确的value!!");
                }
                else
                {
                    USB.SendCMD(Data.OnlyId, addr, value);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入正确的地址和值:" + ex.Message);
            }
        }
Example #4
0
        private void button9_Click_2(object sender, EventArgs e)
        {
            Register.Byte81H = (byte)(Register.Byte81H | (byte)(0x01 << 2));
            USB.SendCMD(Data.OnlyId, 0x81, Register.Byte81H);

            Register.Byte81H = (byte)(Register.Byte81H & (byte)(0x7f - (byte)(0x01 << 2)));
            USB.SendCMD(Data.OnlyId, 0x81, Register.Byte81H);


            String Str_Content = textBox_value_1d02.Text.Trim();
            int    lenth       = (Str_Content.Length) / 2;

            if (lenth >= 0)
            {
                int AddToFour = lenth % 4;
                if (AddToFour != 0)
                {
                    for (int i = 0; i < (4 - AddToFour); i++)
                    {
                        Str_Content += "00";
                    }
                }

                byte[] temp = StrToHexByte("1D02" + lenth.ToString("x4") + Str_Content + "C0DEC0DEC0DEC0DEC0DEC0DEC0DEC0DE");

                USB.SendData(Data.OnlyId, temp);
            }
            else
            {
                MyLog.Error("请至少输入4个Byte的数据");
            }
        }
Example #5
0
        private void initRBoard()
        {
            MyLog.Info("初始化数字电阻通道......");

            //初始化板卡,每个通道值设置为0x00001C03向下发送
            byte[] RSend = new byte[8 + 32];
            RSend[0] = 0x1D;
            RSend[1] = 0x0D;
            RSend[2] = 0x00;
            RSend[3] = 0x20;//0x0020 = 32

            // for (int i = 0; i < 32; i++) RSend[164 + i] = 0x0;

            for (int i = 1; i < 8; i++)
            {
                RSend[4 * i]     = 0x0;
                RSend[4 * i + 1] = 0x0;
                //RSend[4 * i + 2] = 0x1c;
                //RSend[4 * i + 3] = 0x03;
                RSend[4 * i + 2] = 0x03;
                RSend[4 * i + 3] = 0x1c;
            }

            RSend[36] = 0xC0;
            RSend[37] = 0xDE;
            RSend[38] = 0xC0;
            RSend[39] = 0xDE;

            Register.Byte84H = (byte)(Register.Byte84H | 0x40);
            USB.SendCMD(Data.OnlyId, 0x84, Register.Byte84H);
            Register.Byte84H = (byte)(Register.Byte84H & 0x3f);
            USB.SendCMD(Data.OnlyId, 0x84, 0x00);

            USB.SendData(Data.OnlyId, RSend);
        }
Example #6
0
        private void button3_Click(object sender, EventArgs e)
        {
            USB.SendCMD(Data.OnlyId, 0x81, 0x00);

            Register.Byte80H = (byte)(Register.Byte80H | 0x01);
            USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);

            Register.Byte80H = (byte)(Register.Byte80H & 0xfe);
            USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);
        }
Example #7
0
 private void button9_Click(object sender, EventArgs e)
 {
     USB.SendCMD(Data.OnlyId, 0x82, 0x7f);
     Thread.Sleep(100);
     USB.SendCMD(Data.OnlyId, 0x82, 0x00);
     Thread.Sleep(100);
     USB.SendCMD(Data.OnlyId, 0x83, 0x01);
     Thread.Sleep(100);
     USB.SendCMD(Data.OnlyId, 0x83, 0x00);
 }
Example #8
0
        /*Summary
         * Search the device with VID-PID 04b4-00F1 and if found, select the end point
         */
        private void SetDevice(bool bPreserveSelectedDevice)
        {
            int nDeviceList = USB.usbDevices.Count;

            for (int nCount = 0; nCount < nDeviceList; nCount++)
            {
                USBDevice fxDevice = USB.usbDevices[nCount];
                String    strmsg;
                strmsg = "(0x" + fxDevice.VendorID.ToString("X4") + " - 0x" + fxDevice.ProductID.ToString("X4") + ") " + fxDevice.FriendlyName;

                int key = int.Parse(fxDevice.ProductID.ToString("x4").Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
                if (USB.MyDeviceList[key] == null)
                {
                    USB.MyDeviceList[key] = (CyUSBDevice)fxDevice;

                    MyLog.Info(USB.MyDeviceList[key].FriendlyName + ConfigurationManager.AppSettings[USB.MyDeviceList[key].FriendlyName] + "连接");

                    Data.OnlyId = key;

                    USB.SendCMD(Data.OnlyId, 0x81, 0x7f);
                    Thread.Sleep(100);
                    USB.SendCMD(Data.OnlyId, 0x81, 0x00);
                    Thread.Sleep(100);
                    USB.SendCMD(Data.OnlyId, 0x82, 0x7f);
                    Thread.Sleep(100);
                    USB.SendCMD(Data.OnlyId, 0x82, 0x00);
                    Thread.Sleep(100);
                    USB.SendCMD(Data.OnlyId, 0x83, 0x7f);
                    Thread.Sleep(100);
                    USB.SendCMD(Data.OnlyId, 0x83, 0x00);
                    Thread.Sleep(100);
                    USB.SendCMD(Data.OnlyId, 0x84, 0x7f);
                    Thread.Sleep(100);
                    USB.SendCMD(Data.OnlyId, 0x84, 0x00);
                    Thread.Sleep(100);
                    USB.SendCMD(Data.OnlyId, 0x85, 0x7f);
                    Thread.Sleep(100);
                    USB.SendCMD(Data.OnlyId, 0x85, 0x00);
                    Thread.Sleep(100);
                }
            }
        }
Example #9
0
        public MainForm()
        {
            InitializeComponent();

            //启动日志
            MyLog.richTextBox1 = richTextBox1;
            MyLog.path         = Program.GetStartupPath() + @"LogData\";
            MyLog.lines        = 50;
            MyLog.start();


            // Create the list of USB devices attached to the CyUSB3.sys driver.
            USB.usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);

            //Assign event handlers for device attachment and device removal.
            USB.usbDevices.DeviceAttached += new EventHandler(UsbDevices_DeviceAttached);
            USB.usbDevices.DeviceRemoved  += new EventHandler(UsbDevices_DeviceRemoved);

            USB.Init();
        }
Example #10
0
        private void btn_80_0_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            string str = btn.Name;

            string TextName = btn.Text;

            string[] tempList = TextName.Split(':');

            if (tempList[0] == "0")
            {
                btn.Text = "1:" + tempList[1];

                byte addr   = Convert.ToByte(str.Substring(4, 2), 16);
                int  bitpos = Convert.ToByte(str.Substring(7, 1), 10);
                switch (addr)
                {
                case 0x80:
                    Register.Byte80H = (byte)(Register.Byte80H | (byte)(0x01 << bitpos));
                    USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);
                    break;

                case 0x81:
                    Register.Byte81H = (byte)(Register.Byte81H | (byte)(0x01 << bitpos));
                    USB.SendCMD(Data.OnlyId, 0x81, Register.Byte81H);
                    break;

                case 0x82:
                    Register.Byte82H = (byte)(Register.Byte82H | (byte)(0x01 << bitpos));
                    USB.SendCMD(Data.OnlyId, 0x82, Register.Byte82H);
                    break;

                case 0x83:
                    Register.Byte83H = (byte)(Register.Byte83H | (byte)(0x01 << bitpos));
                    USB.SendCMD(Data.OnlyId, 0x83, Register.Byte83H);
                    break;

                case 0x84:
                    Register.Byte84H = (byte)(Register.Byte84H | (byte)(0x01 << bitpos));
                    USB.SendCMD(Data.OnlyId, 0x84, Register.Byte84H);
                    break;

                case 0x85:
                    Register.Byte85H = (byte)(Register.Byte85H | (byte)(0x01 << bitpos));
                    USB.SendCMD(Data.OnlyId, 0x85, Register.Byte85H);
                    break;

                default:
                    Register.Byte80H = (byte)(Register.Byte80H | (byte)(0x01 << bitpos));
                    USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);
                    break;
                }
            }
            //if (btn.Text == "0")
            //{
            //    btn.Text = "1";

            //    byte addr = Convert.ToByte(str.Substring(4, 2), 16);
            //    int bitpos = Convert.ToByte(str.Substring(7, 1), 10);
            //    switch (addr)
            //    {
            //        case 0x80:
            //            Register.Byte80H = (byte)(Register.Byte80H | (byte)(0x01 << bitpos));
            //            USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);
            //            break;
            //        case 0x81:
            //            Register.Byte81H = (byte)(Register.Byte81H | (byte)(0x01 << bitpos));
            //            USB.SendCMD(Data.OnlyId, 0x81, Register.Byte81H);
            //            break;
            //        case 0x82:
            //            Register.Byte82H = (byte)(Register.Byte82H | (byte)(0x01 << bitpos));
            //            USB.SendCMD(Data.OnlyId, 0x82, Register.Byte82H);
            //            break;
            //        case 0x83:
            //            Register.Byte83H = (byte)(Register.Byte83H | (byte)(0x01 << bitpos));
            //            USB.SendCMD(Data.OnlyId, 0x83, Register.Byte83H);
            //            break;
            //        case 0x84:
            //            Register.Byte84H = (byte)(Register.Byte84H | (byte)(0x01 << bitpos));
            //            USB.SendCMD(Data.OnlyId, 0x84, Register.Byte84H);
            //            break;
            //        case 0x85:
            //            Register.Byte85H = (byte)(Register.Byte85H | (byte)(0x01 << bitpos));
            //            USB.SendCMD(Data.OnlyId, 0x85, Register.Byte85H);
            //            break;
            //        default:
            //            Register.Byte80H = (byte)(Register.Byte80H | (byte)(0x01 << bitpos));
            //            USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);
            //            break;
            //    }

            //}
            else
            {
                //                btn.Text = "0";

                btn.Text = "0:" + tempList[1];

                byte addr   = Convert.ToByte(str.Substring(4, 2), 16);
                int  bitpos = Convert.ToByte(str.Substring(7, 1), 10);
                switch (addr)
                {
                case 0x80:
                    Register.Byte80H = (byte)(Register.Byte80H & (byte)(0x7f - (byte)(0x01 << bitpos)));
                    USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);
                    break;

                case 0x81:
                    Register.Byte81H = (byte)(Register.Byte81H & (byte)(0x7f - (byte)(0x01 << bitpos)));
                    USB.SendCMD(Data.OnlyId, 0x81, Register.Byte81H);
                    break;

                case 0x82:
                    Register.Byte82H = (byte)(Register.Byte82H & (byte)(0x7f - (byte)(0x01 << bitpos)));
                    USB.SendCMD(Data.OnlyId, 0x82, Register.Byte82H);
                    break;

                case 0x83:
                    Register.Byte83H = (byte)(Register.Byte83H & (byte)(0x7f - (byte)(0x01 << bitpos)));
                    USB.SendCMD(Data.OnlyId, 0x83, Register.Byte83H);
                    break;

                case 0x84:
                    Register.Byte84H = (byte)(Register.Byte84H & (byte)(0x7f - (byte)(0x01 << bitpos)));
                    USB.SendCMD(Data.OnlyId, 0x84, Register.Byte84H);
                    break;

                case 0x85:
                    Register.Byte85H = (byte)(Register.Byte85H & (byte)(0x7f - (byte)(0x01 << bitpos)));
                    USB.SendCMD(Data.OnlyId, 0x85, Register.Byte85H);
                    break;

                default:
                    Register.Byte80H = (byte)(Register.Byte80H & (byte)(0x7f - (byte)(0x01 << bitpos)));
                    USB.SendCMD(Data.OnlyId, 0x80, Register.Byte80H);
                    break;
                }
            }
        }
Example #11
0
 private void button4_Click(object sender, EventArgs e)
 {
     Register.Byte81H = (byte)(Register.Byte81H | 0x08);
     USB.SendCMD(Data.OnlyId, 0x81, Register.Byte81H);
 }