public TrainStationProcessor(System.Windows.Forms.Label label)
        {
            rand = new Random();

            ip = "localhost:8000";

            if(!File.Exists("ip.txt"))
            {
                File.Create("ip.txt");
            }
            if(File.Exists("ip.txt"))
            {
                try
                {
                    string temp = File.ReadAllText("ip.txt");
                    if (!string.IsNullOrEmpty(temp) && !string.IsNullOrWhiteSpace(temp) && temp.Length > 2)
                    {
                        ip = temp;
                    }
                }
                catch(Exception)
                {

                }
            }

            if (!localOnly)
            {
                _service = new TrafficMessageClient("BasicHttpBinding_ITrafficMessage", "http://" + ip + "/MEX/MessageService");
                //_service = new TrafficMessageClient();

                _inMessage = new ServerMessage();
                _outMessage = new ServerMessage();
            }

            string[] comports = System.IO.Ports.SerialPort.GetPortNames();
            if (comports.Length > 0)
            {
                _arduino = new Arduino(0, System.IO.Ports.SerialPort.GetPortNames()[0]);
                _ledControl = new LedControl(_arduino, 6, 50);
                try
                {
                    _arduino.Connect();
                    _ledControl.InitializeLedStrip();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            //_timer = new Timer(500.0);
            //_timer.Elapsed += Tick;
            _timer = new System.Windows.Forms.Timer();
            _timer.Interval = 127;
            _timer.Tick += _timer_Tick;
            _timer.Enabled = true;
            _timer.Start();
        }
示例#2
0
        public TrainStationProcessor(System.Windows.Forms.Label label)
        {
            rand = new Random();

            ip = "localhost:8000";

            if (!File.Exists("ip.txt"))
            {
                File.Create("ip.txt");
            }
            if (File.Exists("ip.txt"))
            {
                try
                {
                    string temp = File.ReadAllText("ip.txt");
                    if (!string.IsNullOrEmpty(temp) && !string.IsNullOrWhiteSpace(temp) && temp.Length > 2)
                    {
                        ip = temp;
                    }
                }
                catch (Exception)
                {
                }
            }

            if (!localOnly)
            {
                _service = new TrafficMessageClient("BasicHttpBinding_ITrafficMessage", "http://" + ip + "/MEX/MessageService");
                //_service = new TrafficMessageClient();

                _inMessage  = new ServerMessage();
                _outMessage = new ServerMessage();
            }

            string[] comports = System.IO.Ports.SerialPort.GetPortNames();
            if (comports.Length > 0)
            {
                _arduino    = new Arduino(0, System.IO.Ports.SerialPort.GetPortNames()[0]);
                _ledControl = new LedControl(_arduino, 6, 50);
                try
                {
                    _arduino.Connect();
                    _ledControl.InitializeLedStrip();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

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