Exemple #1
0
 private void connect()
 {
     controller = JeromeController.create(currentConnection.jeromeParams);
     if (currentTemplate.uartEncoder)
     {
         controller.usartBytesReceived += usartBytesReceived;
     }
     controller.onDisconnected += onDisconnect;
     controller.onConnected    += onConnect;
     controller.usartBinaryMode = true;
     if (currentConnection.hwLimits)
     {
         controller.lineStateChanged += lineStateChanged;
     }
     controller.asyncConnect();
     updateGUI(
         delegate()
     {
         connectionsDropdown = new ToolStripMenuItem[miConnections.DropDownItems.Count];
         miConnections.Text  = "Отключиться";
         miConnections.DropDownItems.CopyTo(connectionsDropdown, 0);
         miConnections.DropDownItems.Clear();
         Text          = currentConnection.name + " идет соединение";
         lCaption.Text = Text;
         Icon          = (Icon)Resources.ResourceManager.GetObject(CommonInf.icons[currentConnection.icon]);
     });
 }
Exemple #2
0
        private void rotate(int newTarget)
        {
            System.Diagnostics.Debug.WriteLine("Rotate to " + newTarget.ToString());
            target = newTarget;
            if (activeConnection.controller == null || !activeConnection.controller.connected || position == newTarget)
            {
                return;
            }
            if (rotateTask == null)
            {
                rotateTask = TaskEx.Run(async() =>
                {
                    JeromeController controller = activeConnection.controller;
                    System.Diagnostics.Debug.WriteLine("start rotate to " + target.ToString());
                    blinkTimer.Change(1000, 1000);
                    controller.switchLine(controllerTemplate.enable, 0);
                    controller.switchLine(controllerTemplate.ptt, 1);
                    while (target != position && controller.connected)
                    {
                        int dir;
                        if (position == -1)
                        {
                            dir = target == buttonPositions[buttonPositions.Length - 1] ? 1 : -1;
                        }
                        else
                        {
                            dir = target < position ? -1 : 1;
                        }
                        controller.switchLine(controllerTemplate.dir, dir == -1 ? 0 : 1);
                        controller.switchLine(controllerTemplate.pulse, 1);
                        await TaskEx.Delay(5);
                        controller.switchLine(controllerTemplate.pulse, 0);
                        await TaskEx.Delay(5);
                        if (position != -1)
                        {
                            position += dir;
                        }

                        /*if (position == 0 || position == buttonPositions[buttonPositions.Count() - 1])
                         * {
                         *  System.Diagnostics.Debug.WriteLine("Limit reached " + position.ToString());
                         *  break;
                         * }*/
                    }
                    System.Diagnostics.Debug.WriteLine("Rotated to " + position.ToString());
                    controller.switchLine(controllerTemplate.pulse, 0);
                    controller.switchLine(controllerTemplate.enable, 1);
                    controller.switchLine(controllerTemplate.ptt, 0);
                    blinkTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    clearRotateTask();
                    Invoke((MethodInvoker) delegate { lRotation.Visible = false; });
                    if (position != target)
                    {
                        rotate(target);
                    }
                });
            }
        }
Exemple #3
0
 protected void connect(JeromeConnectionParams cp)
 {
     connections[cp].active     = true;
     connections[cp].controller = JeromeController.create(cp);
     connections[cp].controller.onDisconnected += controllerDisconnected;
     connections[cp].controller.onConnected    += controllerConnected;
     writeConfig();
     connections[cp].controller.asyncConnect();
 }
