This interface is implemented by the MODBUS Builder Object. You create an instance of this object by calling the IModbusManager.createBuilder method.
Please consult the MODBUS protocol documentation for term definitions.
interface IModbusBuilder {
// Methods
${error}(functionID: number, exceptionCode: number): Uint8Array;
${requestDiagnostics}(subfunction: number, data: number): Uint8Array;
${requestGetCommEventCounter}(): Uint8Array;
${requestGetCommEventLog}(): Uint8Array;
${requestMaskWriteRegister}(referenceAddress: number, andMask: number, orMask: number): Uint8Array;
${requestReadCoils}(startingAddress: number, numberOfCoils: number): Uint8Array;
${requestReadDiscreteInputs}(startingAddress: number, numberOfInputs: number): Uint8Array;
${requestReadExceptionStatus}(): Uint8Array;
${requestReadFIFOQueue}(fifoPointerAddress: number): Uint8Array;
${requestReadFileRecord}(requests: ${ReadFileRequest}[]): Uint8Array;
${requestReadHoldingRegisters}(startingAddress: number, numberOfRegisters: number): Uint8Array;
${requestReadInputRegisters}(startingAddress: number, numberOfRegisters: number): Uint8Array;
${requestReadWriteMultipleRegisters}(readStartingAddress: number,
numberToRead: number,
writeStartingAddress: number,
data: number [] | Uint16Array): Uint8Array;
${requestReportSlaveID}(): Uint8Array;
${requestUserFunction}(functionID: number, data: number[] | Uint8Array): Uint8Array;
${requestWriteFileRecord}(requests: ${FileRecord}[]): Uint8Array;
${requestWriteMultipleCoils}(startingAddress: number, data: boolean[]): Uint8Array;
${requestWriteMultipleRegisters}(startingAddress: number, data: number[] | Uint16Array): Uint8Array;
${requestWriteSingleCoil}(outputAddress: number, outputValue: number): Uint8Array;
${requestWriteSingleRegister}(registerAddress: number, registerValue: number): Uint8Array;
${responseDiagnostics}(subFunction: number, data: number [] | Uint8Array): Uint8Array;
${responseGetCommEventCounter}(status: number, eventCount: number): Uint8Array;
${responseGetCommEventLog}(status: number, events: number [] | Uint8Array): Uint8Array;
${responseMaskWriteRegister}(referenceAddress: number, andMask: number, orMask: number): Uint8Array;
${responseReadCoilStatus}(items: number [] | Uint8Array): Uint8Array;
${responseReadDiscreteInputs}(items: number [] | Uint8Array): Uint8Array;
${responseReadExceptionStatus}(outputData: number): Uint8Array;
${responseReadFIFOQueue}(registers: number [] | Uint16Array): Uint8Array;
${responseReadFileRecord}(requests: ${ReadFileResponse}[]): Uint8Array;
${responseReadHoldingRegisters}(registers: number [] | Uint16Array): Uint8Array;
${responseReadInputRegisters}(registers: number [] | Uint16Array): Uint8Array;
${responseReadWriteRegisters}(registers: number [] | Uint16Array): Uint8Array;
${responseReportSlaveID}(runIndicatorStatus: number,
slaveIds: number [] | Uint8Array,
data: number [] | Uint8Array): Uint8Array;
${responseWriteFileRecord}(requests: ${FileRecord}[]): Uint8Array;
${responseWriteMultipleCoils}(startingAddress: number, quantityOfOutputs: number): Uint8Array;
${responseWriteMultipleRegisters}(startingAddress: number, quantityOfRegisters: number): Uint8Array;
${responseWriteSingleCoil}(outputAddress: number, outputValue: number): Uint8Array;
${responseWriteSingleRegister}(outRegisterAddress: number, outValue: number): Uint8Array;
}
// This interface is not available in managed environment
// This interface is not available in native environment
error(functionID: number, exceptionCode: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
functionID
exceptionCode
Construct the error response.
var message = builder.error(1, 20);
requestDiagnostics(subfunction: number, data: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
subfunction
data
Send the Diagnostics (see MODBUS protocol documentation) request to the selected device.
var message = builder.requestDiagnostics(1, 65535);
requestGetCommEventCounter(): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
Construct the Get Comm Event Counter request.
var message = builder.requestGetCommEventCounter();
requestGetCommEventLog(): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
Construct the Get Comm Event Log request.
requestMaskWriteRegister(referenceAddress: number, andMask: number, orMask: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
referenceAddress
andMask
orMask
Construct the Mask Write Register request.
requestReadCoils(startingAddress: number, numberOfCoils: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
startingAddress
numberOfCoils
Construct the Read Coils request.
requestReadDiscreteInputs(startingAddress: number, numberOfInputs: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
startingAddress
numberOfInputs
Construct the Read Discrete Inputs request.
requestReadExceptionStatus(): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
Construct the Read Exception Status request.
requestReadFIFOQueue(fifoPointerAddress: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
fifoPointerAddress
Construct the Read FIFO Queue request.
requestReadFileRecord(requests: ${ReadFileRequest}[]): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
requests
Construct the Read File Record request.
var message = builder.requestReadFileRecord([
{ referenceType: 1, fileNumber: 10, recordNumber: 20, registerLength: 30 }
]); // 1 request with refernce type 1 and 10 as file number value
var message = builder.requestReadFileRecord([
{ referenceType: 1, fileNumber: 10, recordNumber: 20, registerLength: 30 },
{ referenceType: 1, fileNumber: 11, recordNumber: 21, registerLength: 31 }
]); // 2 requests: first with 20 as the Record Number value; second with 21 as the Record Number value
requestReadHoldingRegisters(startingAddress: number, numberOfRegisters: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
startingAddress
numberOfRegisters
Construct the Read Holding Registers request.
requestReadInputRegisters(startingAddress: number, numberOfRegisters: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
startingAddress
numberOfRegisters
Construct the Read Input Registers request.
requestReadWriteMultipleRegisters(readStartingAddress: number,
numberToRead: number,
writeStartingAddress: number,
data: number [] | Uint16Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
readStartingAddress
numberToRead
writeStartingAddress
data
Construct the Read Write Multiple Registers request.
The function throws an exception if you specify incorrect values for the data
parameter. The function also throws an exception if there is too many or too little values, as well as if the total length of the packet exceeds 255 bytes.
var message1 = builder.requestReadWriteMultipleRegisters(1, 2, 30, [ 32500 ]); // only one value is written
var message2 = builder.requestReadWriteMultipleRegisters(1, 2, 30, [ 32500, 32000, 65535, 65535, 65535 ]); // 5 values are written
requestReportSlaveID(): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
Construct the Report SlaveID request.
requestUserFunction(functionID: number, data: number[] | Uint8Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
functionID
data
Construct the user-defined message to the device.
var message = builder.requestUserFunction(15, [ 1, 2, 3, 4, 5, 6, 7 ]); // User function 15 with 7 parameters
requestWriteFileRecord(requests: ${FileRecord}[]): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
requests
Construct the Write File Record request.
var message = builder.requestWriteFileRecord([
{ referencyType: 1, fileNumber: 10, recordNumber: 20, records: [ 255 ] },
{ referencyType: 1, fileNumber: 10, recordNumber: 20, records: [ 255, 255 ] },
{ referencyType: 1, fileNumber: 11, recordNumber: 21, records: [ 127, 127, 127] }
]);
requestWriteMultipleCoils(startingAddress: number, data: boolean[]): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
startingAddress
data
Construct the Write Multiple Coils request.
requestWriteMultipleRegisters(startingAddress: number, data: number[] | Uint16Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
startingAddress
data
Construct the Write Multiple Registers request.
requestWriteSingleCoil(outputAddress: number, outputValue: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
outputAddress
outputValue
Construct the Write Single Coil request .
var m1 = builder.requestWriteSingleCoil(0, 65280); // set the 1 (TRUE) value to coil 0
var m2 = builder.requestWriteSingleCoil(1, 0); // set the 0 (FALSE) value to coil 1
var m3 = builder.requestWriteSingleCoil(2, 15); // WARNING: the value 15 is undefined by standard.
// coil #2 will have unknown value now (FALSE or TRUE)
requestWriteSingleRegister(registerAddress: number, registerValue: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
registerAddress
registerValue
Construct the Write Single Register request.
responseDiagnostics(subFunction: number, data: number [] | Uint8Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
subFunction
data
Send the Diagnostics response.
The function throws an exception if you specify incorrect values for the data
parameter. The function also throws an exception if the total length of the packet exceeds 255 bytes.
responseGetCommEventCounter(status: number, eventCount: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
status
eventCount
Construct the Get Comm Event Counter response.
responseGetCommEventLog(status: number, events: number [] | Uint8Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
status
events
Construct the Get Comm Event Log response.
responseMaskWriteRegister(referenceAddress: number, andMask: number, orMask: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
referenceAddress
andMask
orMask
Construct the Mask Write Register response.
responseReadCoilStatus(items: number [] | Uint8Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
items
Construct the Read Coil Status response.
responseReadDiscreteInputs(items: number [] | Uint8Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
items
Construct the Read Discrete Inputs response.
responseReadExceptionStatus(outputData: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
outputData
Construct the Read Exception Status response.
responseReadFIFOQueue(registers: number [] | Uint16Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
registers
Send the Read FIFO Queue response.
The function throws an exception if you specify incorrect values for the registers
parameter. The function also throws an exception if the total length of the packet exceeds 255 bytes.
responseReadFileRecord(requests: ${ReadFileResponse}[]): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
requests
Construct the Read File Record response.
var message = builder.responseReadFileRecord([
{ referenceType: 6, data: [ 255 ] },
{ referenceType: 6, data: [ 65535, 65535 ] },
{ referenceType: 6, data: [ 120 ] }
]);
responseReadHoldingRegisters(registers: number [] | Uint16Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
registers
Construct the Read Holding Registers response.
The function throws an exception if you specify incorrect values for the registers
parameter. The function also throws an exception if the total length of the packet exceeds 255 bytes.
responseReadInputRegisters(registers: number [] | Uint16Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
registers
Construct the Read Input Registers response.
The function throws an exception if you specify incorrect values for the registers
parameter. The function also throws an exception if the total length of the packet exceeds 255 bytes.
responseReadWriteRegisters(registers: number [] | Uint16Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
registers
Construct the Read Write Registers response.
responseReportSlaveID(runIndicatorStatus: number,
slaveIds: number [] | Uint8Array,
data: number [] | Uint8Array): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
runIndicatorStatus
slaveIds
data
Construct the Report SlaveID response.
The function throws an exception if you specify incorrect values for the requests
parameter. The function also throws an exception if there is too many or too little values, as well as if the total length of the packet exceeds 255 bytes.
// send 1 byte (255 in this example) as SlaveId field data
// and 2 bytes (255,100 in this example) as AdditionalData field data
// RunIndicatorStatus field is 0
var message = builder.responseReportSlaveID(0, [ 255 ], [ 255, 100 ]);
responseWriteFileRecord(requests: ${FileRecord}[]): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
requests
Construct the Write File Record response.
var message = builder.responseWriteFileRecord([
{ referenceType: 1, fileNumber: 2, recordNumber: 1, records: [ 65535 ] }, // first request (with 1 record data value)
{ referenceType: 1, fileNumber: 40000, recordNumber: 2, records: [ 65535, 65535, 65535 ] }, // second request (with 3 record data values)
{ referenceType: 1, fileNumber: 2, recordNumber: 3, records: [ 120 ] } // third request (with 1 record data value)
]);
responseWriteMultipleCoils(startingAddress: number, quantityOfOutputs: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
startingAddress
quantityOfOutputs
Construct the Write Multiple Coils response.
responseWriteMultipleRegisters(startingAddress: number, quantityOfRegisters: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
startingAddress
quantityOfRegisters
Construct the Write Multiple Registers response.
responseWriteSingleCoil(outputAddress: number, outputValue: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
outputAddress
outputValue
Construct the Write Single Coil response.
responseWriteSingleRegister(outRegisterAddress: number, outValue: number): Uint8Array;
// This method is not available in managed environment
// This method is not available in native environment
outRegisterAddress
outValue
Construct the Write Single Register response.