|
Hi,
J4amieC wrote: make Visual display line numbers: Tools/Options/TextEditor/...
it is a shame Microsoft did not turn that on by default; posters ignore line numnbers
in exceptions since they don't show in source files anyway, making them look for
problems everywhere except where they really are.
J4amieC wrote: where are you from
Belgium, a little south of where you are See profile page.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Okay NOW i have a complete error-message:
System.ArgumentOutOfRangeException: Non-negative number required.<br />
Parameter name: count<br />
at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)<br />
at MySql.Data.MySqlClient.MySqlStream.Read(Byte[] buffer, Int32 offset, Int32 count)<br />
at MySql.Data.MySqlClient.MySqlStream.ReadString(Int64 length)<br />
at MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData41()<br />
at MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData()<br />
at MySql.Data.MySqlClient.NativeDriver.ReadColumnMetadata(Int32 count)<br />
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()<br />
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)<br />
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()<br />
at Cisco2Mysql.Form1.serialPort1_DataReceived(Object sender, SerialDataReceivedEventArgs e)<br />
So it seems to be really a buggy .NET-Connector or can anyone there a mistake by me?
With best regards,
K. Ahlers
|
|
|
|
|
OK, seems the problem is in your serialPort1_DataReceived method.
Will you find it yourself, or do you plan on showing us the entire method's source code ?
For some reason, we did not get line numbers. Is this release code ?
And this seemed like an 9-hour run, not a 17-hour one ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Good morning Luc,
here is the complete method:
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) {<br />
try {<br />
_buffer += serialPort1.ReadExisting();<br />
<br />
int posofbreak = _buffer.IndexOf('\n');<br />
if (posofbreak > -1) {<br />
string tmp = _buffer.Substring(0, posofbreak).Trim();<br />
<br />
if (posofbreak < _buffer.Length - 1)<br />
_buffer = _buffer.Substring(posofbreak + 1);<br />
<br />
while (tmp.IndexOf('>') > -1)<br />
tmp = tmp.Substring(tmp.IndexOf('>') + 1).Trim();<br />
<br />
string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");<br />
<br />
MySqlCommand cmd = new MySqlCommand("INSERT INTO cisco_log (datelogged, logentry) VALUES ('" + now + "', '" + tmp + "')");<br />
<br />
if(box.Text.Length > 5000) <br />
box.Text = box.Text.Substring(0, 5000);<br />
<br />
box.Text = tmp + "\r\n" + box.Text;<br />
<br />
if (tmp.Contains("L11 0")) {<br />
serialPort1.WriteLine("CD EWE");<br />
serialPort1.WriteLine("DISCO 2");<br />
LogWrite("Call detected, disconnecting second line.");<br />
}<br />
<br />
if (tmp.Contains("L67 2")) {<br />
Thread.Sleep(2000);<br />
serialPort1.WriteLine("CD EWE");<br />
serialPort1.WriteLine("CALL 2");<br />
LogWrite("Line Integrity Violation detected, reconnecting second line.");<br />
}<br />
<br />
if (tmp.Length > 0) {<br />
while (_conn.State != ConnectionState.Open) {<br />
_conn.Open();<br />
Thread.Sleep(100);<br />
}<br />
cmd.Connection = _conn;<br />
cmd.ExecuteNonQuery();<br />
}<br />
<br />
}<br />
<br />
buff.Text = _buffer;<br />
}<br />
catch (Exception ex) {<br />
LogWrite("Exception at serialPort1_DataReceived: "+ex.ToString());<br />
}<br />
}
After the "MARKER" the exception is thrown. (Yes it is a release-binary)
With best regards,
K. Ahlers
|
|
|
|
|
Hi,
I looked at your code and have some comments:
1.
you did not follow my advice "put a try-catch and have it show all relevant variables
when it catches this or some other exception, including cmd, tmp, ..."
2.
I don't see why you have the test in
if(posofbreak < _buffer.Length - 1) _buffer = _buffer.Substring(posofbreak + 1);
With it, if _buffer contains just one line ending on \n, that line remains in
_buffer and will be processed again next time DataReceived fires.
3.
while(tmp.IndexOf('>') > -1) tmp = tmp.Substring(tmp.IndexOf('>') + 1).Trim();
could have been handled more elegantly with ListIndexOf
4.
I am not sure the Thread.Sleeps, especially the one with 2000, are a good idea
inside DataReceived; they make your code not react for 2 seconds on the next
data; if for some reason "L67 2\n" comes in every second, you will never
catch up.
5.
I don't know what value serialport1.ReceivedBytesThreshold has; if it is
much larger than 1, chances are you receive more than one line of text every
time, but you only process one line at a time.
Actually, there should have been a while loop: as long as entire lines are
available, process it.
6.
if buffer contains only one line of the form
sometext > \n
then tmp will be an empty string; not sure SQL will like that
I strongly suggest you follow my advice (see 1); I don't understand how you
did not do this from the beginning: when something goes wrong, the more information
you have about it, the easier it is to pinpoint the problem...
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
1) How can I do that? In the try-catch these variables are not longer availiable. How to access them without declaring them global? Or did you mean to define a try-catch inside my existing try-catch?
2) Solved.
4) It must sleep about 2 seconds because the router have to clean up the line before reconnecting. This error can appear only if the line is connected - so not multiple times before reconnecting.
5) Solved.
6) If tmp.lenght is not greater than 0 the SQL-Command will not be executed.
With best regards,
K. Ahlers
|
|
|
|
|
Hi
1.
declare and initialize the var before the try statement (or as a class
member, see _buffer)
6.
sorry, my mistake
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Okay - This time it took really long to the next crash.
So I cant find any timing in there.
Here is the debug-output:
<br />
Content of tmp: """Connection 2 Add Link 2 Channel 2"""<br />
MySQL-Command: """INSERT INTO cisco_log (datelogged, logentry) VALUES ('2007-08-17 11:47:38', 'Connection 2 Add Link 2 Channel 2')"""<br />
Buffer-Content: """CISCO:EWE> """<br />
PosOfBreak: 50<br />
<br />
Exception: System.ArgumentOutOfRangeException: Non-negative number required.<br />
Parameter name: count<br />
at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)<br />
at MySql.Data.MySqlClient.MySqlStream.Read(Byte[] buffer, Int32 offset, Int32 count)<br />
at MySql.Data.MySqlClient.MySqlStream.ReadString(Int64 length)<br />
at MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData41()<br />
at MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData()<br />
at MySql.Data.MySqlClient.NativeDriver.ReadColumnMetadata(Int32 count)<br />
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()<br />
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)<br />
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()<br />
at Cisco2Mysql.Form1.serialPort1_DataReceived(Object sender, SerialDataReceivedEventArgs e)<br />
The only constant in there is the exception. Every time it's raised by the ExecuteNonQuery()-method.
I do not have any idea why this happens - so if you can help me it would be fine. If you don't have any idea too i'll have to try the ODBC-connector. Might be that it will not crash with this error...
With best regards,
K. Ahlers
|
|
|
|
|
Hi,
as long as your SQL statement looks good, we must assume a bug in MySQL.
which version are you running ?
I have googled a bit and found:
1.
there has been a bug #7345 which got fixed in Version 1.0.4 1-20-05
according to this[^]
2.
there has been/still is a bug giving same message when querying with two
result sets. If that could apply, go and look deeper for that.
I trust you don't have extra threads that also do SQL stuff at the same time?
If your version is recent I would suggest you post this problem to the MySQL
site.
Good luck, and keep us posted.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi guys,
I need to print a file (maybe a .doc or 'jpg or whatever), which is identical in functionality to what we do by right clicking the document and giving the print command in the windows explorer.
Is there any way which I can give the document path through the programme and print it irrespective of the exact type (if it is printable)?
I can have the functionality through any event. But, I want to know how to implement the print function once the path is given.
Regards,
A
|
|
|
|
|
I think you should use Process and ProcessStartInfo classes to accomplish this. Use verb property of ProcessStartInfo to specify print command
|
|
|
|
|
Here is the code from There is always the way to do it, but I don't know one of the members
I used it and it worked well
private static void doPrint(string executable, string fileFullPath, string printerName)
{
System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = "/h /t \"" + fileFullPath + "\" \"" + printerName + "\"";
startInfo.FileName = executable;
startInfo.UseShellExecute = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
System.Diagnostics .Process process = new Process() ;
try {
process = Process.Start(startInfo);
}
catch (Exception ex)
{
}
finally
{
process.WaitForExit(20000);
if (process.HasExited == false)
{
process.Kill();
}
}
}
good luck
|
|
|
|
|
nice. you got 5 from me.
Hessam Jalali wrote: There is always the way to do it, but I don't know
haha. cool name..
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
Do you have any ideas on going further than this get the print job to print legal size. I have a varation of this code and I have tried setting the paper source and paper size to be the correct tray and paper kind but Adobe Reader appears to override and still print on letter size all of the time.
GG
|
|
|
|
|
Is it possible to link any dll file with a c# program without knowing any details about it and to get details of the data and functions of it.I tried with explicit linking but i could not.If any could please...
Thanks in advance
kandy
|
|
|
|
|
Do you mean .NET dll or Native one? I guess the answer is yes in both cases but solutions are very different.
|
|
|
|
|
ya..Native dll's.Mostly the driver dlls created by different vendors
|
|
|
|
|
Then you need to use PInvoke with late binding. Search for the keywords.
P.S. If you don't know about the functions that reside in that dll it can be impossible or quite difficult. Why would you need to invoke function from a dll about which you have no information?
|
|
|
|
|
HI,
Use Object Browser for getting the schema definition of the dll file.
Naresh Patel
|
|
|
|
|
Which works if it's a .Net DLL
You could also try dumpbin, but that will only give you the name of the function, not the parameters (unless it exports decorated names, then you can use 'undname' to undecorate the names to retrieve the parameters)
-- modified at 1:29 Wednesday 15th August, 2007
I have no blog...
|
|
|
|
|
Sorry for the delay answering. Actually I was trying for .Net Dlls.
It worked fine.
Let me tell you a scenario where in the user has to choose any kind of dll he wants, rather be .Net Dll or Native Dll for a connection to his server.
In that he knows the function to Invoke.
I need to write a common user interface to invoke any kind of dll, based on the choice of the user. Is that possible ?. If so help me regarding the stratergy that i have to use or any examples of such accomplishment.
FYI
I know one software which is doing to most of the Dll's.
Thanks in Advance
|
|
|
|
|
I am using 400 text box in my Form. Updating Text property of all the 400 Text boxes in the Form takes more than 30 milliseconds. Is there any way to reduce this time in c# .net.
//Sample code
//t2 is the array of 400 Text boxes.
DateTime dt = DateTime.Now;
for (int i = 0; i < 400; i++)
t2[i].Text = i.ToString();
MessageBox.Show(((TimeSpan)(DateTime.Now - dt)).Milliseconds.ToString());
Nanda
|
|
|
|
|
Stop the visual update of the components using the BeginUpdate(), EndUpdate() methods. More importantly though, why do you have so many textboxes on a form? This doesn't sound like a good design to me.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
There is no BeginUpdate() and EndUpdate() methods associated with either the Form or the TextBox.
Thanks for the reply
Nanda
|
|
|
|
|
Hello,
I think Pete meant,
SuspendLayout();
ResumeLayout();
All the best,
Martin
|
|
|
|