Exemplo n.º 1
0
        private void ProcTimer_Tick(object sender, EventArgs e)
        {
            if (SerPort.IsOpen)
            {
                PortStatus.Text = "Opened";

                //ProcessSend();
            }
            else
            {
                try
                {
                    SerPort.PortName = PortList.Items[PortList.SelectedIndex].ToString();
                    SerPort.Open();
                    Log("Port Opened");
                }
                catch
                {
                    PortStatus.Text = "Error Opening";

                    bootload_enabled = false;
                    ButtonsSet(false, true, false);
                }
            }
        }
Exemplo n.º 2
0
 private void Looper_Tick(object sender, EventArgs e)
 {
     if (SerPort.IsOpen)
     {
         while (SerPort.BytesToRead > 0)
         {
             int  cint = SerPort.ReadByte();
             char c    = Convert.ToChar(cint);
             str += c;
             if (c == '\n')
             {
                 LogList.Items.Insert(0, str.Substring(0, str.Length - 2));
                 str = "";
             }
         }
     }
     else
     {
         try
         {
             SerPort.Open();
             LogList.Items.Insert(0, "Port Open");
         }
         catch
         {
             LogList.Items.Insert(0, "Cannot Open Port");
         }
     }
 }
Exemplo n.º 3
0
        public Form1()
        {
            workdir = Directory.GetCurrentDirectory();

            InitializeComponent();

            flash_data        = new short[65536];
            bootload_enabled  = false;
            CancelBtn.Enabled = false;

            stopwatch = new Stopwatch();
            stopwatch.Start();

            for (int i = 0; i < 32; i++)
            {
                SerPort.PortName = "COM" + Convert.ToString(i);
                try
                {
                    SerPort.Open();
                    PortList.Items.Add(SerPort.PortName);
                }
                catch
                {
                }
                try
                {
                    SerPort.Close();
                }
                catch
                {
                }
            }

            try
            {
                PortList.SelectedIndex = 0;
            }
            catch
            {
            }

            if (File.Exists("savefile.txt"))
            {
                StreamReader sr = new StreamReader("savefile.txt");

                AddToList(ref PortList, sr.ReadLine());

                for (int i = 0; i < 10; i++)
                {
                    AddToList(ref FilePathTxt, sr.ReadLine());
                }

                sr.Close();
            }

            DataProcessor.RunWorkerAsync();
        }
Exemplo n.º 4
0
        private void Checker_Tick(object sender, EventArgs e)
        {
            if (SerPort.IsOpen)
            {
                PortStatusLabel.Text = "Port Status: " + SerPort.PortName + " is Opened at " + Convert.ToString(SerPort.BaudRate) + " Baud";
            }
            else
            {
                PortStatusLabel.Text = "Port Status: Closed";
                is_playing           = false;
                try
                {
                    SerPort.PortName = "COM6";
                    SerPort.BaudRate = 57600;
                    SerPort.Open();
                }
                catch
                {
                    PortStatusLabel.Text = "Port Status: Error";
                }
            }

            if (is_playing)
            {
                PlayButton.Enabled  = false;
                CaliButton.Enabled  = false;
                AbortButton.Enabled = true;
                FileListBox.Enabled = false;
            }
            else
            {
                CaliButton.Enabled  = true;
                PlayButton.Enabled  = true;
                AbortButton.Enabled = false;
                FileListBox.Enabled = true;
                stop_watch.Stop();
            }

            PlayProgBar.Minimum = 0;
            PlayProgBar.Maximum = event_length;
            PlayProgBar.Value   = event_cnt;

            SongLengthLabel.Text      = Convert.ToString(length_of_song);
            TimeTakenLabel.Text       = Convert.ToString(time_taken);
            TimeTakenToPlayLabel.Text = Convert.ToString(time_taken_tp);

            PercentAdjLabel.Text = Convert.ToString(percent_adj * 100);
        }
Exemplo n.º 5
0
        private void PortList_SelectedIndexChanged(object sender, EventArgs e)
        {
            Log("Port Changed");
            try
            {
                SerPort.Close();
                SerPort.PortName = PortList.Items[PortList.SelectedIndex].ToString();
                SerPort.Open();
                Log("Port Opened");
            }
            catch
            {
                Log("Port Cannot be Opened");

                bootload_enabled = false;
                ButtonsSet(true, true, false);
            }
        }
Exemplo n.º 6
0
 private void Checker_Tick(object sender, EventArgs e)
 {
     if (SerPort.IsOpen)
     {
         PortStatusLabel.Text = "Port Status: " + SerPort.PortName + " is Opened at " + Convert.ToString(SerPort.BaudRate) + " Baud";
     }
     else
     {
         PortStatusLabel.Text = "Port Status: Closed";
         try
         {
             SerPort.PortName = "COM6";
             SerPort.BaudRate = 57600;
             SerPort.Open();
         }
         catch
         {
             PortStatusLabel.Text = "Port Status: Error";
         }
     }
 }
Exemplo n.º 7
0
        private void PortProcessor_Tick(object sender, EventArgs e)
        {
            if (SerPort.IsOpen)
            {
                int c;
                while (SerPort.BytesToRead != 0)
                {
                    c = SerPort.ReadByte();
                    if (c >= 0x80)
                    {
                        addr      = (c & 0x7F) >> 1;
                        data      = 0;
                        cnt       = 0;
                        sign_flag = c % 2;
                    }
                    else
                    {
                        data += (c << (7 * cnt));
                        cnt++;
                        if (cnt == 5)
                        {
                            double data_;

                            if ((c & 0x40) == 0x40)
                            {
                                data -= (c << (7 * (cnt - 1)));

                                if ((c & 0x20) == 0x20)
                                {
                                    data_ = (double)data * Math.Pow(10, -1 * (double)(c & 0x1F));
                                }
                                else
                                {
                                    data_ = (double)data * Math.Pow(10, (double)(c & 0x1F));
                                }
                            }
                            else
                            {
                                data_ = (double)data;
                            }

                            if (sign_flag != 0)
                            {
                                data_ *= -1;
                            }
                            try
                            {
                                DataList.Items[addr].SubItems[1].Text = Convert.ToString(data_);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            else
            {
                SerPort.BaudRate = 19200;
                try
                {
                    SerPort.PortName = "COM6";
                    SerPort.Open();
                }
                catch
                {
                    try
                    {
                        SerPort.PortName = "COM3";
                        SerPort.Open();
                    }
                    catch
                    {
                    }
                }
            }
        }