コード例 #1
0
ファイル: ControllerManager.cs プロジェクト: api182/XOutput
        public override bool Start()
        {
            Console.WriteLine(Process.GetCurrentProcess().MainWindowHandle);
            Open();
            detectControllers();
            running = true;
            for (int i = 0; i < 4; i++)
            {
                if (devices[i] != null && devices[i].enabled)
                {
                    //Need to figure this out for multiple controllers...
                    compensationValue = devices[i].mapping[devices[i].mapping.Length - 1];

                    running           = true;
                    processingData[i] = new ContData();
                    Console.WriteLine("Plug " + i);
                    Plugin(i + 1);
                    int t = i;
                    workers[i] = new Thread(() =>
                                            { ProcessData(t); });
                    workers[i].Start();
                }
            }

            return(running);
        }
コード例 #2
0
ファイル: ControllerManager.cs プロジェクト: ImJezze/XOutput
        public override bool Start()
        {
            Open();
            detectControllers();

            for (int i = 0; i < deviceCount; i++)
            {
                if (devices[i] != null && devices[i].enabled)
                {
                    Resize(ref processingData, i + 1);
                    Resize(ref ds4locks, i + 1);
                    Resize(ref workers, i + 1);

                    processingData[i] = new ContData();
                    ds4locks[i]       = new object();
                    Plugin(i + 1);
                    Console.WriteLine("Plugged in device {0} at slot {1}. ", devices[i].name, i);
                    int t = i;
                    workers[i] = new Thread(() =>
                                            { ProcessData(t); });
                    workers[i].Start();

                    if (isExclusive)
                    {
                        devices[i].joystick.Unacquire();
                        devices[i].joystick.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
                        devices[i].joystick.Acquire();
                        Console.WriteLine("Device {0}'s cooperative level set to exclusive.", devices[i].joystick.Information.InstanceName);
                    }
                }
            }

            running = true;
            return(running);
        }
コード例 #3
0
        void tws_ContractDetails(object sender, ContractDetailsEventArgs e)
        {
            // get contact object
            if (!cont_list.ContainsKey(e.RequestId))
            {
                return;
            }
            ContData c = cont_list[e.RequestId];

            c.contracts.Add(e);
        }
コード例 #4
0
        void tws_ContractDetailsEnd(object sender, ContractDetailsEndEventArgs e)
        {
            // get contact object
            if (!cont_list.ContainsKey(e.RequestId))
            {
                return;
            }
            ContData c = cont_list[e.RequestId];

            // release waiting thread
            c.ready_event.Set();
        }
