Click here to Skip to main content
15,919,245 members
Home / Discussions / C#
   

C#

 
QuestionMouse move (hover) over an Image with Graphics drawings Pin
eyalbi00714-Nov-11 2:12
eyalbi00714-Nov-11 2:12 
AnswerRe: Mouse move (hover) over an Image with Graphics drawings Pin
Luc Pattyn14-Nov-11 2:43
sitebuilderLuc Pattyn14-Nov-11 2:43 
QuestionClass for Serail Port Comms Pin
KeithF14-Nov-11 1:24
KeithF14-Nov-11 1:24 
AnswerRe: Class for Serail Port Comms Pin
Luc Pattyn14-Nov-11 1:48
sitebuilderLuc Pattyn14-Nov-11 1:48 
GeneralRe: Class for Serail Port Comms Pin
KeithF14-Nov-11 4:24
KeithF14-Nov-11 4:24 
AnswerRe: Class for Serail Port Comms Pin
Luc Pattyn14-Nov-11 5:06
sitebuilderLuc Pattyn14-Nov-11 5:06 
GeneralRe: Class for Serail Port Comms Pin
KeithF16-Nov-11 4:06
KeithF16-Nov-11 4:06 
AnswerRe: Class for Serail Port Comms Pin
Luc Pattyn16-Nov-11 16:02
sitebuilderLuc Pattyn16-Nov-11 16:02 
Hi Keith,

KeithF wrote:
Am I on the right tracks here?


yes, well, maybe. I did not study your code in much detail, I do see a state-machine-like approach, which could be fine; however I have issues in several aspects:

1. I'm not sure I know enough about your "protocol" to judge the approach. As I said, what you need as an implementation heavily depends on your protocol.
e.g. what should happen when an unexpected response is received (say you send an ENQ and then receive an ETX where it "should" have been an ACK)
2. I didn't see your actual transmit and receive operations; is your receiver operating asynchronously (i.e. using a completion event)? or blocking (i.e. just read-and-wait-till-done)?
3. You seem to somewhat merge, then split, inbound and outbound messages; not sure why.
4. Whatever the goals and needs, I'm pretty sure my code would look quite differently, but that is a matter of style. In particular I'm not fond of methods that need data, don't get it as a parameter, and then go fetch it somehow (as your SendMsg-MessageToSend pair is doing).

Here is what I might consider doing if your protocol is somewhat close to what I think you intend:
- I would opt for (pseudo)synchronous transmit and asynchronous receive;
- so I would transmit using SP.Write() and act as if the data is gone instantly (if necessary just include a sleep period that corresponds to the normal transmission time, probably not necessary at all);
- and I would not read except inside the DataReceived handler.
- that would halve the number of states I need, as each state typically would be an "awaiting" state, say "waiting for ACK0";
      DataReceived should check the next inbound message;
      if it is an ACK0, send a new message (synchronously!), adapt the state (say "waiting for "ACK1"), and return;
      if it isn't, send a new message ("aborting"), set state="IDLE" (=waiting for anything), and return;
- so that boils down to a big switch inside DataReceived, switching to the current state (what am I expecting?), then looking at what actually was received, react (probably by sending something) and adapt the state, so the next DataReceived switch will go to another case.

That would work for simple cases; it would not cope well with slow transmission conditions: if you want overlaps (comparable to overlapped file I/O in Windows) or if your state actions are too large to handle in DataReceived itself, you may need a more complex scheme, maybe an input queue, etc.

Hope this helps. But once again, as I said, it all depends on what you need. It would not make sense to create a 1000 LOC class for a thermometer that sends one or two strings per second.

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

QuestionIterate all child forms and saving all reports to one excel. Pin
pinifg14-Nov-11 1:18
pinifg14-Nov-11 1:18 
AnswerRe: Iterate all child forms and saving all reports to one excel. Pin
Blue_Boy14-Nov-11 1:26
Blue_Boy14-Nov-11 1:26 
GeneralRe: Iterate all child forms and saving all reports to one excel. Pin
pinifg14-Nov-11 2:45
pinifg14-Nov-11 2:45 
AnswerRe: Iterate all child forms and saving all reports to one excel. Pin
DaveyM6914-Nov-11 1:45
professionalDaveyM6914-Nov-11 1:45 
QuestionConvert To English To Gujarati Pin
ramesh dabhi13-Nov-11 22:38
ramesh dabhi13-Nov-11 22:38 
AnswerRe: Convert To English To Gujarati Pin
Keith Barrow13-Nov-11 23:20
professionalKeith Barrow13-Nov-11 23:20 
AnswerRe: Convert To English To Gujarati Pin
Abhinav S14-Nov-11 1:42
Abhinav S14-Nov-11 1:42 
AnswerRe: Convert To English To Gujarati Pin
thatraja14-Nov-11 1:57
professionalthatraja14-Nov-11 1:57 
QuestionMultiple lines : datagridview Pin
abbd13-Nov-11 11:24
abbd13-Nov-11 11:24 
AnswerRe: Multiple lines : datagridview Pin
Richard MacCutchan13-Nov-11 22:42
mveRichard MacCutchan13-Nov-11 22:42 
AnswerRe: Multiple lines : datagridview Pin
thatraja14-Nov-11 2:05
professionalthatraja14-Nov-11 2:05 
QuestionCheckers Board game error Pin
xnaLearner13-Nov-11 11:03
xnaLearner13-Nov-11 11:03 
AnswerRe: Checkers Board game error PinPopular
Pete O'Hanlon13-Nov-11 11:27
mvePete O'Hanlon13-Nov-11 11:27 
QuestionMessage Removed Pin
13-Nov-11 9:24
AghaKhan13-Nov-11 9:24 
AnswerRe: What this mean ??. This code works fine Pin
Luc Pattyn13-Nov-11 9:33
sitebuilderLuc Pattyn13-Nov-11 9:33 
GeneralRe: What this mean ??. This code works fine Pin
AghaKhan13-Nov-11 16:00
AghaKhan13-Nov-11 16:00 
AnswerRe: What this mean ??. This code works fine. [Edited to show message which OP deleted] Pin
Pete O'Hanlon13-Nov-11 9:44
mvePete O'Hanlon13-Nov-11 9:44 

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.