SPLat Logo

ModBus Master control script commands

NOTICE: Our web site is being updated, but is currently experiencing extreme slowness due to host issues. Please contact us directly.
NOTICE: SPLat Controls has moved. We are now at 1/85 Brunel Rd, Seaford, 3198. map
SPLat will be shut down for the Christmas Holiday season from Friday 20 December 2024 through Tuesday 7 January 2025. We will check emails periodically and will continue to process orders but at a slower pace. Santa hat

ModBus Master control script commands

ModBus tutorial

ModBus script commands are stored as table entries in NVEM page 0. In the following pages, each function consists of a 1-byte numeric value followed by 0 to several parameters.

Here are a list of equates in SPLat format:


;--MODBUS function codes
MBkFunc_ReadCoils EQU 1 ;ReadCoils, SlaveAddr, #SrcAddr, ItemCount, #SPLatRAM16
MBkFunc_ReadDiscreteInputs EQU 2 ;ReadInputs, SlaveAddr, #SrcAddr, ItemCount, #SPLatRAM16
MBkFunc_ReadHoldingRegisters EQU 3 ;ReadHReg, SlaveAddr, #SrcAddr, ItemCount, #SPLatRAM16, NumFormat
MBkFunc_ReadInputRegisters EQU 4 ;ReadInputs, SlaveAddr, #SrcAddr, ItemCount, #SPLatRAM16, NumFormat
MBkFunc_WriteSingleCoil EQU 5 ;WriteCoil, SlaveAddr, #DstAddr, #SPLatRAM16
MBkFunc_WriteSingleRegister EQU 6 ;WriteHReg, SlaveAddr, #DstAddr, #SPLatRAM16, NumFormat
MBkFunc_WriteMultipleCoils EQU 15 ;WriteCoils, SlaveAddr, #DstAddr, ItemCount, #SPLatRAM16
MBkFunc_WriteMultipleRegisters EQU 16 ;WriteMultReg, SlaveAddr, #DstAddr, ItemCount, #SPLatRAM16, NumFormat
MBkFunc_Goto EQU 128 ;Goto NV0Ptr Addr
MBkFunc_Stop EQU 129 ;Stop
MBkFunc_Delay EQU 130 ;Delay, 10msTicks (0 - 255)
;--MODBUS number format codes
;for float labels, this is what the letters mean A=31:24, B=23:16, C=15:8, D=7:0
MBkFormat_Byte EQU 0 ;only save LSB of big endian register (hence save the second byte) (standard)
MBkFormat_Word EQU 1 ;16 bit big endian
MBkFormat_ByteLE EQU 2 ;byte, little endian (non-standard)
MBkFormat_WordLE EQU 3 ;word, little endian (non-standard)
MBkFormat_FloatABCD EQU 4 ;big endian
MBkFormat_FloatBADC EQU 5 ;big endian, byte swapped
MBkFormat_FloatDCBA EQU 6 ;little endian
MBkFormat_FloatCDAB EQU 7 ;little endian byte swapped (Modicon and Wonderware standard)

And an example of usage


#Open_Serial Port( COM0 ) MODBUSMaster( 38400, n, 0, 50 )
COMRunScript pMODBUSScript
<your application code>


NVEM0 ;Start of non-volatile memory

pMODBUSScript
NV0Byte MBkFunc_ReadCoils, 0, #160, 8, #asCoils

NV0Byte MBkFunc_WriteSingleCoil, 0, #1008, #sSingleCoil

NV0Byte MBkFunc_ReadHoldingRegisters, 0, #100, 1, #wCount, MBkFormat_Word

NV0Byte MBkFunc_ReadHoldingRegisters, 0, #103, 6, #fCount, MBkFormat_Word

NV0Byte MBkFunc_WriteSingleRegister, 0, #115, #wCount, MBkFormat_Word

NV0Byte MBkFunc_WriteMultipleRegisters, 0, #117, 6, #fCountIEEE_BER, MBkFormat_FloatCDAB

NV0Byte MBkFunc_Delay,10

NV0Byte MBkFunc_Goto
NV0Ptr pMODBUSScript