473,395 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SerialPort CDHolding, Works only during Debug

7
Delving into SCPI commands and DTR/DSR communications. I have worked my problem down to some nuance. I am using C# Express 08 on Win XPSP2. My code does this:

{
create, set, and open serialport; // nothing fancy

SP.WriteLine("APPL?");
SP.DtrEnable = true;
somestring = SP.ReadExisting();
}

EDIT: there are supposed to be ~19 bytes sent back from the APPL? command.

Now this works when I put a debug break on the Write but not when the break is on DtrEnable or just letting it run. The only parameter that changes with the break point placement is SP.CDHolding. This turns and stays 0 with the break at the write but is 1 when break is at DTR.

I tried both types of handshaking and spent an hour learning how to enumerate and the differences in handshaking. I also tried putting Thread.Sleep(1000) before and after everything.

Any holes to chase or new approaches would be helpful.
Feb 4 '09 #1
2 3789
vekipeki
229 Expert 100+
You should implement some sort of a state-machine when doing this type of communication.

The problem is that you cannot know if your data will already be sent in the moment when you manually enable DTR. After that, you immediately start reading, without knowing if your previous data has been sent, and without allowing your other device to reply.

You can either handle the SerialPort.DataReceived event and have a FIFO input buffer which you can then parse to change states in your program, or have a separate thread which polls the SerialPort with some thread sleeping between reads, which also fills the input buffer for later processing.
Feb 4 '09 #2
Sam T
7
@vekipeki
Why would putting a manual sleep into the code not fix this problem? Even in debugging I am breaking before manually setting the DTR, ensuring the output buffer is empty, and the device does not send me anything after setting DTR high. 0.5 seconds will not kill me and will gladly pay that price to avoid a full on state machine (had to wiki this morning). Something is futzing with my serial port and in the debugging environment it does not happen.

I will start moving toward a FSM but do not like spaghetti. Thanks for the reply vekipeki!
Feb 4 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: William Sullivan | last post by:
I was wondering... Are there attributes you can use to mark accessors/variables that will identify them as to be shown when hovering over an instance of the containing object during debugging? As...
3
by: mudman | last post by:
I'm running Visual Studio.NET and am experiencing a problem during debugging (i assume this will also be the case during normal operation). If the variable "test" is a double and "denom" a finite...
6
by: Mike | last post by:
Hi, I have variable strText, with value "Hello World" I see this value at Watch window. Can I change this value to "World Hello" and continue work or I need to stop program , assign new value...
1
by: Bob Day | last post by:
Consider the two code snippets below. a) During development, if you hold your cursor over AKA.SomeDateTime in Snippet 2, it will indicate a value of #1/1/1950# as expected. b) If you...
1
by: Ryan | last post by:
Is there any way to view what data is populating my DataSet tables during debugging? Thanks, Ryan
3
by: JIM.H. | last post by:
private void DownloadPDF(string fPath) { Response.Clear(); Response.ContentType = "Application/pdf"; Response.WriteFile(fPath); Response.End(); } private void Show(string file)
1
by: keithb | last post by:
Using the VS built-in web server, class properties and datatables seem to be getting cached between my debug sessions. How can I disable all caching? Thanks, Keith
4
by: PiotrKolodziej | last post by:
Hi Iam trying to send AT commands to the device. if (serialPort1.IsOpen) serialPort1.Close(); serialPort1.Open(); byte buffer = ASCIIEncoding.ASCII.GetBytes("AT");
12
by: Praveen Raj V | last post by:
I am Receiving 3144 bytes through TCP/IP socket During debug mode, but during excecution 1024 byte were received Why it is happen IPEndPoint ipEnd = new IPEndPoint(ipAdd, ipPort); Socket socket...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.