Click here to Skip to main content
15,913,090 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem with negative number Pin
K. Ahlers14-Aug-07 1:40
K. Ahlers14-Aug-07 1:40 
AnswerRe: Problem with negative number Pin
Luc Pattyn14-Aug-07 1:42
sitebuilderLuc Pattyn14-Aug-07 1:42 
GeneralRe: Problem with negative number Pin
K. Ahlers14-Aug-07 1:45
K. Ahlers14-Aug-07 1:45 
GeneralRe: Problem with negative number Pin
J4amieC14-Aug-07 3:24
J4amieC14-Aug-07 3:24 
GeneralRe: Problem with negative number Pin
Luc Pattyn14-Aug-07 6:06
sitebuilderLuc Pattyn14-Aug-07 6:06 
GeneralRe: Problem with negative number Pin
K. Ahlers14-Aug-07 10:57
K. Ahlers14-Aug-07 10:57 
GeneralRe: Problem with negative number Pin
Luc Pattyn14-Aug-07 13:31
sitebuilderLuc Pattyn14-Aug-07 13:31 
GeneralRe: Problem with negative number Pin
K. Ahlers14-Aug-07 23:14
K. Ahlers14-Aug-07 23:14 
Good morning Luc,

here is the complete method:

        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) {<br />
            try {<br />
                // Read out existing chars into _buffer<br />
                _buffer += serialPort1.ReadExisting();<br />
<br />
                // If there is a complete line availiable process it<br />
                int posofbreak = _buffer.IndexOf('\n');<br />
                if (posofbreak > -1) {<br />
                    // Get the line<br />
                    string tmp = _buffer.Substring(0, posofbreak).Trim();<br />
<br />
                    // If there is more code than this line put it back into the buffer<br />
                    if (posofbreak < _buffer.Length - 1)<br />
                        _buffer = _buffer.Substring(posofbreak + 1);<br />
<br />
                    // If there is a command-prompt before the log-text remove it<br />
                    while (tmp.IndexOf('>') > -1)<br />
                        tmp = tmp.Substring(tmp.IndexOf('>') + 1).Trim();<br />
<br />
                    // Get a database-readable date<br />
                    string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");<br />
<br />
                    // Create insert-command for the database<br />
                    MySqlCommand cmd = new MySqlCommand("INSERT INTO cisco_log (datelogged, logentry) VALUES ('" + now + "', '" + tmp + "')");<br />
<br />
                    // If the textbox with every logoutput is too long shorten it<br />
                    if(box.Text.Length > 5000) <br />
                        box.Text = box.Text.Substring(0, 5000);<br />
<br />
                    // Add the new line before the old logtext<br />
                    box.Text = tmp + "\r\n" + box.Text;<br />
<br />
                    // If there is a call with both lines connected free one line for that call<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 there is a line error reconnect the line<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 />
                    // Check whether the second line is connected, if not connect it and execute the insert-command<br />
                    if (tmp.Length > 0) {<br />
                        while (_conn.State != ConnectionState.Open) {<br />
                            _conn.Open();<br />
                            Thread.Sleep(100);<br />
                        }<br />
                        cmd.Connection = _conn;<br />
                        // MARKER<br />
                        cmd.ExecuteNonQuery();<br />
                    }<br />
<br />
                }<br />
<br />
                // Write the content of _buffer to a textbox for debug view<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

GeneralRe: Problem with negative number Pin
Luc Pattyn15-Aug-07 2:43
sitebuilderLuc Pattyn15-Aug-07 2:43 
GeneralRe: Problem with negative number Pin
K. Ahlers15-Aug-07 3:29
K. Ahlers15-Aug-07 3:29 
GeneralRe: Problem with negative number Pin
Luc Pattyn15-Aug-07 3:57
sitebuilderLuc Pattyn15-Aug-07 3:57 
GeneralRe: Problem with negative number Pin
K. Ahlers17-Aug-07 0:35
K. Ahlers17-Aug-07 0:35 
GeneralRe: Problem with negative number Pin
Luc Pattyn17-Aug-07 5:43
sitebuilderLuc Pattyn17-Aug-07 5:43 
Question[C#] - How to print a file programmatically... Pin
aravinda77713-Aug-07 23:14
aravinda77713-Aug-07 23:14 
AnswerRe: [C#] - How to print a file programmatically... Pin
Giorgi Dalakishvili13-Aug-07 23:27
mentorGiorgi Dalakishvili13-Aug-07 23:27 
AnswerRe: [C#] - How to print a file programmatically... Pin
Hessam Jalali14-Aug-07 2:09
Hessam Jalali14-Aug-07 2:09 
GeneralRe: [C#] - How to print a file programmatically... Pin
Michael Sync14-Aug-07 21:43
Michael Sync14-Aug-07 21:43 
GeneralRe: [C#] - How to print a file programmatically... Pin
Green Goblin20-Aug-07 9:31
Green Goblin20-Aug-07 9:31 
Questionproblem in calling a dll file Pin
kandy_soliton13-Aug-07 22:47
kandy_soliton13-Aug-07 22:47 
AnswerRe: problem in calling a dll file Pin
Giorgi Dalakishvili13-Aug-07 22:51
mentorGiorgi Dalakishvili13-Aug-07 22:51 
GeneralRe: problem in calling a dll file Pin
kandy_soliton13-Aug-07 23:57
kandy_soliton13-Aug-07 23:57 
GeneralRe: problem in calling a dll file Pin
Giorgi Dalakishvili14-Aug-07 0:01
mentorGiorgi Dalakishvili14-Aug-07 0:01 
GeneralRe: problem in calling a dll file Pin
N a r e s h P a t e l14-Aug-07 0:50
N a r e s h P a t e l14-Aug-07 0:50 
GeneralRe: problem in calling a dll file [modified] Pin
Liam O'Hagan14-Aug-07 19:22
Liam O'Hagan14-Aug-07 19:22 
GeneralRe: problem in calling a dll file Pin
kandy_soliton21-Aug-07 19:35
kandy_soliton21-Aug-07 19:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.