SerialPort: thuộc tính writable

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Note: This feature is available in Dedicated Web Workers.

Thuộc tính chỉ đọc writable của giao diện SerialPort trả về một WritableStream để gửi dữ liệu tới thiết bị kết nối với cổng. Các đoạn dữ liệu ghi vào luồng này phải là các thực thể của ArrayBuffer, TypedArray, hoặc DataView. Thuộc tính này khác null miễn là cổng đang mở và chưa gặp lỗi nghiêm trọng.

Giá trị

Một WritableStream

Ví dụ

Ví dụ sau đây cho thấy cách ghi một chuỗi vào một cổng. Một TextEncoder chuyển đổi chuỗi thành Uint8Array trước khi truyền.

js
const encoder = new TextEncoder();
const writer = port.writable.getWriter();
await writer.write(encoder.encode("PING"));
writer.releaseLock();

Thông số kỹ thuật

Specification
Web Serial API
# dom-serialport-writable

Tương thích trình duyệt