"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class SerialPort {
    refid;
    eventEmitter;
    messagePrefix;
    postMessage;
    /** @internal */
    constructor(refid, eventEmitter, messagePrefix, postMessage) {
        this.refid = refid;
        this.eventEmitter = eventEmitter;
        this.messagePrefix = messagePrefix;
        this.postMessage = postMessage;
    }
    onData(listener) {
        this.eventEmitter.addListener('serial_port.data.' + this.refid, listener);
    }
    async write(data) {
        await this.postMessage({
            type: this.getMessage('serial_port.write'),
            refid: this.refid,
            data,
        });
    }
    async close() {
        await this.postMessage({
            type: this.getMessage('serial_port.close'),
            refid: this.refid,
        });
        this.eventEmitter.removeAllListeners('serial_port.data.' + this.refid);
    }
    getMessage(name) {
        return this.messagePrefix + '.' + name;
    }
}
exports.default = SerialPort;
//# sourceMappingURL=SerialPort.js.map