This interface is implemented by the terminal session object. You receive a session object either from ITerminalManager.sessions array, or through a call to ITerminalManager.createSession method.
interface ITerminalSession {
// Properties
${friendlyName}: string;
${portName}: string;
${config}: ${IDeviceConfig};
${rts}: boolean;
${dtr}: boolean;
readonly ${cts}: boolean;
readonly ${dsr}: boolean;
readonly ${dcd}: boolean;
readonly ${ring}: boolean;
readonly ${visible}: boolean;
// Methods
${xon}(): void;
${xoff}(): void;
${breakOn}(): void;
${breakOff}(): void;
${start}(): void;
${stop}(): void;
${send#send1}(text: string): Promise<void>;
${send#send2}(byte: number): Promise<void>;
${send#send3}(bytes: number [] | Uint8Array | Uint16Array | Uint32Array | ArrayBuffer | DataView): Promise<void>;
${sendAs}(sendAs: ${Terminal.SendAs}, data: number [] | Uint8Array | Uint16Array | Uint32Array | ArrayBuffer | DataView, bigEndian?: boolean): Promise<void>;
${sendFile}(fileName: string, byLines: boolean): Promise<void>;
${receive}(): Promise<Uint8Array>;
// Events
${sent}(handler: (data: Uint8Array) => void): number;
${sent}(eventId: number): void;
${received}(handler: (data: Uint8Array) => void): number;
${received}(eventId: number): void;
}
// This interface is not available in managed environment
// This interface is not available in native environment
friendlyName: string;
// This property is not available in managed environment
// This property is not available in native environment
The session friendly name.
portName: string;
// This property is not available in managed environment
// This property is not available in native environment
The property stores the so-called device interface string for a serial device. The device interface is one of the following:
config: ${IDeviceConfig};
// This property is not available in managed environment
// This property is not available in native environment
Get or set a terminal session configuration object. See IDeviceConfig interface for details. Any configuration object property may be omitted, in which case the system default value is used.
rts: boolean;
// This property is not available in managed environment
// This property is not available in native environment
Ready To Send signal state (RTS).
dtr: boolean;
// This property is not available in managed environment
// This property is not available in native environment
Data Terminal Ready signal state (DTR).
readonly cts: boolean;
// This property is not available in managed environment
// This property is not available in native environment
Clear To Send signal state (CTS). This property is read-only.
readonly dsr: boolean;
// This property is not available in managed environment
// This property is not available in native environment
Data Set Ready signal state (DSR). This property is read-only.
readonly dcd: boolean;
// This property is not available in managed environment
// This property is not available in native environment
Data Carrier Detect (DCD). This property is read-only.
readonly ring: boolean;
// This property is not available in managed environment
// This property is not available in native environment
Ring Indicator (RI). This property is read-only.
readonly visible: boolean;
// This property is not available in managed environment
// This property is not available in native environment
true
if this session is visible in UI, false
otherwise. This property is read-only.
xon(): void;
// This method is not available in managed environment
// This method is not available in native environment
Simulate that XON character received.
xoff(): void;
// This method is not available in managed environment
// This method is not available in native environment
Simulate that XOFF character received.
breakOn(): void;
// This method is not available in managed environment
// This method is not available in native environment
Simulate BREAK ON state.
breakOff(): void;
// This method is not available in managed environment
// This method is not available in native environment
Simulate BREAK OFF state.
start(): void;
// This method is not available in managed environment
// This method is not available in native environment
Start a terminal session.
stop(): void;
// This method is not available in managed environment
// This method is not available in native environment
Stop a terminal session. This will cause the opened handle to a serial device to be closed.
send(text: string): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
text
Send data to a terminal session. A given string is converted to ANSI and sent to the port.
send(byte: number): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
byte
Send a given byte to a terminal session.
send(bytes: number [] | Uint8Array | Uint16Array | Uint32Array | ArrayBuffer | DataView): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
bytes
Send a passed byte array to a terminal session.
sendAs(sendAs: ${Terminal.SendAs}, data: number [] | Uint8Array | Uint16Array | Uint32Array | ArrayBuffer | DataView, bigEndian?: boolean): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
sendAs
data
sendAs
parameter.bigEndian
boolean
parameter, which if passed and equals to true tells terminal session to use big-endian encoding for integers. Ignored for when sendAs
equals Terminal.SendAs.Bytes
. Equals false
if omitted.Send a number array to terminal session. First parameter tells how to interpret numbers in an array and the second parameter is a Javascript array of integer numbers.
Send data to the terminal session
await session.sendAs(Terminal.SendAs.Words, [ 0x4154, 0x440d ], true);
sendFile(fileName: string, byLines: boolean): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
fileName
byLines
true
, the file is analyzed and split into the lines. The lines are then sent to the serial terminal session. If this parameter is false
, the file is sent to the session byte by byte.Send contents of a file to the terminal session.
receive(): Promise<Uint8Array>;
// This method is not available in managed environment
// This method is not available in native environment
A promise object that produces a byte array when ready.
Receive (read) data from the terminal session.
Receive data from the terminal session
async function check(session)
{
await session.send("AT\n");
var response = await session.receive();
}
sent(handler: (data: Uint8Array) => void): number;
sent(eventId: number): void;
data
This event is fired when new data is sent to the serial device.
First overload is used to bind new handler to the event. It returns a numeric eventId
which then may be passed to second overload to unbind a handler.
Sample sent data handler for a text protocol.
var user_session = terminal.sessions[0];
var eventId = user_session.sent(function(data)
{
alert(data.length + " bytes sent to " + user_session.FriendlyName + ".\n");
});
// ...
// Unbind event handler when not needed anymore
user_session.sent(eventId);
received(handler: (data: Uint8Array) => void): number;
received(eventId: number): void;
data
This event is fired when new data is received from the serial device.
First overload is used to bind new handler to the event. It returns a numeric eventId
which then may be passed to second overload to unbind a handler.
Sample received data handler for a text protocol.
var user_session = terminal.sessions[0];
var eventId = user_session.received(function(data)
{
alert(data.length + " bytes received to " + user_session.FriendlyName + ".\n");
});
// ...
// Unbind event handler when not needed anymore
user_session.received(eventId);