Ports
May 21, 2013, 09:03:55 am
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: SMF - Just Installed!
Home
Help
Search
Login
Register
Welcome to the PORTS Forum. Please post your questions, answers, and comments relating to USB and other hardware interfaces in the appropriate forums below. - Jan
Ports
>
General Category
>
Serial Ports
>
Need a ReadExisting() example for C#....
Pages: [
1
]
« previous
next »
Print
Author
Topic: Need a ReadExisting() example for C#.... (Read 1597 times)
GlennP
Frequent Contributor
Posts: 126
Need a ReadExisting() example for C#....
«
on:
February 17, 2012, 06:32:40 am »
Hi All,
I am reading back for a board and I think the board is 'randomly' dropping '>' which is used as a prompt occasionally I think one of these is not sent with the data meaning that my
ReadExisting()
does not catch the data while it does appear in a monitor program I am running in the Event Handler.
Glenn
Logged
Jan Axelson
Administrator
Frequent Contributor
Posts: 1627
Re: Need a ReadExisting() example for C#....
«
Reply #1 on:
February 17, 2012, 10:01:15 am »
Is the problem that the sender is not sending ">" or is the problem that the receiver is not seeing every character sent?
Jan
Logged
GlennP
Frequent Contributor
Posts: 126
Re: Need a ReadExisting() example for C#....
«
Reply #2 on:
February 17, 2012, 10:58:49 am »
It looked like I was not waiting long enough. What I am doing was is using the data Serial Data Received Event Handler to check via ReadExisting() and then checking for a '>' with if (End = text.EndsWith(">")) it appears that the string every so often does not have '>' so the PC ignores it. Also I want the program to STOP dead and ideally put a Message Box up to high light this fact.
public int WaitForData(int Timeout)
{
// bool Respond = false;
//bool WaitforPrompt = false;
Stopwatch sw = Stopwatch.StartNew();
this.Invoke(new MethodInvoker(delegate()
{
ReplyData = rtbIncoming.Text;
}));
//if((ReplyData.Contains(">")||(ReplyData.Contains("OK"))))
// Respond = true;
//else
// Respond = false;
while (sw.ElapsedMilliseconds < Timeout && myComPort.BytesToRead > 0)// && Respond == false)// && rtbIncoming.Text.Contains(">") || rtbIncoming.Text.Contains("OK"))
{
lblwhere.Text += ".";
System.Threading.Thread.Sleep(1); // sleep for 1 millisecond
}
int elapsed = (int)sw.ElapsedMilliseconds;
sw.Stop();
return elapsed;
}
That is the timer I am using to try to govern the comms calling via
value = WaitForData(10);
value how ever does not have any thing returned to it.
Logged
Jan Axelson
Administrator
Frequent Contributor
Posts: 1627
Re: Need a ReadExisting() example for C#....
«
Reply #3 on:
February 17, 2012, 12:30:44 pm »
If the sender isn't sending ">", you need to find out why.
If the sender is sending ">" but you're not seeing it with ReadExisting, are you reading multiple times to be sure you get everything that's being sent? You may need to piece together the complete command from multiple reads.
Jan
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> USB
=> Serial Ports
=> Embedded Ethernet
=> Parallel Port
=> Other Interfaces
=> General Discussion
Loading...