Hello everybody, I have a problem when recieve data to Com Port with RS232 communication . When I recieve data to Com port I must delay to conect to Database and process it . But I return to receive next the data , this data is lost data .Example my data transmit to PC is "1234567" . The first time , my data is recieved "1234567" .After , this data is processed and the second my data is recieved "234567" or "34567" .I don't understand? Can you help me,please .This is my code
using System.IO.Ports;
using System.Threading;
public partial class Form1 : DevComponents.DotNetBar.Office2007RibbonForm
{
SerialPort serialPort = new SerialPort();
public string data;
public Form1()
{
InitializeComponent();
serialPort.DataReceived+=new SerialDataReceivedEventHandler(serialPort_DataReceived);
}
void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
data = serialPort.ReadExisting();
//textBoxX5.Text = "";
Thread t = new Thread(new ThreadStart(this.RunThread));
t.Start();
}
public string datare;
void Settext(string str)
{
datare += str;
textBoxX9.Text = datare;
datare = "";
}
public delegate void delSettext(string str);
void RunThread()
{
delSettext func = new delSettext(this.Settext);
this.Invoke(func, new Object[1] { data });
}
Loading
Sam HobbsPosted Mar 1, 2011, 2:18 PM
Are you familiar with handshaking? Serial communication uses two or three types of handshaking. Hardware handshaking is one way and I think there are at least two types of software handshaking. I think that XON and XOFF characters is one type of handshaking. It is a way for the two computers to tell the other one to wait and let it catch up. So if your handshaking is not correct then the other computer or the device might be sending data that the computer is not ready to receive and does not receive.
Or maybe the computer tries to read the data too soon and the data is not there yet. That is probably not a handshaking problem but it would be a synchronization problem of some type.
The best solution is to spend time learning about serial communication.