private void buttonL4Off_Click(object sender, EventArgs e)
        {
            dataPacket[2] = (byte)4;
            dataPacket[3] = (byte)0;

            MySerial.Write(dataPacket, 0, dataPacket.Length);
        }
Ejemplo n.º 2
0
        //Нажатие на кнопку "Открыть ранее закрытый файл"
        private void button4_Click(object sender, EventArgs e)
        {
            Form1.filename = Environment.CurrentDirectory + "\\" + "Cars\\" + MyReg.ValueGet();
            Form1.list     = MySerial <List <CarClass> > .Deserialize(Form1.filename);

            Close();
        }
Ejemplo n.º 3
0
        // Общий метод сохранения
        public void SaveMetodFile()
        {
            if (filename == "") // Если это Новый файл
            {
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.InitialDirectory = Environment.CurrentDirectory + "\\" + "Team"; // Получаем путь директории, куда сохранять
                saveFileDialog1.Filter           = "xml files (*.xml)|*.xml";                    // Маска файла

                if (saveFileDialog1.ShowDialog() == DialogResult.Cancel)
                {
                    this.Text = NameForm + "Новый файл";
                    return;
                }
                filename = saveFileDialog1.FileName; // Получаем путь текущего файла
                MySerial <List <WorldCup2018> > .Serialize(filename, List);

                this.Text = NameForm + filename.Substring(filename.LastIndexOf("\\") + 1) + " - Сохранено";
                //MessageBox.Show("Файл сохранен");
            }
            else
            {
                File.Delete(filename);
                MySerial <List <WorldCup2018> > .Serialize(filename, List);

                this.Text = NameForm + filename.Substring(filename.LastIndexOf("\\") + 1) + " - Сохранено";
                //MessageBox.Show("Файл сохранен");
            }
            FlagCheck = false;
        }
Ejemplo n.º 4
0
        //Нажатие пунка "Открыть"
        private void открытьToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            SaveFile();

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = Environment.CurrentDirectory + "\\" + "Team";
            openFileDialog1.Filter           = "xml files (*.xml)|*.xml";

            if (openFileDialog1.ShowDialog() == DialogResult.Cancel) //Открытие диалогового окна
            {
                return;
            }
            // получаем выбранный файл

            filename = openFileDialog1.FileName;
            list     = MySerial <List <CarClass> > .Deserialize(filename);

            carClassBindingSource.DataSource = list;
            carClassBindingSource.ResetBindings(false);
            if (filename == "")
            {
                this.Text = "Автосалон - Новый";
            }
            else
            {
                this.Text = "Автосалон" + " - " + filename.Substring(filename.LastIndexOf("\\") + 1);
            }
        }
Ejemplo n.º 5
0
        protected void ConnectToArduino(object sender, EventArgs e)
        {
            try
            {
                //serial = new MySerial(int.Parse(port.Text));
                serial = new MySerial(int.Parse(port.Text));
            }
            catch
            {
                ArduinoConnectionButton2.Text = "Error!";
                serial = null;
            }


            if (serial == null)
            {
                ArduinoConnectionButton2.CssClass = "btn btn-danger";
                ArduinoConnectionButton2.Text     = "Connection to Arduino failed";
            }
            else
            {
                ArduinoConnectionButton2.CssClass = "btn btn-success";
                ArduinoConnectionButton2.Text     = " Connected";
                tempIncreaser.Enabled             = true;
                tempDecreaser.Enabled             = true;
                tempIncreaser.CssClass            = "btn btn-danger";
                tempDecreaser.CssClass            = "btn btn-info";
                RefreshData();
            }
        }
Ejemplo n.º 6
0
        private void button4_Click(object sender, EventArgs e)
        {
            Form1.filename = Environment.CurrentDirectory + "\\" + "Team\\" + MyReg.ValueGet();
            Form1.List     = MySerial <List <WorldCup2018> > .Deserialize(Form1.filename);

            Form1.FlagCheck = false;
            Close();
        }
Ejemplo n.º 7
0
        private void ProductRegistry_Load(object sender, EventArgs e)
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard");

            foreach (ManagementObject MySerial in searcher.Get())
            {
                string bserial = MySerial.GetPropertyValue("SerialNumber").ToString();
                txtcopycode.Text = AesCrypt.Encrypt(bserial);
            }
            ProductRegistry pf = new ProductRegistry();
        }
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (!MySerial.IsOpen)
            {
                try
                {
                    MySerial.PortName      = Convert.ToString(comboPorts.Text);
                    MySerial.BaudRate      = Convert.ToInt32(comboBaud.Text);
                    MySerial.DataBits      = Convert.ToInt16(comboBits.Text);
                    MySerial.Parity        = (Parity)Enum.Parse(typeof(Parity), comboParity.Text);
                    MySerial.StopBits      = (StopBits)Enum.Parse(typeof(StopBits), comboStopBit.Text);
                    MySerial.DataReceived += new SerialDataReceivedEventHandler(SerialPort_ReceivedEvent);
                    MySerial.Handshake     = (Handshake)Enum.Parse(typeof(Handshake), comboBoxHandShake.Text);
                    MySerial.Open();

                    buttonConnect.Text        = "Disconnect";
                    comboPorts.Enabled        = false;
                    comboBaud.Enabled         = false;
                    comboBits.Enabled         = false;
                    comboParity.Enabled       = false;
                    comboStopBit.Enabled      = false;
                    comboBoxHandShake.Enabled = false;

                    groupBoxIO.Enabled = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("Connection Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MySerial.Close();
                    buttonConnect.Text        = "Connect";
                    comboPorts.Enabled        = true;
                    comboBaud.Enabled         = true;
                    comboBits.Enabled         = true;
                    comboParity.Enabled       = true;
                    comboStopBit.Enabled      = true;
                    comboBoxHandShake.Enabled = true;

                    groupBoxIO.Enabled = false;
                }
            }
            else
            {
                MySerial.Close();
                buttonConnect.Text        = "Connect";
                comboPorts.Enabled        = true;
                comboBaud.Enabled         = true;
                comboBits.Enabled         = true;
                comboParity.Enabled       = true;
                comboStopBit.Enabled      = true;
                comboBoxHandShake.Enabled = true;

                groupBoxIO.Enabled = false;
            }
        }
