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

Discussion in 'B4J Questions' started by positrom2, Jul 16, 2015.

  1. positrom2

    positrom2 Active Member Licensed User

    Is there a simple solution to read the status of a switch (or a digital voltage 0/5V or so?)
     
  2. Roycefer

    Roycefer Well-Known Member Licensed 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: Jul 16, 2015
  3. positrom2

    positrom2 Active Member Licensed User

    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)?
     
  4. Roycefer

    Roycefer Well-Known Member Licensed User

    There's this library for B4A: http://www.b4x.com/android/help/usbserial.html but I doubt it will work in B4J. How does your computer see the FTD232 chip? As a comport (like "COM3")? If so, then you can use jSerial and AsyncStreams.
     
  5. positrom2

    positrom2 Active Member Licensed 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?
     
  6. positrom2

    positrom2 Active Member Licensed User

    I found this:
    boolean=comport.DSR (compiles).
    Will try with hardware.
    Could DSR cause an event?
     
  7. positrom2

    positrom2 Active Member Licensed User

  8. Roycefer

    Roycefer Well-Known Member Licensed 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.
     
Loading...