|
Bugger! I was all set to show you what I've done to deal with a variety of serial devices of varied and unpredictable timing, and found that System.IO.Port won't do it.
My (much older) code dealt with the lower level beast you could access with things like SetupComm() Get/SetCommState() SetCommTimeouts() etc after getting a handle from CreateFile() . The trick was to set ReadIntervalTimeout to infinite (MAXDWORD) and ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier both to zero.
This had the effect of turning all read calls into non-blocking "give me what you've got in the buffer" calls.
I handled real "device gone AWOL" timeouts at the application level, typically on lack of progress of a message exchange.
As I (and Toyota) said, bugger!
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
That's true. I've written native code that works properly, but this SerialPort class seems to have a bug.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I also have old MFC code setting up the port with the exact same options you mention (as well as buffers and other good stuff), so thank you for the heads up
Currently I don't actually have anything that needs this kind of COM port control in C# code, but I hope there is a workaround to this and I will be watching this thread for pointers.
Soren Madsen
|
|
|
|
|
Umm probably preaching to the choir (i.e. you know this but...) ReadLine() is a blocking method ReadExisting() is not if you use some thing like the below code:
Pause.Elapsed += new System.Timers.ElapsedEventHandler(OnTimeOutPause);
NoDataAtPort = new System.Timers.Timer(25000);
NoDataAtPort.Elapsed += new ElapsedEventHandler(OnTimeOut);
myComPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived);
}
private void OnTimeOut(object sender, ElapsedEventArgs e)
{
Reply_Status = (int)REPLY.TIMEOUT_REPLY;
}
private void OnTimeOutPause(object sender, ElapsedEventArgs e)
{
MessageBox.Show("Something Broke!");
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Reply_Status = (int)REPLY.YES_REPLY;
InputData = myComPort.ReadExisting();
if (InputData != String.Empty)
{
this.BeginInvoke(new SetTextCallback(SetText), new object[] { InputData });
}
}
private void SetText(string text)
{
this.rtbIncomingData.Text += text;
if (this.rtbIncomingData.Lines.Length > 0)
{
lbIncomingData.Items.AddRange(rtbIncomingData.Lines);
}
if (text.StartsWith("S") && text.EndsWith(">"))
{
text = text.Substring(3, (text.Length - 6));
txtSerialNumber.Text = text;
rtbIncomingData.Text = "";
}
myComPort.DiscardInBuffer();
}
using the Reply_Status as pre-defined Enum list:
enum REPLY : int { NO_REPLY, TIMEOUT_REPLY, YES_REPLY }
is either a work around or the correct way of doing it, as I had a board that was spewing data, waiting, vomiting again at odd times (it was an RF board) much confusion
also try using a listBox as this tends to cope with odd amounts of data better.
(Jan Axelsons Serial Port Complete 2nd Edition is quite a good reference ISBN 978-1-931448-06-2)
Glenn
modified 16-Jul-12 5:13am.
|
|
|
|
|
I have a question, starting the debugger somehow indirectly, in this szenario:
1)
I start a dot-net-executable within a batch-file
2)
When this exe is started from the batch, I want, that the debugger is started "automatically", so that I have the chance to trace the running exe (e.g. by breakpoints)
Question:
How can I start the debugger this way?
Thank you
|
|
|
|
|
Maybe wait for it to throw an unhandled Exception?
But seriously, you can't do it that way. If you're using Visual Studio to develop the app you can attach the debugger to a running app by opening the solution and using the menu: Debug | Attach to process... then select the process from the list.
What I have done with Windows Services is have them pause for a minute when they start so I have time to attach the debugger; you may need to do something like that.
|
|
|
|
|
|
You can launch the JIT debugger from the batch file (with the %WINDIR%\System32\vsjitdebugger.exe util), after you've successfully started your app.
For instructions on how to do it refer to this link: Answer 3[^]
2A
|
|
|
|
|
I use the following for debugging on my dev machine
System.Diagnostics.Debugger.Assert(false);
When it executes it pops a dialog that asks for the debugger to run via the 'retry' option on the first popup.
Once the debugger starts there is a break point on the above line.
There are limitations to this such as where the app is running and timeout issues with execution threads (with the debug line).
|
|
|
|
|
Hello, I need to add element host to one column of my datagridview and attach a user control to each element host. Is there anyway to implement this? Datagridview is in windows form and I designed a user control in WPF with Avalon library.
Thanks,
Amir
|
|
|
|
|
Hello,
Is there a way to draw a rectangle on top of all windows form application that we can see threw it the other form controls? (like thick box in asp.net).
or if there is a transparent control that we can see thew it a control behind him...
Thank you very much
|
|
|
|
|
|
Could be helpful if you share what the use and purpose of this transparent overlay is.
best, Bill
The glyphs you are reading now: are place-holders signifying the total absence of a signature.
|
|
|
|
|
i have a pdf in my form and i want to cover him with a transparent control to deny the user to interact with him because i want to deny him to print and save the pdf.
i tried multiple libraries to set this security but the failed with the new adobe reader that comes with a little toolbar right a the bottom of each page (on mouse over) so the user can save and print the pdf.
|
|
|
|
|
Um.
You do realize that any protection you introduce like that can be got round in about half a dozen mouse clicks? For example, Chrome provides both "Inspect element" and "View source" which would either get the complete text or the url which links to the PDF. With that, it would be a simple matter to download it in the normal way...
What are you trying to do that you think an "untouchable" PDF file is a good solution?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
That's handled by the security settings in the PDF document. What you're doing is just a hairbrained scheme that is easily defeated by about half a dozen ways that I can think of in about 5 seconds.
|
|
|
|
|
first,the security in the PDF document didn't work (using 4 different libraries) with this little toolbar at the bottom,second how you can defeat this in 5 second? i deny you to reach the PDF to save it,it's not a web application that you can use developer tool or firebug or .. to reach the PDF,it's windows form application
|
|
|
|
|
jokercocol wrote: first,the security in the PDF document didn't work (using 4 different libraries)
How about Acrobat?? Works perfectly. 3rd party libraries usually don't have great support for the security features, if at all.
jokercocol wrote: i deny you to reach the PDF to save it,it's not a web application that you can
use developer tool or firebug or .. to reach the PDF,it's windows form
application
Hehe. Actually, I CAN defeat it. Since it's Windows Forms and not a web page, it'll take a bit longer, but still very much under a minute. Yes, I already have the tool written to do it.
|
|
|
|
|
Hi everyone
We use of "Add New Data Source" (in the visual studio) and then select a dataset for connect a database in the C#, Is it possible to make a new database in the "Add Connection" window instead "Select or enter a database name"?
Thanks
|
|
|
|
|
|
I have searched on the internet and it looks like nobody tests it and its first time,could you test it ,please(it doesnt get many times)?I enter the new name in the "Select or enter a database name" field and it asks of me:"The database "mydatabse" does not exist or you do not have permission to see it.Would you like to attempt to create it? when you click ok it makes it!
|
|
|
|
|
Congratulations! You tried it and found that you could. You answered your own question. What exactly does this have to do with C#?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Because I'm going to do it on the C# and I want to know Im on the correct way or no,Wes Aday(are you Gondolf? )
|
|
|
|
|
messages wrote: correct way or no
No this is not the correct way. Your question has absolutely nothing to do with C#. And most likely you are not going to be creating databases in C#.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
messages wrote: the correct way or no
No. The better way is to use a database creation script. If it is really needed to be done, then the C# application would run the database creation script and create the database for you through SQL Server. Most of the time, a database should already exist and have been created before you even write any application code.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|