Our offices are closed from August 1, 2020 to August 16, 2020. No orders will be shipped during this time.

TypeScript driver

Overview

The instrument TypeScript driver is written in line with the instrument C++ driver.

Example

For the following C++ driver:

class LedBlinker {
    #...
    uint32_t get_leds() {
        return ctl.read<reg::led>();
    }
    #...
}

The matching TypeScript driver is:

class LedBlinker {
    private driver: Driver;
    private id: number;
    private cmds: HashTable<ICommand>;
    constructor (private client: Client) {
        this.driver = this.client.getDriver('LedBlinker');
        this.id = this.driver.id;
        this.cmds = this.driver.getCmds();
    }
    getLeds(cb: (value: number) => void): void {
        this.client.readUint32(Command(this.id, this.cmds['get_leds']),
                                 (value) => {cb(value)});
    }
}

Available functions

Write

send(command)

Example

C++ driver:

void set_led(uint32_t index, bool status) {
    ctl.write_bit_reg(reg::led, index, status);
}

TypeScript driver:

setLed(index:number, status: boolean): void {
    this.client.send(Command(this.id, this.cmds['set_led'], index, status));
}

Read unsigned-integers

readUint32(cmd: CmdMessage, fn: (x: number) => void): void

Example

C++ driver:

uint32_t get_leds() {
    return ctl.read<reg::led>();
}

TypeScript driver:

getLeds(cb: (value: number) => void): void {
    this.client.readUint32(Command(this.id, this.cmds['get_leds']), (value) => {cb(value)});
}

Read signed-integers

readInt32(cmd: CmdMessage, fn: (x: number) => void): void

Read arrays

readUint32Array(cmd: CmdMessage, fn: (x: Uint32Array) => void): void
readFloat32Array(cmd: CmdMessage, fn: (x: Float32Array) => void): void
readFloat64Array(cmd: CmdMessage, fn: (x: Float64Array) => void): void

Read vectors

readUint32Vector(cmd: CmdMessage, fn: (x: Uint32Array) => void): void
readFloat32Vector(cmd: CmdMessage, fn: (x: Float32Array) => void): void
readFloat64Vector(cmd: CmdMessage, fn: (x: Float64Array) => void): void

Example

C++ driver:

std::vector<float>& get_decimated_data(uint32_t decim_factor, uint32_t index_low, uint32_t index_high) {
    //...
}

TypeScript driver:

getDecimatedData(callback: (data: number[][], range: jquery.flot.range) => void): void {
    this.client.readFloat32Vector(
        Command(this.id, this.cmds['get_decimated_data'], 1, this.indexLow, this.indexHigh), (array) => {
            //...
            callback(data, range);
    });
}

Read booleans

readBool(cmd: CmdMessage, fn: (x: boolean) => void): void

Read tuples

readTuple(cmd: CmdMessage, format: string, fn: (x: any[]) => void): void

Available format: * 'I': unsigned 32-bit integer * 'i': signed 32-bit integer * 'B': unsigned 8-bit integer * 'b': signed 8-bit integer * 'f': 32-bit floating point * 'd': 64-bit double precision * '?': boolean

Example

C++ driver:

auto get_status() {
    //...
    return std::make_tuple(
        laser_on,
        current,
        measured_current,
        measured_power
    );
}

TypeScript driver:

getStatus(callback: (status: LaserStatus) => void): void {
    this.client.readTuple(Command(this.id, this.cmds['get_status']), '?fff',
                            (tup: [boolean, number, number, number]) => {
        //...
        callback(status);
    });
}

See also

[email protected]