Uart module

Hierarchy

Constructors

Properties

Obniz: Obniz

obniz to be used

onreceive?: ((data, text) => void)

Type declaration

    • (data, text): void
    • It is called when data is received. Data is array of bytes. Text is the same data but in text representation.

      So, if obniz Board receives 'A'.

      • Data is [0x41]
      • Text is "A"
      // Javascript Example
      obniz.uart0.start({tx:0, rx:1})
      obniz.uart0.onreceive = function(data, text) {
      console.log(data);
      console.log(text);
      }
      obniz.uart0.send("Hello");

      Parameters

      • data: number[]
      • text: string

      Returns void

received: any
timeout: number = ...

Rsponse waiting timeout in milliseconds

prefixed: string | boolean

Methods

  • Calls each of the listeners registered for a given event.

    Parameters

    • event: string
    • Rest ...args: any[]

    Returns boolean

  • It stops uart and releases io.

    // Javascript Example
    obniz.uart0.start({tx:0, rx:1})
    obniz.uart0.send("Hi");
    obniz.uart0.end();

    Returns void

  • Return an array listing the events for which the emitter has registered listeners.

    Returns string[]

  • It checks if there are data received but not yet used. If there are, it returns true.

    If you are using onreceive callback, it will always be false because you receive the data with the callback function as the data arrives.

    // Javascript Example
    obniz.uart0.start({tx:0, rx:1})

    while(1){
    if(obniz.uart0.isDataExists()){
    console.log(obniz.uart0.readText());
    }
    await obniz.wait(10); //wait for 10ms
    }

    Returns boolean

  • Return the number of listeners listening to a given event.

    Parameters

    • event: string

    Returns number

  • Return the listeners registered for a given event.

    Parameters

    • event: string

    Returns ListenerFn[]

  • Parameters

    • event: string
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns PeripheralUART

  • Add a listener for a given event.

    Parameters

    • event: string
    • fn: ListenerFn
    • Optional context: any

    Returns PeripheralUART

  • Add a one-time listener for a given event.

    Parameters

    • event: string
    • fn: ListenerFn
    • Optional context: any

    Returns PeripheralUART

  • It returns the one byte that are received but not yet used.

    // Javascript Example
    obniz.uart0.start({tx:0, rx:1})

    while(1){
    if(obniz.uart0.isDataExists()){
    console.log(obniz.uart0.readBytes());
    }
    await obniz.wait(10); //wait for 10ms
    }

    Returns null | number

    received data. If not exist data, return null.

  • It returns the data array that are received but not yet used.

    // Javascript Example
    obniz.uart0.start({tx:0, rx:1})

    while(1){
    if(obniz.uart0.isDataExists()){
    console.log(obniz.uart0.readBytes());
    }
    await obniz.wait(10); //wait for 10ms
    }

    Returns number[]

    received data. If not exist data, return [].

  • It returns the data that are received but not yet used as string.

    // Javascript Example
    obniz.uart0.start({tx:0, rx:1})

    while(1){
    if(obniz.uart0.isDataExists()){
    console.log(obniz.uart0.readText());
    }
    await obniz.wait(10); //wait for 10ms
    }

    Returns null | string

    received text data. If not exist data, return null.

  • Remove the listeners of a given event.

    Parameters

    • event: string
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns PeripheralUART

  • This sends data.

    Available formats are

    • string utf8 encoded byte array. Does not include null terminate

    • number will be one byte data

    • array of number array of bytes

    • Buffer array of bytes

    // Javascript Example
    obniz.uart0.start({tx:0, rx:1})
    obniz.uart0.send("Hi");
    obniz.uart0.send(0x11);
    obniz.uart0.send([0x11, 0x45, 0x44]);

    Parameters

    • data: string | number | number[] | Buffer

    Returns void

  • Setting DE IO. IF DE is set, then OS will automatically HIGH when start transmitting and LOW on end of transmitting.

    Parameters

    • io_de: number

      IO of DE(TX Enable)

    Returns void

  • Convert data array to string.

    Parameters

    • data: number[]

      data array

    Returns null | string

    converted string. If convert failed, return null.

Generated using TypeDoc