Hi,
I am having problems with a device bulit by a colleague that needs to be working for Tuesday. If you talk to this device in HyperTerminal it errors all the time as it get the data from the UART too quickly it , he has found a thing call Advanced Serial Port Monitor which lets the user type a complete string before sending it. My code replicates this but I am having trouble seeing the replies
coming back while Advanced Serial Port Monitor says this is being sent I am not picking them up. My first though was a timer how ever this does not appear to work, I think now I have found a way around it using Events rather than the timers is this even possible???
private void port_DataReceivedATE(object sender, SerialDataReceivedEventArgs e)
{
byte[] dataATE = new byte[myComPort.BytesToRead];
myComPort.Read(dataATE, 0, dataATE.Length);
if ((dataATE.Length > 1) && (dataATE[dataATE.Length - 1] == 13))
{
Array.Resize(ref dataATE, dataATE.Length);
}
bufferATE.AddRange(dataATE);
ProcessBufferATE();
}
private void ProcessBufferATE()
{
byte[] byteATE = new byte[buffer.Count];
buffer.CopyTo(0, byteATE, 0, buffer.Count);
buffer.RemoveRange(0, buffer.Count);
string dataATE;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
dataATE = enc.GetString(byteATE);
this.BeginInvoke(new MethodInvoker(delegate() { rtbIncoming.Text += dataATE; }));
}
private void myComPort_DateRecived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
}
This does even less than it did before. I'm guessing I need some code in the myComPort_DateRecived() the unit I am talking to has all commands framed by #, ie #L# or #W512#. what I'm thinking is "
if(myComPort.BytesToRead > 0)
{
dataInATE = myComPort.Read() //not really sure which Read func to use????
if(dataInATE = (char)35)
{
StartOfByte = true;
}
if(StartOFByte == true)
{
while(dataInATE != (char)35)
{
dataInATE += dataInATE;
}
}
}
//copy data out of dataInATE to a rich text box
dataInATE =rtbIncoming.Text;
Umm will this get around the problem I'm having or is it going to get worse!
Glenn