Click here to Skip to main content
14,421,713 members
   

C#

 
GeneralRe: Collecting my replies Pin
Brian_TheLion17-May-19 18:59
MemberBrian_TheLion17-May-19 18:59 
QuestionI can't draw a graph from serialport Data using zedgraph Pin
IlYes Del_SaVior16-May-19 0:04
MemberIlYes Del_SaVior16-May-19 0:04 
AnswerRe: I can't draw a graph from serialport Data using zedgraph Pin
Richard MacCutchan16-May-19 0:33
communityengineerRichard MacCutchan16-May-19 0:33 
GeneralRe: I can't draw a graph from serialport Data using zedgraph Pin
IlYes Del_SaVior16-May-19 0:35
MemberIlYes Del_SaVior16-May-19 0:35 
AnswerRe: I can't draw a graph from serialport Data using zedgraph Pin
OriginalGriff16-May-19 2:18
communityengineerOriginalGriff16-May-19 2:18 
GeneralRe: I can't draw a graph from serialport Data using zedgraph Pin
Richard MacCutchan16-May-19 2:19
communityengineerRichard MacCutchan16-May-19 2:19 
AnswerRe: I can't draw a graph from serialport Data using zedgraph Pin
Gerry Schmitz16-May-19 5:04
mveGerry Schmitz16-May-19 5:04 
AnswerRe: I can't draw a graph from serialport Data using zedgraph Pin
Luc Pattyn16-May-19 5:25
sitebuilderLuc Pattyn16-May-19 5:25 
Hi,

I see several problems:

1.
as other have said already, you should divide and conquer; do not write all the code and then come to the conclusion it doesn't work. Instead chop the task into many smaller tasks and solve them one by one.

2.
NEVER use an empty catch; when an exception occurs, it does so because something is wrong; catching the exception and looking at it will tell you more. It is there to help you. You could display the Exception.Message with a MessageBox. It is better to display the entire Exception.ToString() result as that includes exact line numbers. And I prefer to log all exceptions to a text file, which doesn't disturb the timing aspects as much as interactive debugging. See A simple logging scheme[^]

3.
The DataReceived event will run code on another thread (proof: Asynchronous operations run on ThreadPool threads[^]) , and I trust ZedGraph (as any other WinForms Control) does not work well (or at all) on any thread that did not create it, normally called the GUI thread. So you will be getting cross-thread exceptions. Read more about it here: Invalid cross-thread operations[^]

4.
The DataReceived event fires when one of a few bytes got received, it does not care about lines of text, or whatever constitutes a "message". And (nowhere documented) as long as one DatReceived handler is running, no more such events will happen. Now what happens when you receive a few bytes not including a NewLine? The event may fire, get to your SerialPort.ReadLine() and wait there forever.

The solution here depends very much on the specifics of your peripheral. If data throughput is low and some delay is acceptable, a work-around might be to put some delay (say Thread.Sleep(100)) just before the call to ReadLine(). And yes, that is an ugly hack, but it sometimes suffices.


You should take care of all of the above and then you may be successful!

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

GeneralRe: I can't draw a graph from serialport Data using zedgraph Pin
Jeff_T_123416-May-19 17:42
MemberJeff_T_123416-May-19 17:42 
GeneralRe: I can't draw a graph from serialport Data using zedgraph Pin
Luc Pattyn16-May-19 17:45
sitebuilderLuc Pattyn16-May-19 17:45 
GeneralRe: I can't draw a graph from serialport Data using zedgraph Pin
Jeff_T_123416-May-19 17:47
MemberJeff_T_123416-May-19 17:47 
GeneralRe: I can't draw a graph from serialport Data using zedgraph Pin
Luc Pattyn16-May-19 17:49
sitebuilderLuc Pattyn16-May-19 17:49 
AnswerRe: I can't draw a graph from serialport Data using zedgraph Pin
Jeff_T_123416-May-19 17:57
MemberJeff_T_123416-May-19 17:57 
QuestionWhy is this necessary? Pin
Brian_TheLion15-May-19 20:48
MemberBrian_TheLion15-May-19 20:48 
AnswerRe: Why is this necessary? Pin
OriginalGriff15-May-19 21:05
communityengineerOriginalGriff15-May-19 21:05 
GeneralRe: Why is this necessary? Pin
Brian_TheLion16-May-19 14:50
MemberBrian_TheLion16-May-19 14:50 
GeneralRe: Why is this necessary? Pin
OriginalGriff16-May-19 21:14
communityengineerOriginalGriff16-May-19 21:14 
GeneralRe: Why is this necessary? Pin
Brian_TheLion17-May-19 16:35
MemberBrian_TheLion17-May-19 16:35 
GeneralRe: Why is this necessary? Pin
OriginalGriff17-May-19 21:09
communityengineerOriginalGriff17-May-19 21:09 
AnswerRe: Why is this necessary? Pin
OriginalGriff15-May-19 22:32
communityengineerOriginalGriff15-May-19 22:32 
GeneralRe: Why is this necessary? Pin
Brian_TheLion16-May-19 16:02
MemberBrian_TheLion16-May-19 16:02 
GeneralRe: Why is this necessary? Pin
BillWoodruff17-May-19 16:18
mveBillWoodruff17-May-19 16:18 
GeneralRe: Why is this necessary? Pin
OriginalGriff17-May-19 20:59
communityengineerOriginalGriff17-May-19 20:59 
GeneralRe: Why is this necessary? Pin
jschell18-May-19 7:52
Memberjschell18-May-19 7:52 
AnswerRe: Why is this necessary? Pin
Richard Deeming16-May-19 2:47
communityengineerRichard Deeming16-May-19 2:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.