B4J Question How to read a switch: A simple way?

positrom2

Active Member
Licensed User
Longtime User
Is there a simple solution to read the status of a switch (or a digital voltage 0/5V or so?)
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Is the switch connected to a microcontroller or something? If so, consider using the jSerial library with AsyncStreams to read serial data from the microcontroller via USB or Bluetooth.
 
Last edited:
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
Is the switch connected to a microcontroller
For the switch better without a µC. A µC already streams data via BT to the B4J app.
I wish to detect the state of the switch independently from the µC.
Is there some library to handle an FTD232 to read its port (pins)?
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
The FT232 is seen as a com port.
Could I read for instance DSR without using Asyncstreams? And how to do it with AS?
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
It doesn't look like the jSerial library fires any events. But you can hook up the jSerial library's InputStream and OutputStream to AsyncStreams (indeed, this is the preferred method) and AsyncStreams will take care of sending data and firing events when data is received. If your data is primarily textual in nature, use AsyncStreamsText.
 
Upvote 0
Top