|
Hi,
the .NET Registry classes still don't cover it all, one occasionally needs the original Win32 API functions, and P/Invoke to get to them. However I never needed any REG_NONE, are you sure you do, and it is worth it?
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Look here[^].
I don't think that they have yet updated this
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I have a program that needs to do two-way communication with a serial port. Once I set up the serial port, I will do a WriteLine("something"), then the program must wait for a response, read the response, and then based on that response do another WriteLine, rinse and repeat. Ideally I want to be able to call some function match(SerialPort s, string matchText) that will block until I get a response from the SerialPort and then let me know if my text matches the response.
I've tried using ManualResetEvents and WaitOne(), but calling WaitOne() seems to block everything: the SerialPort.DataReceived event never triggers! Note that all the thread management is occurring in a static management class, but I don't believe this would cause the problem.
Any ideas? Perhaps I'm going about this the wrong way. It seems like the write->wait->read->decide->write... workflow should be a pretty common task with serial ports.
|
|
|
|
|
Hi,
there are at least two obvious ways to tackle this:
1.
fully event-driven: get things started from the main thread, then perform everything else inside some handler, in your case the SerialPort.DataReceived handler. So what it does is read the line that came in, interpret it, and react to it by performing another SerialPort.Write(), then return.
This is fine for simple cases, it may not suit when more complex interactions are required (e.g. imagine talking and listening to two peripherals, both connected serially)
2.
do not use events such as DataReceived, instead have a separate thread that performs all SerialPort operations, including synchronous (i.e. blocking) Reads. This gives you much more flexibility, you must however use the Control.Invoke pattern in order to touch GUI stuff.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
124256 wrote: SerialPort.DataReceived event never triggers
Did you remember to add an event handler for the DataReceived event? (serialPort.DataReceived += DataReceivedHandler)
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
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Hey getting an exception with the following code
string Percentage = LastLine.Substring(LastLine.LastIndexOf("%") - 2, 2);
the string is a wgetlog , Im trying to get the two characters before % but the above code crashes the debugger
modified on Tuesday, June 23, 2009 2:40 PM
|
|
|
|
|
Hi,
No matter how many mistakes your code contains, it is unlikely to crash the debugger. You are probably getting a run-time exception, which provides you with all the information about what is going wrong and where. Since you are already in the debugger, try to have a look at the content of "LastLine", so do one of the following:
- output the content of LastLine prior to the offending line (e.g.use Console.WriteLine);
- hover over "LastLine" somewhere in that block of code;
- add "LastLine" to the watch window;
- set a breakpoint.
In short, debug your code.
Hint: sometimes index functions return -1.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Good answer, best hint. Have a 5, or a cookie. Second thought I'm hungry, cookie for me and 5 for you.
|
|
|
|
|
It seems it is actually crashing vhost.exe and the above dosnt stop it
The problem seems to be that there is no way to know how many constrictors before the start of the string .
for example
1% = -1
10% = -2
100% = -3
is there any way to modify the code to prevent this exception ?
|
|
|
|
|
Hi,
you never can trust your inputs, so your code should be defensive. The percent sign may be absent, the number of digits may vary, there might be spaces, etc.
if what you really want is the number which starts at the start of the string and ends just before the percent sign, just locate the percent sign (check for !=-1) and take the substring to the left of it hence LastLine.Substring(0, percentPosition) which you then can easily pass on to int.TryParse() or something similar.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
|
You could buy a book. If you want me to write the code for you I charge by the hour.
|
|
|
|
|
Hey, welcome to the boards. For work you intend to pay for please try rentacoder[^] or codeproject even has a job[^] board.
You will find not many people here will do work for free for you, but you are welcome to read the tutorials and give it a crack and when you get stuck, try posting in the ASP.Net[^] forum, you will get more results. Again, only post specific problems, not a "please do this for me" post.
|
|
|
|
|
Please refrain from deleting messages, they are important so that others may view them and read both your question and the answers that follow.
|
|
|
|
|
Hello Everybody
I have a problem with retreiving data from Example Northwind.sdf database I need your help please !!!!
I`m very new to C# sharp so please be understanding.
So far I got a connection but cannot manage to get data into the text box(i`m using Microsoft Visual C# 2008 Express Edition) I looked into hundreds of examples and still nothing...
this is my CODE
-----------------
private void getDataButtton_Click(object sender, EventArgs e)<br />
{<br />
string conString = Properties.Settings.Default.NorthwindConnectionString;<br />
using (SqlCeConnection connect = new SqlCeConnection(conString))<br />
{<br />
try<br />
{<br />
connect.Open();<br />
MessageBox.Show("Connection Established");<br />
<br />
.....................<br />
.....................<br />
.....................<br />
<br />
}<br />
catch<br />
{<br />
MessageBox.Show("Connection Error!!!");<br />
}<br />
}<br />
}
Dim
|
|
|
|
|
Once you have connected to the database, use SQLCommand and either SQLDataReader or SQLDataAdapter to get the data. Then set this as the text for the textbox.
There are a plenty of examples available on net for doing this.
|
|
|
|
|
Any chacne that you could post one for my code please??
Seriously I have been trying to find solution for last 5 days !
|
|
|
|
|
There's a tutorial here[^]. You should be able to figure it out based on the example, within a day
dimo1982 wrote: Seriously I have been trying to find solution for last 5 days !
Seriously, you won't find ready-to-go solutions that you can copy&paste. Well, not often at least. In stead of trying to find your next solution, just read the documentation, see how the stuff works and make notes.
I are troll
|
|
|
|
|
Can you post your SQL query? Is the connection successful?
Can you give any other details, maybe you have the right direction but simply get caught on something simple (as is usually the case).
Unfortunately no one will write your code for you, but again post the contents of Properties.Settings.Default.NorthwindConnectionString as well as your sql query, and the status of your connection. Then we can help you further.
|
|
|
|
|
Ok as soon as I get back home I will post my code
|
|
|
|
|
I have a multi line log stored in a string in c# , Is there any way to turn the last line of this string to a new string ?
Thanks
|
|
|
|
|
Something like this;
assume s is your string with multiple lines.
string lastLine is your string to hold the last line of your string s.
lastLine = s.Substring(s.LastIndexOf(Environment.NewLine), s.Length - s.LastIndexOf(Environment.NewLine));
Enjoy.
|
|
|
|
|
Hi,
assuming your string's newline matches your system's newline definition, I would try something along these lines:
string lastLine=s;
int lastNewlinePosition=s.LastIndexOf(Environment.NewLine);
if (lastNewlinePosition>=0) lastLine=s.Substring(lastNewlinePosition+Environment.NewLine.Length);
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Member 6038196 wrote: I have a multi line log stored in a string
From where does that log gets into the string? If it comes from a file, use ReadAllLines and get the last line from the array.
Otherwise you already have replies.
|
|
|
|
|
I want to know about virtual, override & protected in C#.
Pls, write.
Thanks to all.
S. Mustafa Kamal
|
|
|
|