Note that there are some explanatory texts on larger screens.

plurals
  1. PObug in serial port communication
    primarykey
    data
    text
    <p>I might just have the weirdest bug you've heard today.</p> <p>I have this one (very long) method inside a thread, which sends formatted data to a RS232 Led Display. </p> <p>It should display something like this</p> <pre><code>TITLE SUBTITLE 1 ELEMENT 1 ELEMENT 2 SUBTITLE 2 ELEMENT 1 ELEMENT 2 ELEMENT 3 </code></pre> <p>well, each one on it's own message.</p> <p>I'm calling Thread.Sleep(N) after each one of the messages (so each message is displayed N time).</p> <ul> <li>N being the number of seconds</li> </ul> <p>Ok, everything is fine until now. The thing is that if <code>(10 &lt;= N &lt;= 20)</code> I get the following output:</p> <pre><code>TITLE TITLE TITLE TITLE TITLE TITLE TITLE TITLE </code></pre> <p>I can hear the <em>beep</em> when I send the message. I even installed a serial port monitor, to check if the information I was sending was the same.</p> <p>So just to summarize:</p> <p>Writing on Serial Port works after sleeping the thread for n &lt;= 9 or n >= 20. Anything in between will produce an erroneous output, like if the output was cached or something</p> <p>What can this be?</p> <p><strong>Update</strong></p> <ul> <li>Ok, I know System.Threading.Sleep takes miliseconds as arguments. just multiply the number by 1000.</li> <li>Whenever the led display receives a new well formatted message, it beeps. I should have clarified that.</li> </ul> <p>Here is a snippet (this sends the first title)</p> <pre><code> using (var ld = new LedScreen(COM)) { ld.AddEffect(LedScreen.Effects.Snow); ld.AddText(LedScreen.Colors.Red, titulos[ThreadControl.Fase]); ld.AddEffect(LedScreen.Effects.DSnow); ld.Write(); } //Console.WriteLine(titulos[ThreadControl.Fase]); //esperamos N tiempo (titulo) Thread.Sleep(TiempoTitulo); </code></pre> <p>I wrote the LedScreen class. The write method is this one:</p> <pre><code> public void Write() { //caracteres de terminacion buffer.AddRange(new byte[] { 0xBF, 0xB1 }); try { if (!sp.IsOpen) sp.Open(); sp.Write(buffer.ToArray(), 0, buffer.Count); } finally { sp.Close(); } } </code></pre> <p><strong>Update 2</strong></p> <p>I finally got it to work (ugly fix, but meh.)</p> <p>Before each write to the serial port, I send a "blank" message with no delay. That clears the screen, before sending the actual message. hooray! and it works for whatever amount of seconds I sleep the thread</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload