|
|||||||
Modbus Poll user manual
Время создания: 16.01.2020 15:17
Текстовые метки: modbus
Раздел: Разные закладки - MSO - Modbus
Запись: xintrea/mytetra_db_adgaver_new/master/base/1579177031l33rgw449b/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
12. OLE/Automation Automation (formerly known as OLE Automation) makes it possible for one application to manipulate objects implemented in another application. An Automation client is an application that can manipulate exposed objects belonging to another application. This is also called an Automation controller. An Automation server is an application that exposes programmable objects to other applications. Modbus Poll is an automation server. That means you can use any program that supports VBA (Visual Basic for Applications) such as Visual Basic, Excel etc. to interpret and show the modbus data according to your specific requirements. 12.1. Excel example You should display the Developer tab or run in developer mode when you want to write macros. 12.1.1. Excel 2007
12.1.2. Excel 2010
12.1.3. Excel sample code This example opens two windows. One reading registers and another reading Coils. An example is also included with the Modbus Poll installation. Excel VBA Example Public doc1 As Object Public doc2 As Object Public app As Object Dim res As Integer Dim n As Integer
Private Sub StartModbusPoll_Click() Set app = CreateObject("Mbpoll.Application") Set doc1 = CreateObject("Mbpoll.Document") Set doc2 = CreateObject("Mbpoll.Document") ' Read 10 Holding Registers every 1000ms res = doc1.ReadHoldingRegisters(1, 0, 10, 1000) ' Read 10 Coil Status every 1000ms res = doc2.ReadCoils(1, 0, 10, 1000) ' doc1.ShowWindow() app.Connection = 1 ' Modbus TCP/IP app.IPAddress = "127.0.0.1" ' local host app.ServerPort = 502 app.ConnectTimeout = 1000 res = app.OpenConnection() End Sub
Private Sub Read_Click() Cells(5, 7) = doc1.ReadResult() 'Show results for the requests Cells(6, 7) = doc2.ReadResult()
For n = 0 To 9 Cells(5 + n, 2) = doc1.SRegisters(n) Next n
For n = 0 To 9 Cells(18 + n, 2) = doc2.Coils(n) Next n End Sub
12.2. Connection Functions/Properties The following properties and functions do the same as you setup in the connection dialog (F3). 12.2.1. Connection Connection selects the desired connection. A serial port or one of the Ethernet connections can be selected. Property Connection as Integer Valid values 0 = Serial port 12.2.2. BaudRate Applicable only for Connection = 0 Property BaudRate as Long Valid values 300 Example BaudRate = 9600 12.2.3. DataBits Applicable only for Connection = 0 Property DataBits as Integer Valid values 7 Example DataBits = 8 12.2.4. Parity Applicable only for Connection = 0 Property Parity as Integer Valid values 0 = None Example Parity = 2 12.2.5. StopBits Applicable only for Connection = 0 Property StopBits as Integer Valid values 1 (Default)+ 2 Example StopBits = 1 12.2.6. SerialPort Applicable only for Connection = 0 Property SerialPort as Integer Valid values 1…255 Default value = 1 Example SerialPort = 1 12.2.7. ResponseTimeout The ResponseTimeout specifies the length of time in ms that Modbus Poll should wait for a response from a slave device before giving up. Property ResponseTimeout as Integer Valid values 50…100000 Default value = 1000 Example: ResponseTimeout = 1000 12.2.8. ServerPort Applicable only for Connection = 1…4 Property ServerPort as Long Valid values 0…65535 Default value = 502 Example ServerPort = 502 12.2.9. ConnectTimeout The ConnectTimeout specifies the length of time that Modbus Poll should wait for a TCP/IP connection to succeed. Applicable only for Connection = 1…4 Property ConnectTimeout as Integer Valid values 100…30000ms Default value = 1000ms Example ConnectTimeout = 1000 12.2.10. IPVersion Applicable only for Connection = 1…4 Property IPVersion as Integer Valid values 4 = IP Version 4 (Default) Example IPVersion = 4 12.2.11. OpenConnection Opens the connection selected with the Connection property. Function OpenConnection() As Integer Return Value: For error 3-5: Please check if you have the latest serial port driver. 0 = SUCCESS Example how to open a Modbus TCP/IP connection Public app As Object Dim res As Integer ' Create an object to Modbus Poll Set app = CreateObject("Mbpoll.Application") app.Connection = 1 ' Select Modbus TCP/IP app.IPVersion = 4 app.IPAddress = "192.168.1.27" app.ServerPort = 502 app.ConnectTimeout = 1000 app.ResponseTimeout = 1000 res = OpenConnection() Example how to setup a serial connection Public app As Object Dim status As Integer ' Create an object to Modbus Poll Set app = CreateObject("Mbpoll.Application")
app.Connection = 0 ' Mode is serial port app.SerialPort = 1 ' Com port 1 app.BaudRate = 9600 ' 9600 baud app.Parity = 0 ' None parity app.Mode = 0 ' RTU mode app.ResponseTimeout = 1000 ' Wait 1000ms until give up status = app.OpenConnection() 12.2.12. CloseConnection Function CloseConnection() As Integer Return Value Zero if success. Nonzero value if failed. 12.3. Read Functions The following functions do the same as you setup in the read/write definition dialog (F8). Read functions are associated with a Modbus Poll document. (The window with data) ' First a Modbus Poll document is needed. Public doc As Object
Set doc = CreateObject("Mbpoll.Document") res = doc.ReadCoils(1, 0, 100, 1000) ' Read 100 coils every 1000ms
12.3.1. ReadCoils Function ReadCoils(SlaveID As Integer, Address As Long, Quantity As Integer, ScanRate As Long) As Integer Return Value True if success. False if not success Parameters SlaveID: The slave address 1 to 255 12.3.2. ReadDiscreteInputs Function ReadDiscreteInputs(SlaveID As Integer, Address As Long, Quantity As Integer, ScanRate As Long) As Integer Return Value True if success. False if not success Parameters SlaveID: The slave address 1 to 255 12.3.3. ReadHoldingRegisters Function ReadHoldingRegisters(SlaveID As Integer, Address As Long, Quantity As Integer, ScanRate As Long) As Integer Return Value True if success. False if not success Parameters SlaveID: The slave address 1 to 255 12.3.4. ReadInputRegisters Function ReadInputRegisters(SlaveID As Integer, Address As Long, Quantity As Integer, ScanRate As Long) As Integer Return Value True if success. False if not success Parameters SlaveID: The slave address 1 to 255 12.3.5. ShowWindow ShowWindow() 12.3.6. ByteOrder Property ByteOrder As Integer Description Sets the byte order used by Longs, Floats and Doubles properties. Example for Longs: Syntax ByteOrder [=newvalue] 12.3.7. ReadResult Use this property to check if communication established with Read is running successful. Property ReadResult As Integer Return Value: 12.3.8. WriteResult Return a write result as an integer. Property WriteResult As Integer 12.4. Automation data properties The below properties are used to set or get values in the internal write/read arrays in Modbus Poll. The Index used is not a Modbus Address. The Index always counts from 0 no matter of the address used. The data properties are associated with a Modbus Poll document. (The window with data) Example 1: ' doc is assumed created first. See Excel example. doc.SRegisters(0) = 1 doc.SRegisters(1) = 10 doc.SRegisters(2) = 1234 ' Write 3 registers stored in Modbus Poll internal array ' to Modbus address 100 (40101) res = doc.WriteMultipleRegisters(1, 100, 3) Example 2 with floating point values: doc.Floats(0) = 1.3 doc.Floats(2) = 10.5 doc.Floats(4) = 1234.12 res = doc. WriteMultipleRegisters(1, 0, 6) "Write the 6 register stored in Modbus Poll ' 6 Registers are written as float is 32 bit wide. 12.4.1. Coils Property Coils(Index As Integer) As Integer Description Sets a coil in the write array structure or return a coil from the read array. Syntax Coils(Index) [=newvalue] 12.4.2. SRegisters Property SRegisters(Index As Integer) As Integer Description Sets a register in the write array structure or return a register from the read array. Syntax SRegisters (Index) [=newvalue] 12.4.3. URegisters Property URegisters(Index As Integer) As Long Description Sets a register in the write array structure or return a register from the read array. Syntax Object. URegisters (Index) [=newvalue] 12.4.4. Ints_32 Property Ints_32(Index As Integer) As Double Description Sets a 32 Bit integer in the write array structure or return an integer from the read array. Syntax Ints_32 (Index) [=newvalue] 12.4.5. UInts_32 Property UInts_32(Index As Integer) As Double Description Sets a 32 Bit unsigned integer in the write array structure or return an unsigned integer from the read array. Syntax UInts_32 (Index) [=newvalue] 12.4.6. Ints_64 Property Ints_64(Index As Integer) As Double Description Sets a 64 Bit integer in the write array structure or return an integer from the read array. Syntax Ints_64 (Index) [=newvalue] 12.4.7. UInts_64 Property UInts_64(Index As Integer) As Double Description Sets a 64 Bit unsigned integer in the write array structure or return an unsigned integer from the read array. Syntax UInts_64 (Index) [=newvalue] 12.4.8. Floats Property Floats(Index As Integer) As Single Description Sets a float in the write array structure or return a float from the read array. Syntax Floats* (Index) [=newvalue] 12.4.9. Doubles Property Doubles(Index As Integer) As Double Description Sets a double in the write array structure or return a double from the read array. Syntax Doubles* (Index) [=newvalue] 12.5. Automation Write Functions The write functions write the values stored in the array filled by the properties. The functions are associated with a Modbus Poll document. (The window with data) 12.5.1. WriteSingleCoil Function WriteSingleCoil(SlaveID As Integer, Address As Long) As Integer Return Value True if write array is ready and the data are sent. False if array empty or error in parameters. Parameters SlaveID: The slave address 0 to 255 Description Writes the first coil stored in the write array. 12.5.2. WriteSingleRegister Function WriteSingleRegister (SlaveID As Integer, Address As Long) As Integer Return Value True if write array is ready and the data are sent. False if array empty or error in parameters. Parameters SlaveID: The slave address 0 to 255 Description Writes the first register stored in the write array. 12.5.3. WriteMultipleCoils Function WriteMultipleCoils(SlaveID As Integer, Address As Long, Quantity As Integer) As Integer Return Value True if write array is ready and the data are sent. False if array empty or error in parameters. Parameters SlaveID: The slave address 0 to 255 Description Write the coils stored in the write array. 12.5.4. WriteMultipleRegisters Function WriteMultipleRegisters(SlaveID As Integer, Address As Long, Quantity As Integer) As Integer Return Value True if write array is ready and the data are sent. False if array empty or error in parameters. Parameters SlaveID: The slave address 0 to 255 Description Write the registers stored in the write array.
|
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|