|
|
|
อยากรู้ว่ารับค่าจากSerial Portให้แสดง"123456"แล้วจะแยกให้แสดงคนล่ะtextboxได้หรือป่าวครับ |
|
|
|
|
|
|
|
ตัวอย่างการเขียนผ่าน Serial Port
Code (C#)
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);
}
}
http://www.codeproject.com/Questions/55573/HOW-to-appendtext-text-in-Smart-Device-MOBILE-APPL?tab=mostrecent
|
|
|
|
|
Date :
2011-07-29 15:20:42 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุนมากมายเลยครับ
|
|
|
|
|
Date :
2011-08-01 22:50:47 |
By :
khem |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|