But is there a way to code it to be 100% sure which command did or didn't get an answer?
Main Topics
Browse All TopicsHi experts!
I have a very simple c# code for sending and receiving serial commands and it works fine. If i send a command and the command is recognized, then I will receive a respond from the serial device. When the command is not recocnized i don't get any responce at all. My problem is that i want to be noticed when something is sent and nothing is returned in the DataReceived event to make a log showing which commands my serial devide doesn't respond to. How can I do that?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Only if you perform the task of sending and receiving within the same thread and use the timeout as specified by the manufacturer of the hardware-device.
Use the serialport.ReadTimeout-pro
It might prove useful to do the sending and receiving in a seperate function (improves readability and reduces code).
Business Accounts
Answer for Membership
by: djjariesPosted on 2009-09-15 at 03:51:28ID: 25333530
The way you coded it now, you will never be 100% sure which command did or did not got an answer. It could be possible that the reception of the answer is delayed, causing you to think that the command did not receive an answer.
Assuming the communication works very good without delays, you can set a boolean to true when you send something and revert it to false when you receive information. That way, if the boolean is still true when you send the next item, you have not received anything. Alternativly, if you receive information when the boolean is false, you are out of sync with your send/receive-routine since you receive something while you did not send anything.
Use lock to lock the boolean when you want to update it from different threads to avoid problems.