nyholku / purejavacomm

Pure Java implementation of JavaComm SerialPort
http://www.sparetimelabs.com/purejavacomm/index.html
BSD 3-Clause "New" or "Revised" License
367 stars 146 forks source link

type "jtermios.windows.WinAPI$ULONG_PTR" is not supported #128

Closed tmaxted closed 2 years ago

tmaxted commented 5 years ago

When I call CommPortIdentifier.getPortIdentifier("COM2") I get an error that unsigned Long pointer is not supported. I know the device is connected on COM2 because I can access it in YAT.

I've imported the library using gradle compile group: 'com.github.purejavacomm', name: 'purejavacomm', version: '1.0.2.RELEASE'

Stack trace: java.lang.IllegalArgumentException: Invalid Structure field in class jtermios.windows.WinAPI$OVERLAPPED, field name 'Internal' (class jtermios.windows.WinAPI$ULONG_PTR): The type "jtermios.windows.WinAPI$ULONG_PTR" is not supported: Can't create an instance of class jtermios.windows.WinAPI$ULONG_PTR, requires a public no-arg constructor: java.lang.reflect.InvocationTargetException at com.sun.jna.Structure.validateField(Structure.java:1215) at com.sun.jna.Structure.validateFields(Structure.java:1224) at com.sun.jna.Structure.<init>(Structure.java:200) at com.sun.jna.Structure.<init>(Structure.java:193) at com.sun.jna.Structure.<init>(Structure.java:180) at com.sun.jna.Structure.<init>(Structure.java:172) at jtermios.windows.WinAPI$OVERLAPPED.<init>(WinAPI.java:459) at jtermios.windows.JTermiosImpl$Port.<init>(JTermiosImpl.java:65) at jtermios.windows.JTermiosImpl$Port.<init>(JTermiosImpl.java:53) at jtermios.windows.JTermiosImpl.open(JTermiosImpl.java:348) at jtermios.JTermios.open(JTermios.java:422) at purejavacomm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:101) at com.<redacted>.network.SerialClient.SerialClient.connect(SerialClient.java:47) at com.<redacted>.network.NMEAConnection.NMEAConnection.connect(NMEAConnection.java:148) at com.<redacted>.nmea_device.Application.run(Application.java:93) at com.<redacted>.nmea_device.Application.main(Application.java:132) Caused by: java.lang.IllegalArgumentException: The type "jtermios.windows.WinAPI$ULONG_PTR" is not supported: Can't create an instance of class jtermios.windows.WinAPI$ULONG_PTR, requires a public no-arg constructor: java.lang.reflect.InvocationTargetException at com.sun.jna.Native.getNativeSize(Native.java:1362) at com.sun.jna.Structure.getNativeSize(Structure.java:2174) at com.sun.jna.Structure.getNativeSize(Structure.java:2164) at com.sun.jna.Structure.validateField(Structure.java:1211) ... 15 more

Any help is appreciated.

nyholku commented 5 years ago

On 19 Sep 2019, at 6.43, Tom M notifications@github.com wrote:

When I call CommPortIdentifier.getPortIdentifier("COM2") I get an error that unsigned Long pointer is not supported. I know the device is connected on COM2 because I can access it in YAT.

I've imported the library using gradle compile group: 'com.github.purejavacomm', name: 'purejavacomm', version: '1.0.2.RELEASE'

Stack trace: java.lang.IllegalArgumentException: Invalid Structure field in class jtermios.windows.WinAPI$OVERLAPPED, field name 'Internal' (class jtermios.windows.WinAPI$ULONG_PTR): The type "jtermios.windows.WinAPI$ULONG_PTR" is not supported: Can't create an instance of class jtermios.windows.WinAPI$ULONG_PTR, requires a public no-arg constructor: java.lang.reflect.InvocationTargetException at com.sun.jna.Structure.validateField(Structure.java:1215) at com.sun.jna.Structure.validateFields(Structure.java:1224) at com.sun.jna.Structure.(Structure.java:200) at com.sun.jna.Structure.(Structure.java:193) at com.sun.jna.Structure.(Structure.java:180) at com.sun.jna.Structure.(Structure.java:172) at jtermios.windows.WinAPI$OVERLAPPED.(WinAPI.java:459) at jtermios.windows.JTermiosImpl$Port.(JTermiosImpl.java:65) at jtermios.windows.JTermiosImpl$Port.(JTermiosImpl.java:53) at jtermios.windows.JTermiosImpl.open(JTermiosImpl.java:348) at jtermios.JTermios.open(JTermios.java:422) at purejavacomm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:101) at com..network.SerialClient.SerialClient.connect(SerialClient.java:47) at com..network.NMEAConnection.NMEAConnection.connect(NMEAConnection.java:148) at com..nmea_device.Application.run(Application.java:93) at com..nmea_device.Application.main(Application.java:132) Caused by: java.lang.IllegalArgumentException: The type "jtermios.windows.WinAPI$ULONG_PTR" is not supported: Can't create an instance of class jtermios.windows.WinAPI$ULONG_PTR, requires a public no-arg constructor: java.lang.reflect.InvocationTargetException at com.sun.jna.Native.getNativeSize(Native.java:1362) at com.sun.jna.Structure.getNativeSize(Structure.java:2174) at com.sun.jna.Structure.getNativeSize(Structure.java:2164) at com.sun.jna.Structure.validateField(Structure.java:1211) ... 15 more

Any help is appreciated.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

This sounds like a non compatible version of JNA.

tmaxted commented 5 years ago

This sounds like a non compatible version of JNA.

Hi, interesting. I am getting JNA version 5.4.0 from the maven central repository and the same error still occurs

nyholku commented 5 years ago

Still that sounds like the most likely problem. If you look at the code class ULONG_PTR not supported comes when the code is instantiating class OVERLAPPED and for sure every Windows instance of PureJavaComm in the history have instantiated that class and thus problems should have surfaced before if it was problem with PJC.

Further looking at the code you see that ULONG_PTR does have a "public a public no-arg constructor" contrary to what the stack trace claims.

I'm still on JNA 4.0.0 and it seems to work for me (well, I'm on macOS but I'm sure I've tested this combo on Windows too).

I would try an some 4.x.y JNA as way to diagnose this and then seek guidance from the JNA mailing list.

tmaxted commented 5 years ago

Hi I just realised I never replied to this...

I appreciate you taking the time to try and help :)

I actually never found a solution with this, I change to using scream3r's jssc which provided the tools I needed.

yijunwu commented 2 years ago

This sounds like a non compatible version of JNA.

I encountered the same problem(java.lang.IllegalArgumentException: The type "jtermios.windows.WinAPI$ULONG_PTR" is not supported) and found it is indeed a JNA version compatibility problem. After downgrading to JNA 4.2.2(previously 5.10.0), the problem is solved. Just FYI.

nyholku commented 2 years ago

On 25. Jan 2022, at 11.27, Jacob Wu @.***> wrote:

On 19 Sep 2019, at 6.43, Tom M @.***> wrote: When I call CommPortIdentifier.getPortIdentifier("COM2") I get an error that unsigned Long pointer is not supported. I know the device is connected on COM2 because I can access it in YAT. I've imported the library using gradle compile group: 'com.github.purejavacomm', name: 'purejavacomm', version: '1.0.2.RELEASE' Stack trace: java.lang.IllegalArgumentException: Invalid Structure field in class jtermios.windows.WinAPI$OVERLAPPED, field name 'Internal' (class jtermios.windows.WinAPI$ULONG_PTR): The type "jtermios.windows.WinAPI$ULONG_PTR" is not supported: Can't create an instance of class jtermios.windows.WinAPI$ULONG_PTR, requires a public no-arg constructor: java.lang.reflect.InvocationTargetException at com.sun.jna.Structure.validateField(Structure.java:1215) at com.sun.jna.Structure.validateFields(Structure.java:1224) at com.sun.jna.Structure.(Structure.java:200) at com.sun.jna.Structure.(Structure.java:193) at com.sun.jna.Structure.(Structure.java:180) at com.sun.jna.Structure.(Structure.java:172) at jtermios.windows.WinAPI$OVERLAPPED.(WinAPI.java:459) at jtermios.windows.JTermiosImpl$Port.(JTermiosImpl.java:65) at jtermios.windows.JTermiosImpl$Port.(JTermiosImpl.java:53) at jtermios.windows.JTermiosImpl.open(JTermiosImpl.java:348) at jtermios.JTermios.open(JTermios.java:422) at purejavacomm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:101) at com..network.SerialClient.SerialClient.connect(SerialClient.java:47) at com..network.NMEAConnection.NMEAConnection.connect(NMEAConnection.java:148) at com..nmea_device.Application.run(Application.java:93) at com..nmea_device.Application.main(Application.java:132) Caused by: java.lang.IllegalArgumentException: The type "jtermios.windows.WinAPI$ULONG_PTR" is not supported: Can't create an instance of class jtermios.windows.WinAPI$ULONG_PTR, requires a public no-arg constructor: java.lang.reflect.InvocationTargetException at com.sun.jna.Native.getNativeSize(Native.java:1362) at com.sun.jna.Structure.getNativeSize(Structure.java:2174) at com.sun.jna.Structure.getNativeSize(Structure.java:2164) at com.sun.jna.Structure.validateField(Structure.java:1211) ... 15 more Any help is appreciated. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread. This sounds like a non compatible version of JNA.

I encountered the same problem(java.lang.IllegalArgumentException: The type "jtermios.windows.WinAPI$ULONG_PTR" is not supported) and found it is indeed a JNA version compatibility problem. After downgrading to JNA 4.2.2(previously 5.10.0), the problem is solved. Just FYI.

— Reply to this email directly, view it on GitHub https://github.com/nyholku/purejavacomm/issues/128#issuecomment-1020979559, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFP7LM6Y2B2FSUVMYETM5TUXZUHBANCNFSM4IYGARHA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.

Thansk for the heads up!