Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var serialHandler = new SerialHandler();

            serialHandler.InitSerial("COM3");
            var t = new Thread(() => serialHandler.RequestJvsInformation());

            t.Start();
            //serialHandler.CloseSerial();
        }
Пример #2
0
        private void HandleTraffic()
        {
            Thread.Sleep(1000);
            KillTheThread = false;
            var serialHandler = new SerialHandler();

            serialHandler.InitSerial("COM3");
            var jvsThread = new Thread(() => serialHandler.RequestJvsInformation());

            jvsThread.Start();
            var keyb       = new KeyboardInjector.KeyboardInject();
            var idSet      = false;
            var vJoyFeeder = new vJoyInjector.VJoyFeeder();

            while (!KillTheThread)
            {
                if (!serialHandler.JvsInformation.SyncOk)
                {
                    Thread.Sleep(10);
                    continue;
                }

                if (!jvsThread.IsAlive)
                {
                    Thread.Sleep(100);
                    jvsThread = new Thread(() => serialHandler.RequestJvsInformation());
                    jvsThread.Start();
                    Thread.Sleep(100);
                }
                vJoyFeeder.Digitals       = serialHandler.JvsInformation.DigitalBytes;
                vJoyFeeder.AnalogChannels = serialHandler.JvsInformation.AnalogChannels;
                if (idSet)
                {
                    keyb.SendInputs(serialHandler.JvsInformation.DigitalBytes);
                }
                if (!idSet && serialHandler.JvsInformation.JvsIdentifier != "")
                {
                    idSet = true;
                    //keyb.Initialize();
                    new Thread(vJoyFeeder.StartInjector).Start();
                    Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
                    {
                        TxtJvsIo.Text += serialHandler.JvsInformation.JvsIdentifier;
                        TxtJvsCmd.Text += serialHandler.JvsInformation.CmdFormatVersion.ToString("X2");
                        TxtJvsVersion.Text += serialHandler.JvsInformation.JvsVersion.ToString("X2");
                        TxtJvsComm.Text += serialHandler.JvsInformation.CommVersion.ToString("X2");
                    }));
                }
                Thread.Sleep(10);
            }
            vJoyFeeder.KillMe = true;
            serialHandler.CloseSerial();
        }