?? umodbusclient.pas
字號:
unit uModBusClient;
interface
uses
Windows, SysUtils, Classes, SyncObjs;
const
mbUndefined = $FF;
mbReadCoils = 1;
mbReadDiscreteInputs = 2;
mbReadHoldingRegisters = 3;
mbReadInputRegisters = 4;
mbWriteMultipleCoils = 15;
mbWriteMultipleRegisters = 16;
mbeIllegalFunction = 1;
mbeIllegalDataAddress = 2;
mbeIllegalDataValue = 3;
mbeSlaveDeviceFailure = 4;
type
{
byte 0: identifier - copied by responder - usually 0
byte 1: identifier - copied by responder - usually 0
byte 2: protocol identifier = 0
byte 3: protocol identifier = 0
byte 4: length field (upper byte) = 0 (since all messages are smaller than 256)
byte 5: length field (lower byte) = number of bytes following
byte 6: unit identifier (previously 'slave address')
byte 7: MODBUS function code
byte 8 on: data as needed
}
Tmb_tcp_header = packed record
fTransactionID: word;
fProtocolID: word;
fRecLength: word;
end;
//The mb_req_pdu is defined as:
//mb_req_pdu = {function_code, request_data}, where
//function_code = [1 byte] MODBUS function code corresponding to the desired
//MODBUS function code or requested through the client API,
//request_data = [n bytes] This field is function code dependent and usually
//contains information such as variable references,
//variable counts, data offsets, sub-function codes etc.
Tmb_req_pdu = packed record
fUnitID: byte;
fFunctionCode: byte;
case byte of
mbReadCoils, mbReadDiscreteInputs, mbReadHoldingRegisters,
mbReadInputRegisters: (fReadStartAddr: word;
fReadQuantity: word);
mbWriteMultipleCoils: (fCoilsStartAddr: word;
fCoilQuantity: word;
fCount1: byte;
fOutCoilValues: TByteArray);
mbWriteMultipleRegisters: (fHoldStartAddr: word;
fRegisterQuantity: word;
fCount2: byte;
fOutRegisterValues: TWORDArray);
end;
//The mb_rsp_pdu is defined as:
//mb_rsp_pdu = {function_code, response_data}, where
//function_code = [1 byte] MODBUS function code
//response_data = [n bytes] This field is function code dependent and usually
//contains information such as variable references,
//variable counts, data offsets, sub-function codes, etc.
Tmb_rsp_pdu = packed record
fUnitID: byte;
fFunctionCode: byte;
case byte of
mbReadCoils, mbReadDiscreteInputs, mbReadHoldingRegisters,
mbReadInputRegisters: (fCount: byte;
fReadData: TByteArray);
mbWriteMultipleCoils,
mbWriteMultipleRegisters: (fStartAddr2: word;
fQuantity: word);
mbUndefined: (fExceptionCode: byte);
end;
//The mb_excep_rsp_pdu is defined as:
//mb_excep_rsp_pdu = {function_code, request_data}, where
//exception-function_code = [1 byte] MODBUS function code + 0x80
//exception_code = [1 byte] MODBUS Exception Code Defined in table
//"MODBUS Exception Codes" (see section 7 ).
Tmb_excep_rsp_pdu = packed record
fUnitID: byte;
fFunctionCode: byte;
fExceptionCode: byte;
end;
implementation
initialization
finalization
end.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -