示例#1
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            SenderThread.Start();
            phidgetReciver.Start();
            arduinoReciver.Start();
            arduinoSender.Start();
            motionCalculator.Start();
            dataExchanger.Start();
            DataExchangerThread.Start();
            StartButton.Enabled = false;
            //var sw = System.IO.File.AppendText("c:\\tmp\\runlog.csv");
            for (int i = 0; i < listOfKHEdits.Count; i++)
            {
                listOfKHEdits[i].Text = motionCalculator.getSetupAt(i).KoeffH.ToString();
                listOfKVEdits[i].Text = motionCalculator.getSetupAt(i).KoeffV.ToString();
            }
            while (!abort)
            {
                for (int i = 0; i < phidgetReciver.Count(); i++)
                {
                    listOfLEdits[i].Text = (motionCalculator.getSetupAt(i).Load- motionCalculator.getSetupAt(i).ZeroLoad).ToString("#.##");
                    listOfPEdits[i].Text = arduinoReciver.getValueOf(i).ToString("000");
                    listOfTEdits[i].Text = motionCalculator.getSetupAt(i).Direction + motionCalculator.getSetupAt(i).Torque.ToString("#.##");
                    listOfSEdits[i].Text = (motionCalculator.getSetupAt(i).KoeffHSign * motionCalculator.getSetupAt(i).CurKoeffH).ToString("#.##");
                }
                //sw.WriteLine(motionCalculator.getSetupAt(4).LastDiff + "," + phidgetReciver.getValueOf(4).ToString() + "," + motionCalculator.getSetupAt(4).Torque.ToString("#.##")+","+ motionCalculator.getSetupAt(5).LastDiff + "," + phidgetReciver.getValueOf(5).ToString() + "," + motionCalculator.getSetupAt(5).Torque.ToString("#.##"));
                //Thread.Sleep(10);
                Application.DoEvents();
            }
            //sw.Close();

        }
示例#2
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            phidgetReciver.Start();

            for (int i = 0; i < phidgetReciver.Count(); i++)
            {
                TestSetup testSetup = new TestSetup();
                testSetup.ArduinoPort            = MotorsCPort[i];
                testSetup.MotorId                = i;
                testSetup.TargetLoad             = 0;
                testSetup.LastDiff               = 0;
                testSetup.LastRead               = testSetup.TargetLoad;
                testSetup.MinPos                 = AxisLimits[i][0];
                testSetup.MaxPos                 = AxisLimits[i][1];
                testSetup.FirstPick              = true;
                testSetup.PositionRequestCommand = "{P" + testSetup.MotorId.ToString() + "}";
                testSetup.MoveCommand            = "M" + testSetup.MotorId.ToString() + ",{0},{1}";
                testSetup.Torque                 = 0;
                testSetup.Direction              = 'S';
                testSetup.Koeff = 1;
                listOfSetups.Add(testSetup);
            }



            // configure serial port
            int lastPort = 0;

            for (int i = 0; i < MotorsCPort.Count; i++)
            {
                if (lastPort < MotorsCPort[i])
                {
                    lastPort = MotorsCPort[i];
                    SerialPort serialPort = new SerialPort();
                    listofPorts.Add(serialPort);
                    listofPorts[i].BaudRate       = 115200;
                    listofPorts[i].PortName       = "COM" + MotorsCPort[i];
                    listofPorts[i].DataReceived  += SerialPort_DataReceived;
                    listofPorts[i].ErrorReceived += SerialPort_ErrorReceived;
                    listofPorts[i].DtrEnable      = true;
                    listofPorts[i].Open();
                    listofPorts[i].ReadExisting();
                }
            }
            StartButton.Enabled = false;
            StopButton.Enabled  = true;
        }
示例#3
0
        public void ThreadRun()
        {
            initializeExchanger();
            System.Diagnostics.Trace.WriteLine("DataExchanger started");

            while (!abort)
            {
                while (!abort)
                {
                    for (int i = 0; i < phidgetReciver.Count(); i++)
                    {
                        motionCalculator.getSetupAt(i).Load     = phidgetReciver.getValueOf(i);
                        motionCalculator.getSetupAt(i).Position = arduinoReciver.getValueOf(i);
                        arduinoSender.setValueOf(i, motionCalculator.getSetupAt(i).Torque, motionCalculator.getSetupAt(i).Direction);
                    }
                }
            }

            System.Diagnostics.Trace.WriteLine("DataExchanger stopped");
        }