开发者

RXTX difficulties in Windows

开发者 https://www.devze.com 2023-03-02 20:10 出处:网络
Good morning, I have a Java program, orderPrinter, that communic开发者_如何学运维ates to POS printer via USB-to-serial communication.I installed the RXTX and javax.comm libraries as per the instructi

Good morning,

I have a Java program, orderPrinter, that communic开发者_如何学运维ates to POS printer via USB-to-serial communication. I installed the RXTX and javax.comm libraries as per the instructions, and after some fiddling with file locations succeeded in getting the program running on my machine (Windows 7).

However, I'm running into difficulties getting it to work in Windows XP (which, after distribution, will be the primary platform, with secondary being Linux I presume). After substituting the 64-bit JAR and DLL files with their respective 32-bit substitutes (as found on the RXTX wiki), I've run into several issues:

1) RXTX seems to have trouble with locating the correct COM port. Testing via echo [gibberish] >> COMx generates a response, so I know that the printer is at COM5. The following code:

Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements()) {
            System.out.println("Port:  "+((CommPortIdentifier)(portList.nextElement())).getName());
        }
        CommPortIdentifier portID = CommPortIdentifier.getPortIdentifier(settings.port);

prints out "Port: //./COM5" as the only port on the 32-bit machine, whereas in Windows 7 I get back "Port: COM5". The first problem I encounter is that the call to CommPortIdentifier.getPortIdentifier(port) fails in XP; I can only imagine this is due to the CommPortIdentifier matching the port name exactly. Is there a way to modify the JAR to allow for more lenient port matching?

2) Assuming for now, as a temporary fix, I hard-code the exact expected string for Windows XP. Immediately afterwards, when I call portID.open([correct parameters), the program crashes with the following error:

Exception in thread "main" java.lang.VerifyError:  (class:  gnu/io/RXTXPort$SerialOutputStream, methd: flush signature: ()V) Illegal use of nonvirtual function call

Every solution I've found has boiled down to using an older version of RXTX; however, as stated, I'm using 2.1-7r2, which is to my knowledge the most recent stable release. I am completely baffled by this error and how to fix it. Any ideas?

Bear in mind, while I'm familiar with java programming, I'm much more limited in my understanding of build-related errors, which this seems to be the case; I would also like to be able to explain the issue so as to resolve this problem more easily in the future.

Thank you for your time.

EDIT: I believe I have a solution to problem 1; modifying the source and then recompiling. I don't really have time to debug why javac is not a valid command in the prompt, though, nor have I found a reliable way to do this in Eclipse. Again, this is my first time doing anything beyond importing a JAR, so it's a learning experience to say the least. Or a trial by fire at this point.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号