public partial class Form1 : Form { public Form1() { InitializeComponent(); } SerialPort port = new SerialPort(); private void Form1_Load(object sender, EventArgs e) { try { #region Display all available COM Ports string[] ports = SerialPort.GetPortNames(); // Add all port names to the combo box: foreach (string port in ports) { //this.cboPortName.Items.Add(port); this.cbbCOMPorts.Items.Add(port); } #endregion this.btnDisconnect.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnConnect_Click_1(object sender, EventArgs e) { if (port.IsOpen) { port.Close(); } try { { port.PortName = cbbCOMPorts.Text; port.BaudRate = 96000; port.Parity = Parity.None; port.DataBits = 8; port.StopBits = StopBits.One; } //.Encoding = System.Text.Encoding.Unicode port.Open(); lblMessage.Text = cbbCOMPorts.Text + " Connected. "; btnConnect.Enabled = false; btnDisconnect.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } txtDataToSend.Focus(); } private void btnDisconnect_Click_1(object sender, EventArgs e) { try { port.Close(); lblMessage.Text = port.PortName + " disconnected."; btnConnect.Enabled = true; btnDisconnect.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnSend_Click(object sender, EventArgs e) { try { port.Write(txtDataToSend.Text); //txtDataReceived->IS a data Received Text Box name //txtDataToSend->is a data send Text Box name txtDataReceived.AppendText (txtDataToSend.Text ); // <<---- error here txtDataReceived.Text = txtDataReceived.Text + txtDataToSend.Text;//<--- i Tried but it not error but data cannot be appendtext in text box(txtDataReceived) txtDataReceived.ScrollToCaret(); } txtDataToSend.Text = string.Empty; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง