WinTECH Software Industrial Automation Suite of Applications for the Windows O.S. I. Introduction A. Purpose of this manual B. Software Distribution Method C. Basic Software License D. How to contact WinTECH Software II. The Modbus Protocol A. Message Formatting B. Error Detection C. modbus/TCP extensions III. Software Descriptions A. Application Overviews B. ModScan C. ModSim D. MNetSvr E. MNetMon F. Modbus Master ActiveX Control G. Modbus Slave ActiveX Control IV.
Purpose of this manual This manual represents a composite technical description of the applications offered by WinTECH Software to support data acquisition and manipulation using the modbus communications protocol. Topics covered include the distribution and licensing methods utilized to market the software as well as detailed user’s manuals for each application.
Software Distribution Method The WinTECH Software suite of Industrial Automation products is distributed primarily via the internet. Fully-functional demo applications are available from the following Web-Site: http://www.win-tech.com Each software application may be downloaded for evaluation and freely distributed among potential users without cost or obligation. Each application is in some fashion time-limited, allowing free and unrestricted use for a pre-defined period of time.
WinTECH Software License Agreement YOU SHOULD CAREFULLY READ THE FOLLOWING TERMS AND CONDITIONS BEFORE USING THE ACCESS CODES SUPPLIED HEREIN. USING THE SUPPLIED ACCESS CODES TO REGISTER A WINTECH SOFTWARE APPLICATION INDICATES YOUR ACCEPTANCE OF THESE TERMS AND CONDITIONS. IF YOU DO NOT AGREE WITH THEM, YOU SHOULD PROMPTLY RETURN THE ACCESS CODES TO WINTECH SOFTWARE WITHIN FIFTEEN DAYS OF ACQUISITION AND THE REGISTRATION LICENSE FEE PAID WILL BE REFUNDED.
LIMITED WARRANTY During the first 90 days after delivery of the Access Codes to you, as evidenced by a copy of your receipt, invoice or other proof of purchase, (the “Warranty Period”), WinTECH Software warrants that the Application will perform substantially in accordance with the Documentation and that the diskettes on which the Applications are furnished, (if supplied), are free from defects in materials and workmanship under normal use.
How to contact WinTECH Software The most expediant method for contacting WinTECH Software is via e-mail using the following addresses: Sales support: sales@win-tech.com Technical support: support@win-tech.com WinTECH Software is located in the Eastern Time Zone of the United States and may be reached via phone or fax at the following number: (304) 645-5966 The postal address is: WinTECH Software P.O.
Modbus Message Formatting The MODBUS protocol describes an industrial communications and distributed control system developed by Gould-Modicon to integrate PLC’s, computers, terminals, and other monitoring, sensing, and control devices. MODBUS is a Master/Slave communications protocol, whereby one device, (the Master), controls all serial activity by selectively polling one or more slave devices. The protocol provides for one master device and up to 247 slave devices on a common line.
message. The ASCII mode uses twice as many characters as the RTU mode, but decoding handling the ASCII data is easier. Additionally, in the RTU mode, message characters must be transmitted in a continuous stream. In the ASCII mode, breaks of up to one second can occur between characters to allow for a relatively slower master. Error Detection There are two types of errors which may occur in a communications system: transmission errors and programming errors.
The step by step procedure to form the CRC-16 is as follows: Load a 16-bit register with all 1’s. 1. 2. Exclusive OR the first 8-bit byte with the high order byte of the 16-bit register, putting the result in the 16-bit register. 3. Shift the 16-bit register one bit to the right. 4a. If the bit shifted out to the right is one, exclusive OR the generating polynomial 1010 0000 0000 0001 with the 16-bit register. 4b. If the bit shifted out to the right is zero; return to step 3. 5.
Shift 1 Polynomial 0100 1010 0000 0000 1001 0000 1100 0001 Shift 2 Polynomial 1110 0111 1010 0000 0000 0000 1001 0100 0000 1101 1110 0001 1 Shift 3 Polynommial 1101 0110 1010 0000 1000 0000 0010 0010 0000 1111 0111 0001 1 Shift 4 Shift 5 Polynomial 1100 0110 0011 1010 1000 0100 0010 0000 0010 0001 0000 0000 0110 0011 1001 0001 0 1 Shift 6 Shift 7 Shift 8 1001 0100 0010 0001 0010 1001 0100 0010 0000 0000 1000 0100 1000 0100 0010 0001 HEX 12 HEX 41 TRANSMITTED MESSAGE WITH CRC-16
LRC (Longitudinal Redundancy Check) The error check sequence for the ASCII mode is LRC. The error check is an 8-bit binary number represented and transmitted as two ASCII hexadecimal (hex) characters. The error check is produced by converting the hex characters to binary, adding the binary characters without wraparound carry, and two’s complementing the result. At the received end the LRC is recalculated and compared to the sent LRC.
MODBUS Message Types ASCII Framing Framing in ASCII Transmission mode is accomplished by the use of the unique colon, (:), character to indicate the beginning of frame and carriage return/line feed, (CRLF), to delineate end of frame. The line feed character also serves as a synchronizing character which indicates that the transmitting station is ready to receive an immediate reply.
Function Field The Function Code field tells the addressed slave what function to perform. MODBUS function codes are specifically designed for interacting with a PLC on the MODBUS industrial communications system. The high order bit in this field is set by the slave device to indicate an exception condition in the response message. If no exceptions exist, the high-order bit is maintained as zero in the response message.
Exception Responses Programming or operation errors are those involving illegal data in a message, no response from the PLC to its interface unit, or difficulty in communicating with a slave. These errors result in an exception response from either the master computer software or the PLC slave, depending on the type of error. The exception response codes are listed below.
READ OUTPUT STATUS (FUNCTION CODE 01) This function allows the user to obtain the ON/OFF status of logic coils used to control discrete outputs from the addressed slave only. Broadcast mode is not supported with this function code. In addition to the slave address and function fields, the message requires that the information field contain the initial coil address to be read, (Starting Address), and the number of locations that will be interrogated to obtain status data.
READ INPUT STATUS (FUNCTION CODE 02) This function allows the user to obtain the ON/OFF status of discrete inputs in the addressed slave. Broadcast mode is not supported. In addition to the slave address and function code fields, this message requires that the information field contain the initial input address to be read, (Starting Address) and the number of locations that will be interrogated to obtain the status data.
READ OUTPUT REGISTERS (FUNCTION CODE 03) Read Output Registers allows the user to obtain the binary contents of holding registers in the addressed slave. These registers can store the numerical values of associated timers and counters which can be driven to external devices. The addressing allows up to 125 registers to be obtained at each request; however, the specified slave device may have restrictions that lower this maximum quantity. The registers are numbered from zero, broadcast mode is not allowed.
READ INPUT REGISTERS (FUNCTION CODE 04) Function Code 04 obtains the contents of the controllers input registers. These locations receive their vales from devices connected to the I/O structure and can only be referenced, not altered from within the controller nor via MODBUS. The example below requests the contents of register 30009 in slave number 17.
FORCE SINGLE COIL (FUNCTION CODE 05) This message forces a single coil either On of OFF. Any coil that exists within the controller can be forced to either state, (ON or OFF). Coils are numbered from zero (i.e. coil 1 is address 0000, coil 2 is address 0001, etc.). The data value 65,280, (FF00 HEX) will set the coil ON and the value zero will turn it off. All other values are illegal and will not effect the coil.
PRESET SINGLE REGISTER (FUNCTION CODE 06) Function 06 allows the user to modify the contents of a holding register. Any holding register that exists within the controller can have its contents changed by this message. The values are provided in binary up to the maximum capacity of the controller. Unused high-order bits must be set to zero. When used with slave address 00, all slave controllers will load the specified register with the contents specified.
FORCE MULTIPLE COILS (FUNCTION CODE 15) Function 15 allows the user to modify the contents of a group of consecutively addressed coils. The following example forces 10 coils starting at address 20, (13 HEX). The two data fields, CD = 1100 1101 and 00 = 0000 0000, indicate that coils 27, 26, 23, 22 and 20 are to be forced on. ADDR 11 FUN C 0F H.O. ADDR 00 L.O.
PRESET MULTIPLE REGISTERS (FUNCTION CODE 16) Holding registers existing within the controller can have their contents changed via function code 16. Sixteen bits of data for each register is contained within the message. ADDR 11 FUN C 10 H.O. ADDR 00 L.O. ADDR 87 QUANTITY 00 BYTE CNT 02 04 H.O. DATA L.O. DATA 00 0A etc.
modbus/TCP Extensions The Modbus Applications Programming Interface for Network Communications, (MBAP), was developed by Modicon to allow traditional serial modbus communiactions to occur over a TCP/IP network. It basically defines a “wrapper” around the modbus protocol to accomidate routing data packets between two network nodes.
WinTECH Software Application Overviews The WinTECH Software suite of applications for Industrial Automation was designed to provide a costeffective solution to interface data from modbus devices into the PC Windows environment. Without the overhead associated with a full featured MMI, these products provide an easy to use interface to remote devices.
MNetMon MNetMon is a Win32 Application designed to unintrusively monitor an active modbus communications link by tapping into the RS-232 Transmit signals via two separate PC comm ports. As MNetMon recognizes data passed between the master and slave devices, it mirrows the data points to a local database, and makes this data accessible to other network devices operating as modbus/TCP clients.
ModScan Following is a concise user’s manual for the operation of ModScan32. Operation of the 16-bit version of ModScan is similar, but is not detailed in this document. I. Application Overview A. Document/View Architecture B. Modbus Data Definition C. Display Formats D. Connections II. Commands A. File Menu B. Connection Menu C. Setup Menu 1. Commands 2. Display Options 3. Extended Options D. View Menu 1. Commands 2. Config Menu E. Window Menu F. Help Menu III. Toolbars & Status Bar A. Toolbar B.
ModScan Overview The ModScan application operates as a MODBUS master device in either RTU or ASCII transmission modes. ModScan may be used to access and modify data points contained in one or more MODBUS slave devices connected to the PC via a serial port, modem, or network. ModScan supports the standard MODBUS message types 01-06, 15 & 16, as well as providing the ability for you to exercise special features of a slave device by transmitting custom command strings and observing the response.
Display Formats As data is received from the slave device, it is displayed to the lower splitter view of the associated document. Any errors incurred during the exchange of information will be displayed on the first line. The font and colors used to display the data is configurable via the View, Config menu options.
File Menu The File menu offers the following commands: New Creates a new document. Use this command to create a new document in ModScan. Each document represents a different block of data from a modbus device. Open Opens an existing document. Use this command to open an existing document in a new window. You can open multiple documents at once. Use the Window menu to switch among the multiple open documents. Custom This command allows you to open/create a Custom Display document.
Connection Menu The Connect menu offers the following commands: Connect Attaches the ModScan application to a modbus network, enabling data collection. Use this command to connect the ModScan application to a modbus network. A dialog box will prompt you for information relative to the connection. You may use ModScan to connect directly to a modbus device via one of four Windows COM ports, or via a modem or TCP/IP network.
Display Options The Display Options menu offers the following commands: Show Data This default view configuration displays data values as obtained from the modbus slave device. ModScan is normally configured to display modbus data points in the lower splitter view of the associated document. Data points are displayed in order from top to bottom, left to right. Data is displayed using the current colors and font selection. Coil values are displayed as either <0> or <1>.
ModScan will attempt to convert the values contained within the selected registers as the IEEE value. If the bit pattern contained within the register set matches the criteria for a floating point number, the value will be displayed on the lower document splitter view as a decimal value associated with the first register address of the pair. Swapped Dbl Register Values are displayed in floating point notation, (least significant register first).
Extended Options The Setup Extended Options menu offers the following commands: Force Coils Provides the ability to write coil values to a designated slave device. Use this command to manually force a group of coils to a given state, (on/off). The ability to address multiple coils in a slave depends upon the operating characteristics of the device. ModScan uses modbus message 15, (Force Multiple Coils), to transmit the request to the designated slave.
The View menu offers the following commands: Toolbar Shows or hides the toolbar. Status Bar Shows or hides the status bar. Display Bar Shows or hides the format toolbar used to select the display format for modbus registers. Config Allows you to customize the appearance of ModScan by selecting the colors and font used. Config Menu The config options supported under the View menu offers you the ability to select the colors used to display modbus data as well as the character font.
Tollbars & Status Bar Toolbar The toolbar is displayed across the top of the application window, below the menu bar. The toolbar provides quick mouse access to many tools used in ModScan. The toolbar is detachable and dockable by clicking the mouse on the toolbar background and dragging it to the desired location within the ModScan application window. To hide or display the Toolbar, choose Toolbar from the View menu (ALT, V, T). Toolbar buttons, (from left to right), allow you to: Open a new document.
Display registers in double-precision floating point, (interpreted as having the least significant 16-bits in the first register). Status Bar The status bar is displayed at the bottom of the ModScan window. To display or hide the status bar, use the Status Bar command in the View menu. The left area of the status bar describes actions of menu items as you use the arrow keys to navigate through menus.
Testing Features Writing Data In order to write a MODBUS data point in a slave device, the communications with the device must first be initiated by scanning a series of data points by configuring the correct addressing information and initiating a polling cycle. Once the data is successfully displayed, double-clicking the address/value portion of the screen will initiate a dialog box which allows the value to be changed.
User Defined Messsages Use this command to customize a command string for transmission to a designated modbus slave device. This command is useful for observing the slave response to non-standard modbus queries or to test its reaction to requests for data which may not be available. The slave device should respond with the proper exception message if a master device asks for data which is beyond its address range or otherwise unavailable via the modbus.
// ignore the data and only verify proper quantity returned // Verify Input Status,1,2,100,100,0,D // // // Forth Test: // Check Slave Response to request for 1000 registers // (Should probably generate an exception response) // Test Exception 2,1,3,100,1000,0,2 // // Fifth Test: // Check Slave Response to bad CRC // Invalid Request,1,1,100,1,0,C // // Sixth Test: // Query an unknown device & expect no response // Query Device 73,73,1,1,1,0,R // // Seventh Test: // Write 6 Holding Registers with data // (Ea
Database Operation An optional feature of ModScan32 allows you to write data directly into a Microsoft compatible database such as Access. ModScan uses the Jet database engine to provide an efficient exchange of information from an addressed slave device into the designated database table. Selecting the Dbase Capture menu item allows you to associate a ModScan document with a given database table. The table will then be updated with new data each time the slave device is polled.
OLE Automation An optional feature of ModScan32 is the ability to access modbus data using OLE Automation routines. This allows custom programs to be generated, (using Visual Basic, Excel Basic, etc.,), to interpret and format data according to your specific requirements. OLE Automation routines provide both read and write access to one or more modbus slave devices through the ModScan application. Using the OLE Automation routines is a very simple process: The VBA application links to the ModScan32.
Status - indicates whether or not the operation was completed successfully Notes: Status will be MBUS_OK, (0), if the data point was successfully read, otherwise, a non-zero value indicates one of the defined error conditions. short WriteValue (short PointHandle, short Index, short Value) Arguments: Point Handle - refers to value returned from CreatePollRequest Index - Specifies the index into the array structure Value - is the data to be written.
ModScan OLE Automation Error Return Values The following status codes may be returned from the ModScan application in response to an OLE Automation request: 1-255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 Modbus Exception Message as returned from slave device.
Visual Basic Example The example Visual Basic application included with the ModScan32 distribution files is a simple take-off on the ModScan application itself. The Form creates four array points, (one each for inputs, coils, input registers, and holding registers). A timer is used to read and update the data once per second.
Modbus_Addr = Modbus_Id(3) + StartAddress(3) temp = m_svr.ModifyPollRequest(PollHandle(3), SlaveDevice, Modbus_Addr, 10) End If End Sub Private Sub Form_Load() ‘ ‘ Create the ModScan interface object ‘ Set m_svr = CreateObject("ModScan32.
If Index = 259 Then statusline = "Invalid Device Address" If Index = 260 Then statusline = "Invalid Length Specification" If Index = 261 Then statusline = "Invalid modbus command" If Index = 262 Then statusline = "Driver Out-Of-Memory" If Index = 263 Then statusline = "** Time-Out **" If Index = 264 Then statusline = "Invalid Protocol Specification" If Index = 265 Then statusline = "** Bad Checksum **" If Index = 266 Then statusline = "Server NOT Connected" If Index = 267 Then statusline = "Invalid Response
‘ ‘ Each secon read and update all 10 values ‘ in each of th efour arrays ‘ For Counter = 0 To 9 status(0) = m_svr.ReadValue(PollHandle(0), Counter, temp) StatusMsg (status(0)) If temp = 0 Then inputstatus(Counter).Value = 0 Else inputstatus(Counter).Value = 1 End If Next Counter For Counter = 0 To 9 status(1) = m_svr.ReadValue(PollHandle(1), Counter, temp) StatusMsg (status(1)) If temp = 0 Then coilstatus(Counter).Value = 0 Else coilstatus(Counter).
Custom Displays Using the Custom Document Display feature of ModScan allows you to generate graphical displays of modbus data representing your specific instrumentation requirements. You can mix and match different types of data from the same or different slave device and have it displayed in a varity of formats.
Bar Chart Items Bar Chart items allow a modbus register value to be displayed as a colored bar whose amplitute represents its current value. Bar Charts may be drawn vertically, (bottom to top), or horizontally, (left to right), and the respective sizes are determined by user defined properties. Properties also define the source of the data used to update the chart and various drawing options such as the colors to use and whether or not to surround the bar chart with a border.
ModSim Following is a concise user’s manual for the operation of ModSim32. Operation of the 16-bit version of ModSim is similar, but is not detailed in this document. I. Application Overview A. Document/View Architecture B. Modbus Data Definition C. Display Formats D. Connections II. Commands A. File Menu B. Connection Menu C. Display Menu D. Window Menu E. Help Menu III. OLE Automation A. Automation Routines B.
ModSim Overview ModSim32 is a Windows Application designed to simulate data from one or more modbus slave devices. ModSim32 may be connected serially to a modbus master application, or connected to multiple modbus master client applications via a network. Modbus supports the modbus/TCP communications protocol standard. ModSim32 operates as a Windows MDI, (Multiple Document Interface), application, with each document representing a block of modbus data.
Display Formats Input Status and Coil Status values are represented within a ModSim32 document as either 1 or 0. Register values may be displayed in binary, decimal, hexadecimal, or floating-point notation. Floating-point representation uses the contents of two consequtive 16-bit registers to assemble one 32-bit IEEE floatingpoint value. ModSim32 can store a floating point value withe the most-significant 16-bits of data in the low-order register address or the high-order register address.
ModSim Commands File Menu The File menu offers the following commands: New Creates a new document. Use this command to create a new document in ModSim32. Open Opens an existing document. Use this command to open an existing document in a new window. You can open multiple documents at once. Use the Window menu to switch among the multiple open documents. Close Closes an opened document. Use this command to close all windows containing the active document.
Connection Menu The Connection menu offers the following commands for configuring each of the four COM ports and starting and stopping the MBAP Network Server: Connect Port 1 Port 2 Port 3 Port 4 Port 5 Port 6 Port 7 Port 8 Port 9 modbus/TCP Dosconnect Port 1 Port 2 Port 3 Port 4 Port 5 Port 6 Port 7 Port 8 Port 9 modbus/TCP Allows you to configure COM Port 1. Allows you to configure COM Port 2. Allows you to configure COM Port 3. Allows you to configure COM Port 4. Allows you to configure COM Port 5.
Window Menu The Window menu offers the following commands, which enable you to arrange multiple views of multiple documents in the application window: Cascade Arranges windows in an overlapped fashion. Tile Arranges windows in non-overlapped tiles. Arrange Icons Arranges icons of closed windows. Window 1, 2, ... Goes to specified window.
OLE Automation ModSim32 supports two OLE Automation functions which may be used to customize it’s operation for automated testing applications. Using Visual Basic or similar Windows OLE Automation Client, the user can access and modify modbus data points defined within a ModSim32 document. OLE Automation Routines short ReadValue (short NodeAddress, long PointAddress, short *pValue) Arguments: Node Address - refers to slave address associated with a ModSim32 document.
Visual Basic Example A very simple Visual Basic example project is included with the ModSim32 distribution files which demonstrates how to access/modify data points contained within a ModSim32 document. The example project simply updates a holding register based on a one second timer and updates a text control on the form. To create the project, perform the following steps: Use the Project Framework to Browse for ModSim32.
MNetSvr Following is a concise user’s manual for the operation of MNetSvr. I. modbus/TCP II. Application Overview A. Commands B.
modbus/TCP (MBAP) The Modbus Applications Programming Interface, (MBAP), protocol specification provides extensions to the messaging descriptions which allow components to communicate over TCP/IP networks. Developed by Modicon to support direct ethernet connections to PLC’s, the MBAP protocol defines header information which routes modbus packets between network devices transparent to other network activity.
MNetSvr Overview The MNetSvr application was designed to operate as a MBAP compatible interface between network client applications, (such as ModScan32), and serial slave devices. MNetSvr opens TCP Port #502 and listens for other network devices to initiate a connection. When a connection is made, MNetSvr spins off a separate thread of execution to process requests from the connected client.
MNetMon Following is a concise user’s manual for the operation of MNetMon. I. Application Description A. Overview B. Serial Connections C. Network Connections II. Menu Commands A. Connect B. Stale Data Timer C. Message Statistics D. Freeze Display E.
MNetMon Description Overview What is MNetMon and why do you need it? First of all. MNetMon is a Win32 software application designed to operate under Windows. It runs on Windows 95, Windows 98 or Windows NT. It uses all standard Windows drivers, so no special hardware or drivers are required for its operation. MNetMon was designed to provide a seamless interface between modbus devices and a TCP/IP network.
Serial Connections MNetMon uses a very simple concept. The nature or RS-232 allows multiple receivers to be connected to a single transmitter. As long as the total cable length does not exceed the RS-232 specification, a listening device, (in this case MNetMon), may tap into the transmit signal of an existing communications link and ‘hear’ everything that’s being said.
MNetMon Commands Connect To begin collecting data from the modbus network, you must issue the Connect menu option. MNetMon will guide you through a series of dialogs prompting for the port assignment of the connection to the modbus master and slave transmitters as well as the hardware characteristics of the link, (baud rate, parity, etc). After enabling the specified serial ports. MNetMon will begin monitoring character data on the two links.
Browse Data Points You may also review the data point directory as collected by the MNetMon monitoring operation. All modbus data currently contained within MNetMon local memory is made available via the View Data menu selection. Data presented by these dialogs represent a copy of MNetMon data made at the time the command was issued. The data presented here is not live.
Modbus Master ActiveX Control Following is a concise user’s manual for the operation of the Modbuss OCX control I. Overview A. Controls B. RegSvr32 C. MbOCXsvr II. Port Control Description A. Properties B. Methods C. Events III. Modbus Data Control Description A. Properties B. Methods C. Events D. Block Writes IV. Visual Basic Example V.
Controls Overview Modbuss.ocx contains 32-bit custom controls which allow Visual Basic and other OLE Container applications to quickly and easily access data points contained in a modbus slave device connected to the PC. The modbus device may be connected directly to a PC COM port or accessed via a network connection using the modbus/TCP, communications protocol standard. Modem connections are also supported using the Win32 TAPI interface.
Port Control Description The Modbus Port Configuration Control, (Serial), is used to programatically control the operating characteristics of a local PC Com port connected to one or more MODBUS slave devices. Use of the Serial control within a user application is optional. The hardware parameters configured by this control may also be set by accessing menu items within the modbuss ocx helper application, mbOCXsvr.exe.
Two events are also available which signal the controlling application when a modem connaction has been made or dropped. Connect ConnectionDrop Event which is fired upon successful establishment of a remote TAPI connection.. Event which is fired if the TAPI connection fails.
Modbus Data Control Description The Modbus Data Control, (modbuss), reflects the status of one or more I/O data points contained within a connected MODBUS slave device. Each control contains an array of up to 128 boolean values, (Coils), 128 integer values, (Registers), or 64 Floating Point values. The data is defined by properties which identify the device and point address.
could be the result of the user application making an invalid request, (such as setting the Length Property > 128), or as the result of a communications error with the designated MODBUS slave device. WriteStatus This status property is set by the control to indicate the results of the last write command issued from the control.
Methods Update() IssueCmd() Instructs the control to update its data array with fresh data values from the MODBUS slave device. Update will return an error, (FALSE), if the control’s IO Point property definitions are invalid or if the control is busy processing a previous Update() request. When the results of the data poll are obtained, the control will trigger the Ready event. If the poll for data fails, the Busy status indicator will go false, but the Ready event will not fire.
Data may be accessed from the control via the following array properties: Coil() This array property allows the control application to read or write a boolean value from/to the slave device. A read operation does not verify proper data addressing of the point prior to returning the value. If the control property data address has been configured to scan register values from the MODBUS device, erroneous readings will occur if the Coil property is used to access the data array.
Events The Modbus Data Control posts the following events as a result of the Update method: UpdateFinished The Modbuss UpdateFinished Event signals that the control has finished processing the Update() request and is ready to accept a new command. The UpdateFinished event does not indicate success or failure of the Update(). Use the Status property to evaluate the results of the Update(), or use the Ready event to indicate new data available.
Block Writes The following property and method determine how modbus data is written to the slave device(s). EnableBlockWrites This boolean property determines how modbus data is written to the slave device attached to the control. If this property is FALSE, the control will attempt to write data to the slave device whenever the controlling application modifies an array value using Coil(), Register(), Float(), or WSFloat().
Visual Basic Example An example Visual Basic project is included with the modbuss.ocx distribution zip file. This example, (Demo1), consists of a single VBA form containing standard text controls along with the Modbus Data Control and Modbus Port Configuration Control contained within modbuss.ocx. Operation of the Demo1 example scans the IO_Points defined by the edit controls based on a 5 second timer tick.
Timer2 is configured to run every 5 seconds. The Serial Port Configuration Property defines the time-out associated with the RTU slave device as 1 second. If the user attempts to address a node which is not present, no indication will be received, (i.e. the Ready event will not trigger). This is why the first timer updates the status text every second asynchronously to the updates. Private Sub Timer2_Timer() ErrRet = Modbuss1.
Command1 is used to write a data value to the slave device. The value specified by Text5 is written to the IO Point array indexed by Text4. Again, the application must determine whether to write a coil or register value by examininig the Address property. The control data is automatically refreshed after a write operation so the next ready event should displaythe results of the write. Private Sub Command1_Click() If (Modbuss1.
Mobuss OCX Implementation Notes The following notes present programming details concerning operation of the Modbuss Data Control. if Update() returns TRUE guaranteed to get an UpdateFinished Event NOT guaranteed to get Ready Event. if Update() returns FALSE UpdateFinished is NOT fired.
If EnableBlockWrites is TRUE Setting a data value will change the contents of the control's data. Status will be set to UNINITIALIZED indicating that the data within the control does not match the data in the slave. No messages are issued to the modbus. If an Update request is made, new data received from the slave device will overwrite any data which may have been written by the program. The application must insure that Updates are suspended during block write operations.
Modbus Slave ActiveX Control Following is a concise user’s manual for the operation of the Modbus_slave OCX control I. Overview II. Modbus_slave Control Description A. Properties B. Methods C. Events III.
Modbus_Slave OCX Overview Modbus_slave.ocx contains a 32-bit custom control, which allows Visual Basic and other OLE Container applications to quickly, and easily interface user-defined data points to a modbus master device connected to the PC. The modbus master may be connected directly to a PC COM port or accessed via a network connection using modbus/TCP.
Methods ClearMessageCounter (LONG InterfaceHandle) Method to reset the control’s message counter to zero. The InterfaceHandle parameter passed to ClearMessageCounter must match the LONG value returned from a ConnectSerial() or ConnectTCP() method. The control maintains an internal counter for each open connection detailing the number of successful message transactions which have occured on between the control and the modbus master.
CreateModbusData (LONG Address, SHORT Size, SHORT *pData) The CreateModbusData() method exposes user data for access by a connected modbus master. The supplied Address and Size parameters define how the data is to be addessed according to the modbus protocol. The current value of the NodeAddress property determines which slave node is associated with the defined data.
Events The Modbus_slave Control posts the following events to the controlling application: DataWrittenFromMaster The DataWrittenFromMaster Event signifies that a block of data maintained by the control has been modified via the modbus connection. The handle of the effected data block is returned as a parameter with this event. The controlling application should compare the returned value with it’s list of defined data blocks to determine which range of addresses have been written.
Visual Basic Example An example Visual Basic project is included with the mbslvocx distribution zip file. This example, (Project1), was designed using Visual Basic 5.0 and consists of a single VBA form containing standard text controls representing two arrays of modbus data. Defined are twenty HOLDING REGISTERS and thirty STATUS COILS which may be read/written from a modbus master. Default settings for the example application operate on COM Port number 1 at 9600 Baud, 8 Data bits, 1 Stop Bit and no parity.
‘ on Form Load Private Sub Form_Load() Interface = Modbus_slave1.ConnectSerial(1) Data1 = Modbus_slave1.CreateModbusData (40101, 20, MyData1(0)) Data2 = Modbus_slave1.