If i use scm.writeBytes other threads always freeze

3 views
Skip to first unread message

Makarna35

unread,
Apr 2, 2019, 3:55:49 AM4/2/19
to SerialPundit

If i use scm.writeBytes other threads always freeze


Example:

runProgressBar();
// WriteToPort
           
Object[] openPort = openComPort(selectedComPort.getSelectedItem().toString());
            scm
= (SerialComManager) openPort[0];
            handle
= (long) openPort[1];
           
try {
               
// Write delayInbytes
                scm
.writeBytes(handle, messagesData.getBytes(), speedSlider.getValue());
               
//System.out.println("WRITE COMPLATE : ");
               
//System.out.println("write : " + scm.writeString(handle, textSpeedSliderStringValue, 0));
                portRepeatingRead
();
           
} catch (Exception e) {
                e
.printStackTrace();
           
}

public void runProgressBar() {
    loadingBar
.setVisible(true);
    loadingBar
.setStringPainted(true);
    threadProgressBar
= new Thread(new Runnable() {
       
@Override
       
public void run() {
           
int i = 0;
           
try {
           
while (i <= 100) {
               
// fill the menu bar
                loadingBar
.setValue(i + 10);
 
               
// delay the thread
               
Thread.sleep(messagePercent1);
                i
+= 1;
           
}
       
}
       
catch (Exception e) {
       
}
       
}
   
});
    threadProgressBar
.start();
}


runProgressBar(); function start before scm. But always freeze. after finished write port loadingBar.setVisible(true); work. why?

Andreas Kuhtz

unread,
Apr 2, 2019, 8:07:40 AM4/2/19
to Makarna35, SerialPundit
Hello,

Is the loadingBar a swing UI element? In this case it should/must be updated from EDT, otherwise it can block.
You can try to change the line below "// fill menu bar" to:
SwingUtilities.invokeLater( () -> loadingBar.setValue(i + 10) );
Regards,
Andreas

--
You received this message because you are subscribed to the Google Groups "SerialPundit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to SerialPundit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/SerialPundit/53d0f748-7509-43eb-be9a-87eca2e004b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Makarna35

unread,
Apr 2, 2019, 1:48:41 PM4/2/19
to SerialPundit
Thanks.
Yes the loadingBar a swing UI element I'm try SwingUtilities.invokeLater( () -> loadingBar.setValue(i + 10) ); but still blocked.
With SwingUtilities.invokeLater( () -> loadingBar.setValue(i + 10) ); process strat after finished write port.

Makarna35

unread,
Apr 2, 2019, 3:09:27 PM4/2/19
to SerialPundit
I fix problem. I running writeport function as Background Thread.
Reply all
Reply to author
Forward
0 new messages