예제 #1
0
파일: Form1.cs 프로젝트: grasmanek94/t22-4
 public Form1()
 {
     InitializeComponent();
     arduino = new Arduino(1, "COM17", 9600);
     if (arduino.Connect())
     {
         __RP6Control = new RP6Control(arduino);
         controlTimer.Start();
     }
     else
     {
         MessageBox.Show("failed connecting");
     }
 }
예제 #2
0
        public TrainConnection(CTrafficMessage trafficMessage)
        {
            administration = Program._Administration;

            TrafficMessage = trafficMessage;

            connectedTrains = new List<Arduino>();
            _IP2ARDUINO = new Dictionary<IPEndPoint, Arduino>();
            _ARDUINO2IP = new Dictionary<Arduino, IPEndPoint>();
            _ID2ARDUINO = new Dictionary<int, Arduino>();
            _ARDUINO2ID = new Dictionary<Arduino, int>();
            _ARDUINO2TRAIN = new Dictionary<Arduino, Train>();

            string[] ports = System.IO.Ports.SerialPort.GetPortNames();
            int id = 1;
            foreach(string port in ports)
            {
                IPEndPoint endpoint = new IPEndPoint(new IPAddress(0xA9FE0000+ArduinoIdToIPAddress(id)), 3333);//169.254.0.0+id:3333
                Arduino a = new Arduino(id, port);
                Train arduinoTrain = new Train(id, int.Parse(port.Remove(0, 3)));

                connectedTrains.Add(a);
                AddArduino(endpoint, a, arduinoTrain);

                try
                {
                    a.Connect();
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                id++;
            }

            //_timer = new Timer(1000.0);
            //_timer.Elapsed += Tick;
            _timer = new System.Windows.Forms.Timer();
            _timer.Interval = 127;
            _timer.Tick += _timer_Tick; ;
            _timer.Enabled = true;
            _timer.Start();

            Program._TrainConnection = this;
        }
예제 #3
0
 public RP6Control(Arduino arduino)
 {
     _arduino = arduino;
     _moveMessage = new MMessage();
 }
예제 #4
0
 private void AddArduino(IPEndPoint endPoint, Arduino arduino, Train train)
 {
     _IP2ARDUINO.Add(endPoint, arduino);
     _ARDUINO2IP.Add(arduino, endPoint);
     _ID2ARDUINO.Add(arduino.Id, arduino);
     _ARDUINO2ID.Add(arduino, arduino.Id);
     _ARDUINO2TRAIN.Add(arduino, train);
 }