ModbusRTUCom

From AdvancedHMI
Revision as of 06:32, 14 August 2017 by Arj3090 (talk | contribs)
Jump to: navigation, search

ModbusRTUCom

This driver implements the common ModbusRTU protocol as used by many PLCs as well as other devices such as VFD, temperature controllers, servos, etc.

Properties
BaudRate The Baud Rate to match that of the device
DataBits The serial communication data bit length. Options are 7 or 8
EnableLogging Used as a troubleshooting tool only. When set to True, the driver will write all data bytes sent and received by the driver.
DisableSubscriptions uses updating of subscriptions. This is useful in cases such as when hiding a form and there is no longer a need to refresh the values. Or when used with a Trend Chart, it can pause the charting.
PollRateOverride This set the target rate for refreshing all of the subscriptions. When there are a large number of subscriptions that have to be split amongst sever requests, this value is divided by the number of requests required to determine the delay between each packet. A value of 0 will make the driver update as fast as the PLC will respond, but be cautious because it can reach rates less than 5ms and start to use a lot of resources.
INIFileName An INI file can be created to store the properties for being set during application startup. See INI File Usage for more details
INIFileSection Specifies the section within the INI file to use for this driver instance settings
MaxReadGroupSize When using subscriptions, the driver will optimize communications by grouping multiple subscriptions into a single read.
The MaxReadGroupSize determines the largest number of registers to read in a single request.


Methods

For the methods common to all drivers see the section on the IComComponent

No driver specific methods exist.

Addressing

This driver uses the common Modbus addressing scheme. The first digit determines the address space (function codes) to use. The remaining digits determine the offset. The address offset starts at 1, therefore to access register 0, you must use 1.

40001


Forcing function code can be done as follows:

3:0001


Double integers can be read by telling the driver to combine 2 registers by using a prefix "L". For example:

L40001

Note that since 2 registers are used, the register numbers will be every other number, such as L40001, L40003, L40005


Floating point values are read using a prefix "F". For example:

F40001

As with double integers, floating point value also require 2 registers, therefore the register numbers must use every other register such as F40001, F40003, F40005

Function code to first address digit relationship:

                        Case 0 : m_ReadFunctionCode = 1                             WriteSingleFunctionCode = 5                             WriteMultiFunctionCode = 15                             m_BitsPerElement = 1                         Case 1 : m_ReadFunctionCode = 2                             WriteMultiFunctionCode = 0 '* Invalid                             m_BitsPerElement = 1                         Case 3 : m_ReadFunctionCode = 4                             WriteMultiFunctionCode = 0                             m_Element = CInt(Address.Substring(1)) - 1                             m_BitsPerElement = 16                         Case 4 : m_ReadFunctionCode = 3                             WriteSingleFunctionCode = 6                             WriteMultiFunctionCode = 16                             m_Element = CInt(Address.Substring(1)) - 1

Code Samples

Dim MyDriver as ModbusRTUCom