Esempio n. 1
0
        public TrainDrukteForm()
        {
            InitializeComponent();
            timer1.Start();

            _arduino    = null;
            _ledControl = null;

            _byteViewer      = new ByteViewer();
            _byteViewer.Dock = DockStyle.Fill;
            panel1.Controls.Add(_byteViewer);

            _trackBars = new TrackBar[6] {
                tb1, tb2, tb3, tb4, tb5, tb6
            };
            _colorCodes = new Color[3] {
                Color.White, Color.Green, Color.Red
            };

            SetBarsState(false);

            foreach (TrackBar bar in _trackBars)
            {
                bar.ValueChanged += bars_ValueChanged;
            }

            _trafficStates = new Color[6];

            Messages = new List <Message>();

            cbCom.Items.AddRange(SerialPort.GetPortNames());
        }
Esempio n. 2
0
        private void connectbutton_Click(object sender, EventArgs e)
        {
            if (_ledControl == null)
            {
                try
                {
                    _arduino    = new Arduino(0, cbCom.SelectedItem.ToString());
                    _ledControl = new LedControl.LedControl(_arduino, 6, (byte)maxLedsNUP.Value);
                }
                catch (IOException exception)
                {
                    MessageBox.Show(exception.Message);
                }
                catch (InvalidOperationException exception)
                {
                    MessageBox.Show(exception.Message);
                }
                if (_arduino != null)
                {
                    _arduino.Connect();
                }
                _ledControl.InitializeLedStrip();
            }

            if (_arduino != null && _ledControl != null && _arduino.IsConnected)
            {
                SetBarsState(true);
                MessageBox.Show("Connected");
            }
        }
Esempio n. 3
0
        public TrainDrukteForm()
        {
            InitializeComponent();
            timer1.Start();

            _arduino = null;
            _ledControl = null;

            _byteViewer = new ByteViewer();
            _byteViewer.Dock = DockStyle.Fill;
            panel1.Controls.Add(_byteViewer);

            _trackBars = new TrackBar[6]{ tb1, tb2, tb3, tb4, tb5, tb6 };
            _colorCodes = new Color[3] { Color.White, Color.Green, Color.Red };

            SetBarsState(false);

            foreach (TrackBar bar in _trackBars)
            {
                bar.ValueChanged += bars_ValueChanged;
            }

            _trafficStates = new Color[6];

            Messages = new List<Message>();

            cbCom.Items.AddRange(SerialPort.GetPortNames());
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        private void connectbutton_Click(object sender, EventArgs e)
        {
            if (_ledControl == null)
            {
                try
                {
                    _arduino = new Arduino(0, cbCom.SelectedItem.ToString());
                    _ledControl = new LedControl.LedControl(_arduino, 6, (byte)maxLedsNUP.Value);
                }
                catch (IOException exception)
                {
                    MessageBox.Show(exception.Message);
                }
                catch (InvalidOperationException exception)
                {
                    MessageBox.Show(exception.Message);
                }
                if (_arduino != null)
                {
                    _arduino.Connect();
                }
                _ledControl.InitializeLedStrip();
            }

            if (_arduino != null && _ledControl != null && _arduino.IsConnected)
            {
                SetBarsState(true);
                MessageBox.Show("Connected");
            }
        }