Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Characters on USB port #124

Open
danishmhmd opened this issue Apr 16, 2022 · 2 comments
Open

Missing Characters on USB port #124

danishmhmd opened this issue Apr 16, 2022 · 2 comments

Comments

@danishmhmd
Copy link

danishmhmd commented Apr 16, 2022

I am facing issue that sometimes number of characters are not properly received. Using serialPort.readString(serialPort.getInputBufferBytesCount(), 150) Method.(Maven Version 2.8.0) I tried using multiple values of timeout but still either two different messages are received in correctly. For ex:
Expected Data:
[011131FF8300000F0000000000420001000000e9]
[001131FF8300000F000000000042000200000097]

Actual Received Data:
[011131FF8300000F0000
000000420001000000e9]
[001131FF8300000F000000000042000200000097]

Or

[011131FF8300000F0000000000420001000000e9]
[001131FF8300000F000000000
042000200000097]

@tresf
Copy link

tresf commented Apr 16, 2022

I'm not familiar with what could cause this, but I wanted to reply to acknowledge the bug report so you know that the project is still active.

@tresf
Copy link

tresf commented Jan 9, 2025

@danishmhmd I've looked over this bug report and I believe the library is working to the best of it's ability. I will elaborate:

Missing Characters on USB port [...] I am facing issue that sometimes number of characters are not properly received.

If I'm reading your problem description properly, the expected and actual results do not appear to be missing characters, but rather appear in two separate chunks. Can you please confirm? I am basing this observation off of the fact that your expected and actual results are identical.

The way that readString works is it calls readBytes, which is basically just one of two native calls depending if you're on Windows or on *nix:

JNIEXPORT jbyteArray JNICALL Java_jssc_SerialNativeInterface_readBytes

JNIEXPORT jbyteArray JNICALL Java_jssc_SerialNativeInterface_readBytes

In the case of Windows, I believe it attempts to strictly send bytes back that are the size requested, but I'm not sure if this is 100% reliable. @hiddenalpha may be able to shed more light on this.

In the case of *nix, I believe it will send back only what could be read.

The reason I'm skeptical that this is an actual bug is because since I started using JSSC, I've always had to use byte delimiters (or length) in my application to detect when a stream was finished (I've never relied blindly on the result of readBytes) so I suspect this is a problem that all implementers have to work around.

Two years later I'm sure that you (@danishmhmd) have either chose a different library or coded these workarounds yourself, so I'm curious as to your thoughts, but at initial glance, I do not believe this to be a bug with the library, at least not one that we can easily and reasonably solve.

A response is required or this bug report will be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants