fawadbutt
Member level 3
- Joined
- Oct 29, 2010
- Messages
- 61
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 1,288
- Location
- Lahore, Pakistan, Pakistan
- Activity points
- 1,754
hi i need help in serial data receiving . i using vs2013 and code write in c#. i call serial data received event handler but its not in working this is my code:
my data port open and sending code is working fine.
plz i need help.
Code:
public partial class Form1 : Form
{
string rxdata;
public Form1()
{
InitializeComponent();
///////////////////////Serial port Setting//////////////////////////////////
SerialPort SerialPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
SerialPort1.Handshake = Handshake.None;
SerialPort1.ReadTimeout = 500;
SerialPort1.WriteTimeout = 500;
///////////////////////////-Receiving event handler-/////////////////////////////
SerialPort1.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);
//////////////////////////////////////////////////////////////////////////////
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (SerialPort1.IsOpen)
{
SerialPort1.Close();
}
}
private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
MessageBox.Show("Data Received");
SerialPort1 = (SerialPort)sender;
rxdata = SerialPort1.ReadExisting();
this.Invoke(new EventHandler(displaytext));
}
private void displaytext(object sender, EventArgs e)
{
// textBox1.AppendText(rxdata);
richTextBox1.AppendText(rxdata);
}
my data port open and sending code is working fine.
plz i need help.