Click here to Skip to main content
15,896,479 members
Home / Discussions / C#
   

C#

 
Questionflickers with draw plots from serial port ? Pin
Honeyboy_206-Jun-10 16:40
Honeyboy_206-Jun-10 16:40 
AnswerRe: flickers with draw plots from serial port ? Pin
Luc Pattyn6-Jun-10 16:57
sitebuilderLuc Pattyn6-Jun-10 16:57 
GeneralRe: flickers with draw plots from serial port ? Pin
Honeyboy_206-Jun-10 17:09
Honeyboy_206-Jun-10 17:09 
GeneralRe: flickers with draw plots from serial port ? Pin
Luc Pattyn6-Jun-10 17:19
sitebuilderLuc Pattyn6-Jun-10 17:19 
GeneralRe: flickers with draw plots from serial port ? Pin
Honeyboy_208-Jun-10 5:24
Honeyboy_208-Jun-10 5:24 
GeneralRe: flickers with draw plots from serial port ? Pin
Ravi Bhavnani6-Jun-10 17:30
professionalRavi Bhavnani6-Jun-10 17:30 
GeneralRe: flickers with draw plots from serial port ? Pin
Honeyboy_207-Jun-10 5:19
Honeyboy_207-Jun-10 5:19 
GeneralRe: flickers with draw plots from serial port ? Pin
Luc Pattyn8-Jun-10 6:28
sitebuilderLuc Pattyn8-Jun-10 6:28 
Hi,

I've been trying to read some of that code, which you made very hard by not using PRE tags. PRE tags exist for preserving formatting, mainly indentation, which facilitates seeing the structure of it all. So whatever you do in future, use PRE tags. You could even still edit your existing message and put PRE tags around its code.

The code itself looks horrible too. Here are some comments, the list is not complete:

1.
using Exception.Message rather than Exception.ToString() is stupid, as the latter offers much more information, making debugging a lot easier.

2.
You have a DataReceived event handler (fine), but all it does is use Invoke to force a delegate to execute on the GUI thread, so it actually is your GUI thread that will read all bytes from the serial port and interpret them. That is not smart, as it has no relation with the GUI at all. You should deal with the serial data in a handler (or a separate thread) and only invoke towards the GUI thread at the very moment you want to update the GUI.

3.
you read all serial port data one byte at a time; why not use SerialPort.Read(byte[] buffer, int offset, int count) to read all available data at once, then process it?

4.
you have lots of unnecessary conversions, from bytes to strings to ints and back. As your data is binary (I assume so, since you are reading bytes right now), why not always deal with it as bytes; and possibly once turning it into a string for displaying it if necessary.

5.
Get rid of those silly Conversion.Hex calls; they reek like Basic. If at all necessary, simply use byte.ToString("X2")

6.
I skipped some code, then saw a Paint method, with lots of mistakes.
A. use the Graphics you get from PaintEventArgs, don't create your own
B. don't call Invalidate() or Refresh() in a Paint handler. It is terribly wrong.
C. Avoid calling methods such as Math.Cos in a paint handler; you should have done that calculation beforehand and store it in your objects.
D. Dispose of the garbage you create; e.g. the pen


Conclusion: it is an abominable mess; I don't want to have another look at it, it should be binned and started all over.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read formatted code with indentation, so please use PRE tags for code snippets.

I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).

GeneralRe: flickers with draw plots from serial port ? Pin
Honeyboy_2010-Jun-10 2:15
Honeyboy_2010-Jun-10 2:15 
GeneralRe: flickers with draw plots from serial port ? Pin
Luc Pattyn10-Jun-10 2:31
sitebuilderLuc Pattyn10-Jun-10 2:31 
GeneralRe: flickers with draw plots from serial port ? Pin
Ahmed R El Bohoty14-Jun-10 17:43
Ahmed R El Bohoty14-Jun-10 17:43 
QuestionC# programm merging pdf files Pin
nstk6-Jun-10 6:39
nstk6-Jun-10 6:39 
AnswerRe: C# programm merging pdf files Pin
Richard MacCutchan6-Jun-10 6:51
mveRichard MacCutchan6-Jun-10 6:51 
AnswerRe: C# programm merging pdf files Pin
dan!sh 6-Jun-10 7:18
professional dan!sh 6-Jun-10 7:18 
AnswerRe: C# programm merging pdf files Pin
Johnny J.6-Jun-10 23:37
professionalJohnny J.6-Jun-10 23:37 
QuestionGetting cookies from IE process. [modified] Pin
Evgeni575-Jun-10 20:19
Evgeni575-Jun-10 20:19 
QuestionGet object count Pin
ruknil5-Jun-10 9:39
ruknil5-Jun-10 9:39 
QuestionRendering a page break in WinForms RichTextBox Pin
The Man from U.N.C.L.E.5-Jun-10 9:06
The Man from U.N.C.L.E.5-Jun-10 9:06 
AnswerRe: Rendering a page break in WinForms RichTextBox Pin
Luc Pattyn5-Jun-10 10:24
sitebuilderLuc Pattyn5-Jun-10 10:24 
GeneralRe: Rendering a page break in WinForms RichTextBox Pin
The Man from U.N.C.L.E.5-Jun-10 11:10
The Man from U.N.C.L.E.5-Jun-10 11:10 
GeneralRe: Rendering a page break in WinForms RichTextBox Pin
Luc Pattyn5-Jun-10 11:36
sitebuilderLuc Pattyn5-Jun-10 11:36 
QuestionProblem with Listview,help! Pin
imbiz5-Jun-10 7:31
imbiz5-Jun-10 7:31 
AnswerRe: Problem with Listview,help! Pin
Henry Minute5-Jun-10 8:05
Henry Minute5-Jun-10 8:05 
AnswerRe: Problem with Listview,help! Pin
Luc Pattyn5-Jun-10 8:07
sitebuilderLuc Pattyn5-Jun-10 8:07 
GeneralRe: Problem with Listview,help! Pin
Henry Minute5-Jun-10 8:30
Henry Minute5-Jun-10 8:30 

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.