Esempio n. 1
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);
            }
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
        private void onConnect(object sender, EventArgs e)
        {
            if (currentTemplate.adc != 0)
            {
                adcTimer = new System.Threading.Timer(obj => readADC(), null, 100, 100);
            }

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



            this.Invoke((MethodInvoker) delegate()
            {
                timer.Enabled      = true;
                miSetNorth.Visible = true;
                miSetNorth.Enabled = true;
                pMap.Enabled       = true;
                if (currentTemplate.adc != 0)
                {
                    miCalibrate.Visible = true;
                }

                Text          = currentConnection.name;
                lCaption.Text = currentConnection.name;
                Icon          = (Icon)Resources.ResourceManager.GetObject(CommonInf.icons[currentConnection.icon]);
            });
            if (currentTemplate.uartEncoder)
            {
                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();
            }
        }