MB Ethernet Master Query Read Discrete Inputs (poly).vi
The master uses this VI to read the slaves' discrete inputs. This corresponds to a public function code of 2 in the MODBUS protocol.
|MBAP Header is a cluster containing the transaction ID and Unit ID. This is additional information not usually required for a MODBUS transaction.|
Transaction Identifier—This identifier is for transaction pairing; the MODBUS server copies the request transaction identifier in the response.
Unit Identifier—This field is for intra-system routing purposes. It typically communicates to a MODBUS serial line slave through a gateway between an Ethernet TCP-IP network and a MODBUS serial line. The MODBUS client sets this field in the request, and the server response must return this field with the same value.
|TCP Connection Refnum in is a network connection refnum that uniquely identifies the TCP connection. Use TCP Open Connection.vi to open a TCP connection.|
|Starting Address is the first address location of the discrete inputs to read. This address is sometimes referred to as offset. Refer to your device's documentation to find the discrete input address mapping.|
Be sure to specify the correct address in the MODBUS device configuration software for the register you want to use in LabVIEW. In most MODBUS device configuration software, you must enter a name for the register you want to use. Per MODBUS convention, the register address of the slave device is calculated by subtracting 1 from the register name that you specify in the master device configuration software. The MODBUS LabVIEW library expects register addresses, not register names, so you may need to subtract 1 from the address you defined in the MODBUS device configuration software. For example, a register name defined as 2 in a MODBUS configuration device translates to register address 1 in the Holding Registers table of the LabVIEW MODBUS library, as shown below.
|Quantity represents how many discrete inputs to read from the slave. The VI returns the discrete input at Starting Address and each following discrete input up to Quantity. For example, if Starting Address is 0 and Quantity is 4, the VI reads discrete inputs from the slave at address 0, 1, 2, and 3.|
|Timeout specifies the maximum time period, in milliseconds, that the VI waits for the slave's response before throwing an error.|
|error in describes error conditions that occur before this VI or function runs. The default is no error. If an error occurred before this VI or function runs, the VI or function passes the error in value to error out. If an error occurs while this VI or function runs, the VI or function runs normally and sets its own error status in error out. Use the Simple Error Handler or General Error Handler VIs to display the description of the error code. Use error in and error out to check errors and to specify execution order by wiring error out from one node to error in of the next node.
|TCP Connection Refnum (dup) can be an input to another MODBUS VI, or you can close it using TCP Close Connection.vi.|
|Discrete Inputs represents the data read from the slave.|
|Exception Code is nonzero if a MODBUS error has occurred. The exception code mapping is as follows:|
|error out contains error information. If error in indicates that an error occurred before this VI or function ran, error out contains the same error information. Otherwise, it describes the error status that this VI or function produces. Right-click the error out front panel indicator and select Explain Error from the shortcut menu for more information about the error.