public Form1() { InitializeComponent(); arduino = new Arduino(1, "COM17", 9600); if (arduino.Connect()) { __RP6Control = new RP6Control(arduino); controlTimer.Start(); } else { MessageBox.Show("failed connecting"); } }
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 RP6Control(Arduino arduino) { _arduino = arduino; _moveMessage = new MMessage(); }
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); }