예제 #1
0
        static void Run()
        {
            USBHIDDRIVER.USBInterface usb = new USBInterface("vid_11fa", "pid_0202");

            usb.Connect();

            usb.enableUsbBufferEvent(new System.EventHandler(MyEventCacher));

            usb.startRead();

            Console.Write("Press CTRL+C To Quit" + Environment.NewLine);
            Console.CancelKeyPress += (sender, eArgs) =>
            {
                _quitEvent.Set();
                eArgs.Cancel = true;
            };

            _quitEvent.WaitOne();

            usb.stopRead();

            while (true)
            {
                System.Threading.Thread.Sleep(1000);
            }
        }
예제 #2
0
        public InputSourceBaanto()
        {
            USBInterface usb = new USBInterface("vid_2453", "pid_0100");

            usb.Connect();
            usb.enableUsbBufferEvent(incomingData);
            usb.startRead();
        }
예제 #3
0
        private static void Main(string[] args)
        {
            var usb = new USBInterface(@"vid_0a81", @"pid_ff01");

            usb.Connect();
            WriteData(usb, 64);
            WriteData(usb, 16);
            WriteData(usb, 64);
            WriteData(usb, 64);
            WriteData(usb, 32);
            Console.ReadLine();
        }
예제 #4
0
파일: Program.cs 프로젝트: vadimas/events
        private static void Main(string[] args)
        {
            _device = new USBInterface("vid_1294", "pid_1320");
            _device.Connect();
            var line = Console.ReadLine();

            while (line != null && line != "E")
            {
                var b = Convert.ToByte(line);
                WriteDataEx(b);
                line = Console.ReadLine();
            }
            Console.ReadLine();
        }
예제 #5
0
        public void Start()
        {
            device = new USBInterface("vid_1244", "pid_d237");

            if (!device.Connect())
            {
                throw new Exception("Victor 70C Multimeter cannot be found");
            }

            device.enableUsbBufferEvent(new System.EventHandler(myEventCacher));

            Thread.Sleep(5);
            device.startRead();
        }
예제 #6
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length > 0)
                {
                    VirtualKeys = false;
                }
                string VID = ConfigurationManager.AppSettings["VID"] ?? "vid_05f3";
                string PID = ConfigurationManager.AppSettings["PID"] ?? "pid_00ff";

                Left   = ConfigurationManager.AppSettings["Left"] ?? "L";
                Middle = ConfigurationManager.AppSettings["Middle"] ?? "M";
                Right  = ConfigurationManager.AppSettings["Right"] ?? "R";

                VKeyLeft   = ConfigurationManager.AppSettings["Left"] ?? "{LEFT}";
                VKeyMiddle = ConfigurationManager.AppSettings["Middle"] ?? " ";
                VKeyRight  = ConfigurationManager.AppSettings["Right"] ?? "{RIGHT}";


                usbI       = new USBInterface(VID, PID);
                savehandle = new EventHandler(HIDhandler);

                bool conn = usbI.Connect();

                if (conn)
                {
                    usbI.enableUsbBufferEvent(savehandle);
                    Thread.Sleep(5);
                    usbI.startRead();
                }

                Console.Read();
                if (conn)
                {
                    usbI.stopRead();
                    try
                    {
                        usbI.Disconnect();
                    }
                    catch { }
                }
            }
            finally
            {
                Environment.Exit(0); //Force close application
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            var usb = new USBInterface(@"vid_0a81", @"pid_ff01");

            usb.Connect();
            // sample to file a missile
            WriteData(usb, 8);
            Thread.Sleep(2000);
            WriteData(usb, 0);
            Thread.Sleep(2500);
            WriteData(usb, 8);
            Thread.Sleep(2500);
            WriteData(usb, 0);
            Thread.Sleep(2500);
            Console.ReadLine();
        }
예제 #8
0
파일: Program.cs 프로젝트: vadimas/events
        private static void Main(string[] args)
        {
            Console.WriteLine("Press key (1 ... 8) to change color in Light Notifier");
            Console.WriteLine("Press key (E) to exit app");
            Console.WriteLine("Press other key to crash the app");

            _device = new USBInterface("vid_1294", "pid_1320");
            _device.Connect();
            var line = Console.ReadLine();

            while (line != null && line.ToUpper() != "E")
            {
                var b = Convert.ToByte(line);
                WriteDataEx(b);
                line = Console.ReadLine();
            }
            Console.ReadLine();
        }
예제 #9
0
        public MainWindow()
        {
            InitializeComponent();
            IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();

            mySender = aTypedMessagesFactory.CreateDuplexTypedMessageSender <MyResponse, MyRequest>();
            mySender.ResponseReceived += OnResponseReceived;

            // Create messaging based on TCP.
            IMessagingSystemFactory aMessagingSystemFactory = new TcpMessagingSystemFactory();
            IDuplexOutputChannel    anOutputChannel         = aMessagingSystemFactory.CreateDuplexOutputChannel("tcp://192.168.2.9:8060/");

            // Attach output channel and be able to send messages and receive response messages.
            mySender.AttachDuplexOutputChannel(anOutputChannel);
            MyRequest test = new MyRequest {
                side = "L", strength = 10
            };

            mySender.SendRequestMessage(test);
            MyRequest reset = new MyRequest {
                side = "L", strength = 0
            };

            mySender.SendRequestMessage(reset);
            try
            {
                USBInterface usb = new USBInterface("vid_044f", "pid_b108");
                usb.Connect();
                usb.enableUsbBufferEvent(new System.EventHandler(myEventCacher));
                usb.startRead();

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #10
0
        /// <summary>
        /// Open the controller
        /// </summary>
        public bool OpenDevice()
        {
            int _reconn_counter = 0;

            this.IsConnected = false;

            while (true)
            {
                try
                {
                    _reconn_counter++;

                    if (_hid_device.Connect())
                    {
                        // Start the received task on the UI thread
                        OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.ConnectionSuccess, null));

                        // start to read hid report from usb device in the background thread
                        ////_hid_device.StartRead();

                        // to realize the mechanism of timeout, save the time when the initialization process is started
                        DateTime _init_start_time = DateTime.Now;

                        // Wait the first report from HID device in order to get the 'TotalAxes'
                        do
                        {
                            // read hid report
                            byte[] report = _hid_device.Read();
                            if (report != null)
                            {
                                this.Report.ParseRawData(report);

                                this.TotalAxes = this.Report.TotalAxes;
                            }

                            // Don't check it so fast, the interval of two adjacent report is normally 20ms but not certain
                            Thread.Sleep(100);

                            // check whether the initialization process is timeout
                            if ((DateTime.Now - _init_start_time).TotalSeconds > 5)
                            {
                                this.LastError = "unable to get the total axes";
                                break;
                            }
                        } while (this.TotalAxes <= 0);

                        // TotalAxes <= 0 indicates that no axis was found within 5 seconds, exit initialization process
                        if (this.TotalAxes <= 0)
                        {
                            break;
                        }

                        // the total number of axes returned, generate the instance of each axis
                        this.Report.AxisStateCollection.Clear();

                        // create the axis collection according the TotalAxes property in the hid report
                        for (int i = 0; i < this.TotalAxes; i++)
                        {
                            // generate axis state object to the controller report class
                            this.Report.AxisStateCollection.Add(new AxisState()
                            {
                                AxisIndex = i
                            });

                            // generate axis control on the user window
                            this.AxisCollection.Add(new Axis()
                            {
                                // set the properties to the default value
                                MaxSteps          = 15000,
                                SoftCCWLS         = 0,
                                SoftCWLS          = 15000,
                                PosAfterHome      = 0,
                                MaxSpeed          = MAX_VELOCITY,
                                AccelerationSteps = ACC_DEC_STEPS
                            });
                        }

                        // start to read the hid report repeatedly
                        _hid_device.StartRead();


                        this.IsConnected = true;

                        // initialize this.Report property on UI thread
                        OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.TotalAxesReturned, this.TotalAxes));
                        break;
                    }
                    else
                    {
                        // pass the try-times to UI thread
                        OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.ConnectionRetried, _reconn_counter));
                        Thread.Sleep(500);

                        // check if reaches the max re-connect times
                        if (_reconn_counter > 10)
                        {
                            this.LastError = "the initialization process was timeout";
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.LastError = ex.Message;
                    break;
                }
            }

            return(IsConnected);
        }
 public static void Find()
 {
     USBInterface = new USBInterface("vid_067b", "pid_2303");
     USBInterface.Connect();
 }