コード例 #1
0
        // Verbindung mit COM Device aufbauen Baud Rate 4800 Datenbits 8
        public void Connect(string port, TextBox logbox, PICProgramm prog, Form1 f)
        {
            ComPort = new SerialPort();

            ComPort.PortName = port;
            ComPort.BaudRate = 4800;
            ComPort.DataBits = 8;
            ComPort.Parity   = Parity.None;
            ComPort.StopBits = StopBits.One;

            try
            {
                ComPort.Open();
            }
            catch (Exception ex)
            {
                logbox.Text += ex + "\r\n";
                ComPort      = null;
                return;
            }

            if (ComPort.IsOpen)
            {
                logbox.Text += "Connected to " + port + "\r\n";
                Programm     = prog;
                TextBox      = logbox;
                Fenster      = f;
                return;
            }

            ComPort = null;
        }
コード例 #2
0
        // Empfangen des Datenstrings und in Log anzeigen
        private void RecieveData()
        {
            string x = ReadDataSegment();

            if (x != string.Empty)
            {
                if (x == null)
                {
                    TextBox.Text += ("< [ERR-R] NULL") + "\r\n";
                }
                else if (x.Length == 4)
                {
                    TextBox.Text += ("< " + x) + "\r\n";

                    var v = decodeBytes(x);

                    if (v == null)
                    {
                        TextBox.Text += ("< [ERR-D] " + x) + "\r\n";
                    }
                    else
                    {
                        for (uint i = 0; i < 8; i++)
                        {
                            // Nur 'i' bits übernehmen

                            if (Programm.GetRegisterOhneBank(PICProgramm.ADDR_TRIS_A, i))
                            {
                                Programm.Register[PICProgramm.ADDR_PORT_A] = PICProgramm.SetBit(Programm.Register[PICProgramm.ADDR_PORT_A], i, !PICProgramm.GetBit((byte)v.Item1, i));
                            }
                            if (Programm.GetRegisterOhneBank(PICProgramm.ADDR_TRIS_B, i))
                            {
                                Programm.Register[PICProgramm.ADDR_PORT_B] = PICProgramm.SetBit(Programm.Register[PICProgramm.ADDR_PORT_B], i, !PICProgramm.GetBit((byte)v.Item1, i));
                            }
                        }

                        Fenster.OberflaecheAktualisieren();
                    }
                }
                else
                {
                    TextBox.Text += ("< [ERR-L] " + x) + "\r\n";
                }

                x = ReadDataSegment();
            }
        }