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; }
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; }