GithubHelp home page GithubHelp logo

Comments (4)

tresf avatar tresf commented on August 27, 2024

Hi,

I don't believe this is possible currently. To support this without breaking backwards compatibility, a new function (e.g. write(bytes[])) would have to be written and the old boolean functions would have to be update to check the return length.

This would require Windows and Unix C++ code to be updated to return jint and the current functions would be wrapped to still return a boolean.

Disclaimer, this library is mostly in maintenance mode, so any features would have to be authored by the vested/interested parties.

Relevant functions:

Unix:

JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_writeBytes
(JNIEnv *env, jobject, jlong portHandle, jbyteArray buffer){
jbyte* jBuffer = env->GetByteArrayElements(buffer, JNI_FALSE);
jint bufferSize = env->GetArrayLength(buffer);
jint result = write(portHandle, jBuffer, (size_t)bufferSize);
env->ReleaseByteArrayElements(buffer, jBuffer, 0);
return result == bufferSize ? JNI_TRUE : JNI_FALSE;
}

Windows:

JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_writeBytes
(JNIEnv *env, jobject, jlong portHandle, jbyteArray buffer){
HANDLE hComm = (HANDLE)portHandle;
DWORD lpNumberOfBytesTransferred;
DWORD lpNumberOfBytesWritten;
OVERLAPPED *overlapped = new OVERLAPPED();
jboolean returnValue = JNI_FALSE;
jbyte* jBuffer = env->GetByteArrayElements(buffer, JNI_FALSE);
overlapped->hEvent = CreateEventA(NULL, true, false, NULL);
if(WriteFile(hComm, jBuffer, (DWORD)env->GetArrayLength(buffer), &lpNumberOfBytesWritten, overlapped)){
returnValue = JNI_TRUE;
}
else if(GetLastError() == ERROR_IO_PENDING){
if(WaitForSingleObject(overlapped->hEvent, INFINITE) == WAIT_OBJECT_0){
if(GetOverlappedResult(hComm, overlapped, &lpNumberOfBytesTransferred, false)){
returnValue = JNI_TRUE;
}
}
}
env->ReleaseByteArrayElements(buffer, jBuffer, 0);
CloseHandle(overlapped->hEvent);
delete overlapped;
return returnValue;
}

from jssc.

danielgruber avatar danielgruber commented on August 27, 2024

Hi @tresf,

Thanks for your update! Iā€™m happy to implement the changes, still I would first want to know if there was a reason behind it not to implement it like this from the beginning?
So is this at all possible with the C stack being used? Or do I have to try?
Thanks!
Best
Daniel

from jssc.

tresf avatar tresf commented on August 27, 2024

I would first want to know if there was a reason behind it not to implement it like this from the beginning?

Hi, this project is a fork of the original from https://github.com/scream3r/java-simple-serial-connector, so the history behind this decision likely lies there.

So is this at all possible with the C stack being used? Or do I have to try?

I think the Unix code makes it relatively easy, but I'm not sure about the win32 API. Perhaps the answer lies in GetOverlappedResult returning a zero? I'm not very familiar with hardware flow control and only partially familiar with the C++ portions of the codebase. We do have some other volunteers here as well as a Slack channel if interested. @hiddenalpha has been very helpful with the C++ portions as well.

from jssc.

hiddenalpha avatar hiddenalpha commented on August 27, 2024

Looks related to issue #96

from jssc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.