Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PeripheralUART<EventTypes>

Uart module

Type parameters

  • EventTypes: string

Hierarchy

Index

Constructors

constructor

Properties

Obniz

Obniz: Obniz

obniz to be used

Optional onreceive

onreceive: undefined | ((data: number[], text: string) => 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");

received

received: any

timeout

timeout: number = 30 * 1000

Rsponse waiting timeout in milliseconds

Static prefixed

prefixed: string | boolean

Methods

addListener

  • addListener(event: EventTypes, fn: ListenerFn, context?: any): this
  • Parameters

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

    Returns this

emit

  • emit(event: EventTypes, ...args: Array<any>): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: EventTypes
    • Rest ...args: Array<any>

    Returns boolean

end

  • end(): void
  • It stops uart and releases io.

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

    Returns void

eventNames

  • eventNames(): Array<EventTypes>
  • Return an array listing the events for which the emitter has registered listeners.

    Returns Array<EventTypes>

isDataExists

  • isDataExists(): boolean
  • 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

listenerCount

  • listenerCount(event: EventTypes): number
  • Return the number of listeners listening to a given event.

    Parameters

    • event: EventTypes

    Returns number

listeners

  • listeners(event: EventTypes): Array<ListenerFn>
  • Return the listeners registered for a given event.

    Parameters

    • event: EventTypes

    Returns Array<ListenerFn>

notifyFromObniz

  • notifyFromObniz(json: any): void

off

  • off(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Parameters

    • event: EventTypes
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

on

  • on(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a listener for a given event.

    Parameters

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

    Returns this

once

  • once(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a one-time listener for a given event.

    Parameters

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

    Returns this

readByte

  • readByte(): number | null
  • 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 number | null

    received data. If not exist data, return null.

readBytes

  • readBytes(): number[]
  • 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 [].

readText

  • readText(): string | null
  • 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 string | null

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

removeAllListeners

  • Remove all listeners, or those of the specified event.

    Parameters

    Returns this

removeListener

  • removeListener(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Remove the listeners of a given event.

    Parameters

    • event: EventTypes
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

send

  • send(data: string | number | number[] | Buffer): void
  • 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

start

  • It starts uart on io tx, rx.

    You can start uart without much configuration. Just use as below.

    Parameters

    Returns void

tryConvertString

  • tryConvertString(data: number[]): string | null
  • Convert data array to string.

    Parameters

    • data: number[]

      data array

    Returns string | null

    converted string. If convert failed, return null.

validate

  • validate(commandUri: any, json: any): WSSchema.MultiResult
  • Parameters

    • commandUri: any
    • json: any

    Returns WSSchema.MultiResult

Generated using TypeDoc