Listener for UART and Socket streams | Telit Cinterion IoT Developer Community
January 27, 2017 - 9:07am, 2487 views
Hello,
Is there a listener mechanism for ComConnection and/or SocketConnection data receive. In sample examples, an InputStream is opened for connection and it is checked always.
I'm using 2 separate thread to check if data is available in receive buffers of InputStreams (socket and uart streams). In a while loop, InputStream available() method is used to check if data received. Thread's run() method has an infinite while loop in it to check/read streams.
If there was a notification when a byte received like interrupt, it wouldn't be necessary to check buffer continuously.
Best Regards,
Hello,
There are no such listeners. You are doing it correctly with available() method (it is the recommended way because read() methods can block until the data is available). You should also add some delay with a sleep() method inside the loop with a value that is acceptable for your scenario because when there's no data to be read it works like the empty loop and it could slow down other threads execution.
Regards,
Bartłomiej
Hello Bartlomiej,
Thanks for the answer. I will apply delay with sleep as you recommended.
Is there a Thread number limit for user Midlets. How many threads can run at the same time for BGS5 properly?
There are 1 main thread and 4 other threads always in my application.
I checked the active thread ***** with activeCount() method for an application having only main thread. It is 33-34. If I compare this number with my Thread number,5, it seems no matter.
Are there recommandations about thread usage, thread ***** etc. for BGS5?
Best Regards,
Hello,
There are no fixed numbers for the maximum allowed thread *****. 5 threads shouldn't be a problem. But besides the number of threads there are other factors that influence the overall performance like empty loops, total number of objects in use etc.
Generally you need to always remember that the module is an embedded device with a limited resources and because of that the applications should be kept possibly simple and light. But each solution is different and each application is different. Each one ***** to be tested also for stability, memeory usage etc.
Please also see this article about optimising J2ME applications: https://iot-developer.thalesgroup.com/tutorial/optimising-j2me-applications
Regards,
Bartłomiej
Hello Bartlomiej,
Thank you very much.
Best Regards,