java-native / jssc

Java library for talking to serial ports (with added build support for maven, cmake, MSVC)
https://discord.gg/RBsUfE9sX9
GNU Lesser General Public License v3.0
173 stars 53 forks source link

Can't read serial port on Windows 10 #173

Open AlexanderSveshnikov opened 1 month ago

AlexanderSveshnikov commented 1 month ago

Hello. I'm trying to use JSSC to communicate with my STM32 device via virtual serial port, but I can read data only under debug mode. When I switch into run-mode, no reading performed. I use netbeans 22, java se 22.0.2 on 64 bit machine. And I use event listener to read data. What's wrong? Does anybody faced with this problem?

tresf commented 1 month ago

Hi,

Although you may find others that have the same problem, it's difficult for a JSSC developer to reproduce the issue without some form of reproducible code snippet.

Can you provide a minimally reproducible code snippet that illustrates the issue? Even a very basic Netbeans project that illustrates the issue may suffice.

AlexanderSveshnikov commented 1 month ago

numberaddition.zip Here is my sources

tresf commented 1 month ago

@AlexanderSveshnikov thanks for sharing the code. This code is not a minimally reproducible example as it 1,400 lines of code, which makes it a bit harder to understand what's going wrong with JSSC. Can you prepare a very simple example with JSSC that illustrates the problem?

[...] but I can read data only under debug mode. When I switch into run-mode, no reading performed.

When you say "debug mode", do you mean that you are placing the STM32 device into debug mode, or that you are running Netbeans in debug mode?

When you cannot read data, do you receive any information at all (console logs, symptoms, etc) that may allude to the problem?

AlexanderSveshnikov commented 1 month ago

When I say "Debug mode", I mean Netbeans in debug mode of course. When I cannot read data, I receive information from Netbeans console log:

 public void serialEvent(SerialPortEvent event) {

            if (event.isRXCHAR()) {
                if (event.getEventValue() > 0) {
                    try {
                        System.out.println("Got reply");  //<- This is the message I can view in debug mode, but can't in run mode!
tresf commented 1 month ago

When I say "Debug mode", I mean Netbeans in debug mode of course. When I cannot read data, I receive information from Netbeans console log: public void serialEvent(SerialPortEvent event) {

        if (event.isRXCHAR()) {
            if (event.getEventValue() > 0) {
                try {
                    System.out.println("Got reply");  //<- This is the message I can view in debug mode, but can't in run mode!

I'm not sure how the IDE's debug mode would impact the reliability of the library's behavior. Initial thoughts are that it will use a different compiled class cache, which may allude to the problem, but that's purely speculative. There may also be something about Java 22 that's causing something we haven't seen before.

I can fire up NetBeans on just about any OS and test the same version of JSSC against a serial device that I have locally to see if this is reproducible, but I would need a minimally reproducible code example, preferably a sample Netbeans project that I can use to click "Run" or "Debug" from.