B4J Question AsyncStreams object passed to class wrapping jSerial - newdata event not found

MTailor

Member
Licensed User
Longtime User
Hi
I am wrapping jSerial in my own class and in the open I pass an AsyncStreams object and a string which is the event name.
When I send data via uart I get an exception -

java.lang.Exception: Sub rxporta_newdata was not found.

I have attached my test project.

The smoking gun could be that mAsyncStream.Initialize is called in the class module clsSerialPort but the sub rxporta_NewData is defined in the main module.

What am I am not getting here?

Thank you in advance
 

Attachments

  • SerialTst.zip
    16.8 KB · Views: 233

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

MTailor

Member
Licensed User
Longtime User
the event sub should be in the class.

I tried that after posting this and as you recommend, it does work.

However, I want this class to be reusable so in future I do not know how the application will consume the 'newdata' that arrives and in C++ I would have solved this by deriving from this class and have a virtual member function that would override the stub that would be in this class.

Erel suggests CallSub() and I did try that and it helps solve the problem of that a C++ virtual member function does - a future application can provide it's own consume functionality.

However, CallSub() does not check the argument list and so I will need to be very explicit in my documentation that the sub to be called has to have a certain signature otherwise it is going to go pear shaped -- unless I am mistaken.

And then I am curious how much of an time overhead does CallSub() add given there could be a search for that subname everytime that routine is invoked which will impact the data throughput. I have seen a post (quite old one) that there is a throughout issue as it is.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
However, CallSub() does not check the argument list and so I will need to be very explicit in my documentation that the sub to be called has to have a certain signature otherwise it is going to go pear shaped -- unless I am mistaken.
You do need to set the arguments correctly. You can use the #Event attribute to declare the event and it will then be autocompleted (only if you compile your class into a library or custom view).

The overhead of CallSub is very small. It doesn't search for the sub. CallSubDelayed will be a bit slower as it sends a message to the message queue which is later processed.
 
Upvote 0
Top