コード例 #5
0
        void tws_Error(object sender, Krs.Ats.IBNet.ErrorEventArgs e)
        {
            if (tick_list.ContainsKey(e.TickerId))
            {
                TickData t = tick_list[e.TickerId];
                t.error_code = e.ErrorCode;
                t.ready_event.Set();
            }
            else if (cont_list.ContainsKey(e.TickerId))
            {
                ContData c = cont_list[e.TickerId];
                c.error_code = e.ErrorCode;
                c.ready_event.Set();
            }
            else if (e.ErrorCode == ErrorMessage.NotConnected)
            {
                Connect = false;
            }
            else if (e.ErrorMsg.Contains("max rate"))
            {
                Thread.Sleep(1000 + tws_backoff_time);
            }
            else if (e.ErrorMsg.StartsWith("Max number of tickers has been reached"))
            {
                if (!tws_err_max_tickers_reached)
                {
                    MessageBox.Show("Max number of tickers has been reached.\nPlease reduce number of parallel tickers in plug-in configuration, or number of active tickers in TWS.    ", "Interactive Brokers Plug-In - TWS Error Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    tws_err_max_tickers_reached = true;
                }
            }
            else if (e.ErrorMsg.StartsWith("Connectivity between IB and TWS has been lost"))
            {
                MessageBox.Show("Connectivity between IB and TWS has been lost.    ", "Interactive Brokers Plug-In - TWS Error Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Connect = false;
            }
            else if (e.ErrorMsg.StartsWith("Market data farm connection is OK") ||
                     e.ErrorMsg.StartsWith("Can't find EId with tickerId") ||
                     e.ErrorMsg.StartsWith("No historical data query found for ticker id") ||
                     e.ErrorMsg.StartsWith("AlreadyConnected"))
            {
                // ignore
            }
#if DEBUG
            else
            {
                MessageBox.Show(e.ErrorMsg, "TWS Client Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
#endif
        }
コード例 #6
0
ファイル: ControllerManager.cs プロジェクト: MarcGeh/XOutput
 public override bool Start()
 {
     Console.WriteLine(Process.GetCurrentProcess().MainWindowHandle);
     Open();
     keyb.Acquire();
     DetectControllers();
     if (device != null)
     {
         if (!running)
         {
             running               = true;
             processingData        = new ContData();
             controllerNrPluggedIn = controllerIndex + 1;
             Console.WriteLine("Plug in XBox controller " + controllerNrPluggedIn.ToString());
             Plugin(controllerNrPluggedIn);
             worker = new Thread(() =>
                                 { ProcessData(); });
             worker.Start();
         }
     }
     return(running);
 }
コード例 #7
0
ファイル: ControllerManager.cs プロジェクト: alfrix/XOutput
        public override bool Start()
        {
            Console.WriteLine(Process.GetCurrentProcess().MainWindowHandle);
            Open();
            detectControllers();
            running = true;
            for (int i = 0; i < 4; i++)
            {
                if (devices[i] != null && devices[i].enabled)
                {
                    running           = true;
                    processingData[i] = new ContData();
                    Console.WriteLine("Plug " + i);
                    Plugin(i + 1);
                    int t = i;
                    workers[i] = new Thread(() =>
                                            { ProcessData(t); });
                    workers[i].Start();
                }
            }

            return(running);
        }
コード例 #8
0
ファイル: ControllerManager.cs プロジェクト: api182/XOutput
        public ControllerDevice[] detectControllers()
        {
            for (int i = 0; i < 4; i++) //Remove disconnected controllers
            {
                if (devices[i] != null && !directInput.IsDeviceAttached(devices[i].joystick.Information.InstanceGuid))
                {
                    Console.WriteLine(devices[i].joystick.Properties.InstanceName + " Removed");
                    devices[i] = null;
                    workers[i].Abort();
                    workers[i] = null;
                    Unplug(i + 1);
                }
            }

            foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                Joystick joystick = new Joystick(directInput, deviceInstance.InstanceGuid);

                if (joystick.Information.ProductGuid.ToString() == "028e045e-0000-0000-0000-504944564944") //If its an emulated controller skip it
                {
                    continue;
                }

                if (joystick.Capabilities.ButtonCount < 1 && joystick.Capabilities.AxesCount < 1) //Skip if it doesn't have any button and axes
                {
                    continue;
                }

                int spot = -1;
                for (int i = 0; i < 4; i++)
                {
                    if (devices[i] == null)
                    {
                        if (spot == -1)
                        {
                            spot = i;
                            Console.WriteLine("Open Spot " + i.ToString());
                        }
                    }
                    else if (devices[i] != null && devices[i].joystick.Information.InstanceGuid == deviceInstance.InstanceGuid) //If the device is already initialized skip it
                    {
                        Console.WriteLine("Controller Already Acquired " + i.ToString() + " " + deviceInstance.InstanceName);
                        spot = -1;
                        break;
                    }
                }

                if (spot == -1)
                {
                    continue;
                }

                if (isExclusive)
                {
                    joystick.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
                }
                else
                {
                    joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Background);
                }
                joystick.Properties.BufferSize = 128;
                joystick.Acquire();

                devices[spot] = new ControllerDevice(joystick, spot + 1);
                if (IsActive)
                {
                    processingData[spot] = new ContData();
                    Console.WriteLine("Plug " + spot);
                    Plugin(spot + 1);
                    int t = spot;
                    workers[spot] = new Thread(() =>
                                               { ProcessData(t); });
                    workers[spot].Start();
                }
            }
            return(devices);
        }
コード例 #9
0
        public ContData RequestDetails(string symbol, string exchange, string primary_exchange, SecurityType type, string currency, bool cache_ok)
        {
            // make sure we are connected
            if (!Connect)
            {
                Connect = true;
                if (!Connect)
                {
                    return(null);
                }
            }

            // check cache
            string cache_key = symbol + "," + exchange + "," + primary_exchange + "," + type.ToString() + "," + currency;

            if (cont_cache.ContainsKey(cache_key) && cache_ok)
            {
                ContData c_cache = cont_cache[cache_key];
                if (c_cache.contracts.Count > 0 &&
                    c_cache.timestamp.Date == DateTime.Now.Date)
                {
                    return(c_cache);
                }
            }

            // get id from id queue
            if (id_queue.Count == 0)
            {
                return(null);
            }
            int id = id_queue.Dequeue();

            // get tick object
            if (!cont_list.ContainsKey(id))
            {
                cont_list[id] = new ContData(id);
            }
            ContData c = cont_list[id];

            c.timestamp = DateTime.Now;

            // request underlying contract
            Contract contract = new Contract(symbol, exchange, type, currency);

            contract.PrimaryExchange = primary_exchange;
            tws.RequestContractDetails(id, contract);

            // wait for result
            c.ready_event.WaitOne(new TimeSpan(0, 0, tws_quote_timeout * 2), false);

            // remove tick from list
            cont_list.Remove(id);

            // return id to id queue
            id_queue.Enqueue(id);

            // keep in cache
            if (cont_cache.ContainsKey(cache_key))
            {
                cont_cache[cache_key] = c;
            }
            else
            {
                if (cont_cache.Count >= MAX_CACHE_SIZE)
                {
                    cont_cache.Remove(cont_cache.Keys.GetEnumerator().Current);
                }

                cont_cache.Add(cache_key, c);
            }

            return(c);
        }
コード例 #10
0
        public ControllerDevice[] detectControllers()
        {
            for (int i = 0; i < 4; i++) //Remove disconnected controllers
            {
                if (devices[i] != null && !directInput.IsDeviceAttached(devices[i].joystick.Information.InstanceGuid))
                {
                    Console.WriteLine(devices[i].joystick.Properties.InstanceName + " Removed");
                    devices[i] = null;
                    workers[i].Abort();
                    workers[i] = null;
                    Unplug(i + 1);
                }
            }

            foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                Joystick joystick = new Joystick(directInput, deviceInstance.InstanceGuid);

                if (joystick.Information.ProductGuid.ToString() == "028e045e-0000-0000-0000-504944564944") //If its an emulated controller skip it
                    continue;

                if (joystick.Capabilities.ButtonCount < 1 && joystick.Capabilities.AxesCount < 1) //Skip if it doesn't have any button and axes
                    continue;

                int spot = -1;
                for (int i = 0; i < 4; i++)
                {
                    if (devices[i] == null)
                    {
                        if (spot == -1)
                        {
                            spot = i;
                            Console.WriteLine("Open Spot " + i.ToString());
                        }
                    }
                    else if (devices[i] != null && devices[i].joystick.Information.InstanceGuid == deviceInstance.InstanceGuid) //If the device is already initialized skip it
                    {
                        Console.WriteLine("Controller Already Acquired " + i.ToString() + " " + deviceInstance.InstanceName);
                        spot = -1;
                        break;
                    }
                }

                if (spot == -1)
                    continue;

                if (isExclusive)
                {
                    joystick.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
                }
                else
                {
                    joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Background);
                }
                joystick.Properties.BufferSize = 128;
                joystick.Acquire();

                devices[spot] = new ControllerDevice(joystick, spot + 1);
                if (IsActive)
                {
                    processingData[spot] = new ContData();
                    Console.WriteLine("Plug " + spot);
                    Plugin(spot + 1);
                    int t = spot;
                    workers[spot] = new Thread(() =>
                    { ProcessData(t); });
                    workers[spot].Start();
                }
            }
            return devices;
        }
コード例 #11
0
        public override bool Start()
        {
            Console.WriteLine(Process.GetCurrentProcess().MainWindowHandle);
            Open();
            detectControllers();
            running = true;
            for (int i = 0; i < 4; i++)
            {
                if (devices[i] != null && devices[i].enabled)
                {
                    running = true;
                    processingData[i] = new ContData();
                    Console.WriteLine("Plug " + i);
                    Plugin(i + 1);
                    int t = i;
                    workers[i] = new Thread(() =>
                    { ProcessData(t); });
                    workers[i].Start();
                }
            }

            return running;
        }