# ModBusSlave
| Valid For | #Open_Serial |
|---|---|
| Applies To | All |
This instruction opens a serial port for use as a MODBUS slave.
Function Prototype
#Open_Serial Port(PortNumber) ModbusSlave(
BaudRate,
Parity,
SlaveAddress,
MessageGap
{,
RAMUnprotectedStart,
RAMUnprotectedEnd,
OutputUnprotectedStart,
OutputUnprotectedEnd
}
)
"{}" denotes optional.
| Parameter | Option | Description |
|---|---|---|
| BaudRate | mandatory | The baudrate to be used. Legal values are 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, (230400, 460800)* |
| Parity | mandatory | May be either:n = noneo = odde = even |
| SlaveAddress | mandatory | The ModBus slave address of the SPLat controller. Legal values are 1 through 247. May be changed later via ComDevAddr. |
| MessageGap | mandatory | See description here. Set to 0 for the default. |
| RAMUnprotectedStart | optional | Starting RAM address where master writes are permitted. Any attempt by the master to write before this address will be denied. Default is 255. |
| RAMUnprotectedEnd | optional | Ending RAM address where master writes are permitted. Any attempt by the master to write after this address will be denied. Default is 255. |
| OutputUnprotectedStart | optional | Starting output number where master writes are permitted. Any attempt by the master to write before this address will be denied. Default is 255. |
| OutputUnprotectedEnd | optional | Ending output number where master writes are permitted. Any attempt by the master to write after this address will be denied. Default is 255. |
Description
This hash function sets the serial port up for use with the ModBusRTU slave. Once initiated and configured, the SPLat controller Firmware takes care of all the low level communications activity. ModBus documentation.
You should set these to match the device you are communicating with.
Port() is only available on SPLat 32 bit controllers (black boards).
Note that 32-bit controllers allow use of Modbus on multiple ports. It has been successfully tried with Master mode on one port and Slave mode on another.
*The (high speed baud rates) are only available on SPLat 32 bit controllers (black boards).
Unprotected Area
RAM and Output write protection is only available on SPLat 32 bit controllers. It provides a mechanism of ensuring a Modbus Master cannot write to RAM or Outputs that the slave wishes to protect. Both RAM and Output protection follow these conditions:
- Start & End = 255.
All writes are denied. This is the default. - Start & End = 0.
All writes are permiteed. Be careful! - All other values mark the start and end, inclusive. So if start =100 and end = 115, then 100, 101, …, 114 & 115 are all permitted.
If any part of a Modbus Master WriteMultipleCoils or WriteMultipleRegisters command lies within the protected area, then the whole command will be rejected.
Examples
COM0 EQU 252 ;the TTL serial port
#Open_Serial Port( COM0 ) ModbusSlave( 38400, n, 10, 0, 0, 255, 255, 255 )
Use COM0 as a MODBUS Slave port, permit write to all RAM, block writes to all outputs.