Exemple #4
0
        public FWX0B(JCAppContext _appContext, int __idx) : base(_appContext, __idx)
        {
            appContext = _appContext;
            _idx       = __idx;
            InitializeComponent();
            fStatus = new FWX0BStatus(this);
            foreach (WX0BTerminalSwitchTemplate st in TerminalTemplate.switches)
            {
                switches[st] = new WX0BTerminalSwitch(st);
                if (st.isDefault)
                {
                    defaultSwitch = switches[st];
                    activeSwitch  = switches[st];
                }
            }
            defForeColor = cbConnectTerminal.ForeColor;
            if (config.terminalConnectionParams == null)
            {
                config.terminalConnectionParams = new JeromeConnectionParams();
            }
            updateTerminalConnectionParamsCaption();
            terminalJConnection                   = JeromeController.create(config.terminalConnectionParams);
            terminalJConnection.onConnected      += TerminalJControllerConnected;
            terminalJConnection.onDisconnected   += TerminalJControllerDisconnected;
            terminalJConnection.lineStateChanged += TerminalJConnectionLineStateChanged;
            foreach (WX0BControllerConfigEntry cConfig in config.controllers)
            {
                createController(cConfig);
            }
            if (config.terminalConnectionParams != null)
            {
                cbConnectTerminal.Enabled = true;
                if (config.terminalActive)
                {
                    //new System.Threading.Timer(new TimerCallback(x => connectTerminal()), null, 5000, Timeout.Infinite);*/
                    connectTerminal();
                }
            }
            else
            {
                cbConnectTerminal.Enabled = false;
            }
            if (config.activeController != -1 && config.activeController < controllers.Count)
            {
                controllers[config.activeController].jConnection.asyncConnect();
            }
            else
            {
                setActiveController(-1);
            }

            if (config.statusOnly)
            {
                WindowState = FormWindowState.Minimized;
            }
        }
Exemple #5
0
 public void switchLine(JeromeController controller, int line, int state)
 {
     controller.switchLine(enLine, 0);
     controller.switchLine(line, state);
     //Thread.Sleep(1);
     controller.switchLine(clkLine, 1);
     //Thread.Sleep(1);
     controller.switchLine(clkLine, 0);
     controller.switchLine(enLine, 1);
 }
Exemple #6
0
        protected void controllerConnected(object sender, EventArgs e)
        {
            bool senderFound = false;
            KeyValuePair <JeromeConnectionParams, JeromeConnectionState> senderEntry =
                connections.FirstOrDefault(x => x.Value.controller == sender && (senderFound = true));

            if (!senderFound)
            {
                return;
            }
            JeromeConnectionParams cp = senderEntry.Key;

            this.Invoke((MethodInvoker) delegate
            {
                connections[cp].watch   = false;
                menuControl[cp].Checked = true;
                this.Text = cp.name;
                updateButtonsMode();
            });
            JeromeController controller = connections[cp].controller;
            string           linesState = controller.readlines();

            controller.setLineMode(controllerTemplate.dir, 0);
            controller.setLineMode(controllerTemplate.pulse, 0);
            controller.setLineMode(controllerTemplate.enable, 0);
            controller.setLineMode(controllerTemplate.ptt, 0);
            controller.switchLine(controllerTemplate.enable, 1);
            controller.switchLine(controllerTemplate.pulse, 0);
            controller.switchLine(controllerTemplate.ptt, 0);
            for (int co = 0; co < controllerTemplate.relays.Length; co++)
            {
                controller.setLineMode(controllerTemplate.relays[co], 0);
                controller.switchLine(controllerTemplate.relays[co], 0);
            }
            foreach (int line in controllerTemplate.limits.Values)
            {
                controller.setLineMode(line, 1);
            }
            controller.lineStateChanged += controllerLineStateChanged;
            if (linesState[controllerTemplate.limits[-1] - 1] == '0')
            {
                limit = -1;
            }
            else if (linesState[controllerTemplate.limits[1] - 1] == '0')
            {
                limit = 1;
            }
            if (position == -1)
            {
                rotate(0);
            }
        }
Exemple #7
0
 private async void disconnect()
 {
     if (timeoutTimer != null)
     {
         timeoutTimer.Dispose();
         timeoutTimer = null;
     }
     if (adcTimer != null)
     {
         adcTimer.Dispose();
         adcTimer = null;
     }
     if (controller != null)
     {
         if (engineStatus != 0)
         {
             engine(0);
         }
         if (engineTask != null)
         {
             await engineTask;
             engineTask.Dispose();
             engineTask = null;
         }
         if (engineTaskActive)
         {
             clearEngineTask();
         }
         if (currentTemplate.ledLine != 0)
         {
             toggleLine(currentTemplate.ledLine, 0);
         }
         if (currentTemplate.uartEncoder)
         {
             controller.usartBytesReceived -= usartBytesReceived;
         }
         if (closingFl)
         {
             controller.onDisconnected -= onDisconnect;
         }
         controller.onConnected -= onConnect;
         if (currentConnection.hwLimits)
         {
             controller.lineStateChanged -= lineStateChanged;
         }
         controller.disconnect();
         controller = null;
     }
 }
Exemple #8
0
 protected void connect(JeromeConnectionParams cp)
 {
     foreach (JeromeConnectionParams c in connections.Keys)
     {
         if (connections[c].active)
         {
             disconnect(c);
             menuControl[c].Checked = false;
         }
     }
     connections[cp].active     = true;
     connections[cp].controller = JeromeController.create(cp);
     connections[cp].controller.onDisconnected += controllerDisconnected;
     connections[cp].controller.onConnected    += controllerConnected;
     writeConfig();
     connections[cp].controller.asyncConnect();
     activeConnection = connections[cp];
 }
Exemple #9
0
        private void connect()
        {
            miConnections.Enabled = false;
            if (controller == null)
            {
                controller = JeromeController.create(currentConnection.jeromeParams);
            }
            UseWaitCursor = true;
            if (controller.connect())
            {
                miConnections.Text         = "Отключиться";
                controller.usartBinaryMode = true;
                if (currentConnection.hwLimits)
                {
                    controller.lineStateChanged += lineStateChanged;
                }
                controller.usartBytesReceived += usartBytesReceived;
                controller.disconnected       += onDisconnect;
                connectionsDropdown            = new ToolStripMenuItem[miConnections.DropDownItems.Count];
                miConnections.DropDownItems.CopyTo(connectionsDropdown, 0);
                miConnections.DropDownItems.Clear();

                miConnectionGroups.Visible = false;
                //miConnectionParams.Enabled = false;


                setLine(currentTemplate.ledLine, 0);
                foreach (int[] dir in currentTemplate.engineLines.Values)
                {
                    foreach (int line in dir)
                    {
                        setLine(line, 0);
                        toggleLine(line, 0);
                    }
                }
                setLine(currentTemplate.uartTRLine, 0);
                foreach (int line in currentTemplate.limitsLines.Values)
                {
                    setLine(line, 1);
                }

                timer.Enabled = true;

                miSetNorth.Visible = true;
                miSetNorth.Enabled = true;

                Text          = currentConnection.name;
                lCaption.Text = currentConnection.name;
                if (currentConnectionGroup != null)
                {
                    Text += " (" + currentConnectionGroup.name + ")";
                }
                Icon = (Icon)Resources.ResourceManager.GetObject(CommonInf.icons[currentConnection.icon]);
                if (currentConnection.hwLimits)
                {
                    string lines = controller.readlines();
                    foreach (KeyValuePair <int, int> kv in currentTemplate.limitsLines)
                    {
                        if (lines[kv.Value - 1] == '0')
                        {
                            onLimit(kv.Key);
                        }
                    }
                }
                else if (currentConnection.northAngle != -1)
                {
                    currentConnection.limits = new Dictionary <int, int> {
                        { 1, currentConnection.northAngle + 180 }, { -1, currentConnection.northAngle + 180 }
                    }
                }
                ;
                scheduleTimeoutTimer();
            }
            else
            {
                showMessage("Подключение не удалось", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            miConnections.Enabled = true;
            UseWaitCursor         = false;
        }
Exemple #10
0
 public WX0BController(WX0BControllerConfigEntry _config)
 {
     config      = _config;
     jConnection = JeromeController.create(config.connectionParams);
 }