Ejemplo n.º 9
0
    public static void Main()
    {
        MySerial sp = new MySerial(115200);

        sp.Open();
        JtagUartIfaceV1  iface = new JtagUartIfaceV1(sp, true);
        JtagDevicePoller jp    = new JtagDevicePoller(iface);

        Console.WriteLine("device number: {0}", jp.CountDevices(true));

        sp.Close();
    }
Ejemplo n.º 10
0
        public UARTViewer()
        {
            InitializeComponent();
            FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MyUARTViewer_Closing);

            // Init MySerialPort and add event handler after a non-empty line-input
            MySerialPort = new MySerial();
            MySerialPort.GetLineEvent += LineReceivedHandler;
            //
            // Reference: https://docs.microsoft.com/zh-tw/dotnet/csharp/programming-guide/events/how-to-publish-events-that-conform-to-net-framework-guidelines
            //
        }
Ejemplo n.º 11
0
        //Метод сохранения файлов, в которых были изменения или они были новыми
        public void SaveFile()
        {
            if (filename == "")
            {
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;

                DialogResult result;

                result = MessageBox.Show("Вы хотите сохранить файл?", "Подтвердить действие", buttons, MessageBoxIcon.Question);

                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                    saveFileDialog1.Filter           = " XML Files(*.xml)| *.xml";
                    saveFileDialog1.InitialDirectory = Environment.CurrentDirectory + "\\" + "Cars";

                    if (saveFileDialog1.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                    // получаем выбранный файл
                    filename = saveFileDialog1.FileName;
                    // сохраняем текст в файл

                    MySerial <List <CarClass> > .Serialize(filename, list);

                    MessageBox.Show("Файл сохранен", "Подтвердить", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                return;
            }


            if (change == true)
            {
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;

                DialogResult result;

                result = MessageBox.Show("Вы хотите сохранить изменения?", "Подтвердить действие", buttons, MessageBoxIcon.Question);

                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    File.Delete(filename);
                    MySerial <List <CarClass> > .Serialize(filename, list);

                    MessageBox.Show("Файл сохранен", "Подтвердить", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Ejemplo n.º 12
0
        //Нажатие на кнопку "Загрузить файл"
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = Environment.CurrentDirectory + "\\" + "Cars";
            openFileDialog1.Filter           = "xml files (*.xml)|*.xml";

            if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            // получаем выбранный файл

            Form1.filename = openFileDialog1.FileName;
            Form1.list     = MySerial <List <CarClass> > .Deserialize(Form1.filename);

            Close();
        }
Ejemplo n.º 13
0
        private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (FlagCheck) // Если были изменения в файле
            {
                DialogResult result = MessageBox.Show(
                    "Вы хотите сохранить изменения в текущем файле?",
                    "Подтвердить действие",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);

                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    SaveMetodFile();
                }
            }
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = Environment.CurrentDirectory + "\\" + "Team";
            openFileDialog1.Filter           = "xml files (*.xml)|*.xml";

            if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            // получаем выбранный файл
            filename = openFileDialog1.FileName;
            List     = MySerial <List <WorldCup2018> > .Deserialize(filename);

            FlagCheck = false;
            this.Text = NameForm + filename.Substring(filename.LastIndexOf("\\") + 1);
            worldCup2018BindingSource.DataSource = List;
            if (List.Count() == 0)
            {
                button2.Enabled = false;
                button3.Enabled = false;
            }
            else
            {
                button2.Enabled = true;
                button3.Enabled = true;
            }
        }
Ejemplo n.º 14
0
        private void Serial_UpdatePortName()
        {
            lstSerialComPort.Items.Clear();

            foreach (string comport_s in MySerial.FindAllSerialPort())
            {
                lstSerialComPort.Items.Add(comport_s);
            }

            if (lstSerialComPort.Items.Count > 0)
            {
                lstSerialComPort.SelectedIndex = 0;     // this can be modified to preferred default
                EnableConnectButton();
                UpdateToConnectButton();
            }
            else
            {
                DisableConnectButton();
                UpdateToConnectButton();
            }
        }
        private void buttonExit_Click(object sender, EventArgs e)
        {
            DialogResult result;

            result = MessageBox.Show("Are you sure you want to exit ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                if (MySerial.IsOpen)
                {
                    MySerial.Close();
                }

                try
                {
                    Environment.Exit(1);
                }
                catch (Exception)
                {
                }
            }
        }
        private void SerialPort_ReceivedEvent(object sender, SerialDataReceivedEventArgs e)
        {
            string data = MySerial.ReadLine();

            listBox1.Items.Add(data);
        }
Ejemplo n.º 17
0
 // use this if you only have brate. user will be polled for portname
 public MySerial(int baudRate) : base(MySerial.MakeUserSelectPort(), baudRate)
 {
 }
Ejemplo n.º 18
0
 public JtagUartIfaceV1(MySerial sp, bool verbose = false)
 {
     _verbose = verbose;
     _sp      = sp;
     _sp.Write(0x55);
 }
Ejemplo n.º 19
0
 protected void DecreaseTemp(object sender, EventArgs e)
 {
     serial = new MySerial(3);
     serial.Send(TEMPERATURE_DECREASE);
     RefreshData();
 }