# $ Functions: Devices - Modbus

Note: The following $ Functions are available only if the Modbus plugin has been installed and loaded into the Cognex Designer project. See the Optional Communications Plugins and Enabling Optional Plugins in a Project topics for more information.

    $Devices.ModbusClientDevice.ReadCoils(startingAddress, count : Integer) : Boolean[]
Function Code | 1
Arguments | startingAddress: Integer, specifying the memory address of the connected Modbus server from which coil reading is started. count: Integer, specifying the number of coils to read. Its maximum value is 2000.
Returns | An array of booleans, representing the value of the coils from the specified startingAddress for the specified count.
Description | Reads the value of one or more Coils from the connected Modbus Server.

    $Devices.ModbusClientDevice.ReadDiscreteInputs(startingAddress, count : Integer) : Boolean[]
Function Code | 2
Arguments | startingAddress: Integer, specifying the memory address of the connected Modbus server from which discrete input reading is started. count: Integer, specifying the number of discrete inputs to read. Its maximum value is 2000.
Returns | An array of booleans, representing the value of the digital inputs from the specified startingAddress for the specified count.
Description | Reads the value of one or more Discrete Inputs from the connected Modbus Server.

    $Devices.ModbusClientDevice.ReadHoldingRegisters(startingAddress, count : Integer) : Int16[]
Function Code | 3
Arguments | startingAddress: Integer, specifying the memory address of the connected Modbus server from which holding register reading is started. count: Integer, specifying the number of holding registers to read. Its maximum value is 125.
Returns | An array of booleans, representing the value of the holding registers from the specified startingAddress for the specified count.
Description | Reads the value of one or more Holding Registers from the connected Modbus Server.

    $Devices.ModbusClientDevice.ReadInputRegisters(startingAddress, count : Integer) : Int16[]
Function Code | 4
Arguments | startingAddress: Integer, specifying the memory address of the connected Modbus server from which input register reading is started. count: Integer, specifying the number of input registers to read. Its maximum value is 125.
Returns | An array of booleans, representing the value of the input registers from the specified startingAddress for the specified count.
Description | Reads the value of one or more Input Registers from the connected Modbus Server.

    $Devices.ModbusClientDevice.WriteMultipleCoils(startingAddress : Integer, valuesToWrite : Boolean[])
Function Code | 15
Arguments | startingAddress: Integer, specifying the memory address of the connected Modbus server from which the write operation is performed. valuesToWrite: An array of booleans, specifying the values to write to the coils. The array can contain up to 1968 values.
Returns | N/A
Description | Writes the value of one or more Coils at the connected Modbus Server.

    $Devices.ModbusClientDevice.WriteMultipleRegisters(startingAddress : Integer, valuesToWrite : Int16[])
Function Code | 16
Arguments | startingAddress: Integer, specifying the memory address of the connected Modbus server from which the write operation is performed. valuesToWrite: An array of short integers, specifying the values to write to the registers. The array can contain up to 123 values.
Returns | N/A
Description | Writes the value of one or more Holding Registers at the connected Modbus Server.

    $Devices.ModbusClientDevice.WriteSingleCoil(address : Integer, valueToWrite : Boolean)
Function Code | 5
Arguments | address: Integer, specifying the memory address of the connected Modbus server at which the write operation is performed. valueToWrite: Boolean, specifying the value to write to the Coil.
Returns | N/A
Description | Writes the value of a single Coil at the connected Modbus Server.

    $Devices.ModbusServerDevice.ReadBits(ioType : ModbusIOType, startingAddress : Integer, count : Integer) : Boolean[]
Arguments | ioType: A ModbusIOType type. Its values can be the following: Coils: Represents the writable 1-bit length units. DiscreteInputs: Represents the read-only 1-bit length units. InputRegisters: Represents the read-only 16-bit length units. HoldingRegisters: Represents the writable 16-bit length units. startingAddress: Integer, specifying the memory address of the Modbus server from which the read operation is performed. count: Integer, specifying the number of bits to read
Returns | An array of booleans, listing the values of the bits read during the operation.
Description | Reads the value(s) of one or more locally stored bits. Note: By default, all IO units are filled with zero bits and bytes in the Modbus Server storage.

    $Devices.ModbusServerDevice.ReadData(ioType : ModbusIOType, startingAddress : Integer, count : Integer) : Int16[]
Arguments | ioType: A ModbusIOType type. Its values can be the following: Coils: Represents the writable 1-bit length units. DiscreteInputs: Represents the read-only 1-bit length units. InputRegisters: Represents the read-only 16-bit length units. HoldingRegisters: Represents the writable 16-bit length units. startingAddress: Integer, specifying the memory address of the Modbus server from which the read operation is performed. count: Integer, specifying the number of IO units to read
Returns | An array of short integers, listing the values of the IO units read during the operation.
Description | Reads the value(s) of one or more IO units. Note: By default, all IO units are filled with zero bits and bytes in the Modbus Server storage.

    $Devices.ModbusServerDevice.WriteBits(ioType : ModbusIOType, startingAddress : Integer, valuesToWrite : Boolean[])
Arguments | ioType: A ModbusIOType type. Its values can be the following: Coils: Represents the writable 1-bit length units. DiscreteInputs: Represents the read-only 1-bit length units. InputRegisters: Represents the read-only 16-bit length units. HoldingRegisters: Represents the writable 16-bit length units. startingAddress: Integer, specifying the memory address of the Modbus server from which the write operation is performed. valuesToWrite: An array of booleans, specifying the values to write into the bits from the startingAddress.
Returns | N/A
Description | Writes the value(s) of one or more locally stored bits.

    $Devices.ModbusServerDevice.WriteData(ioType : ModbusIOType, startingAddress : Integer, valuesToWrite : Int16[])
Arguments | ioType: A ModbusIOType type. Its values can be the following: Coils: Represents the writable 1-bit length units. DiscreteInputs: Represents the read-only 1-bit length units. InputRegisters: Represents the read-only 16-bit length units. HoldingRegisters: Represents the writable 16-bit length units. startingAddress: Integer, specifying the memory address of the Modbus server from which the write operation is performed. valuesToWrite: An array of short integers, specifying the values to write into the IO units from the startingAddress.
Returns | N/A
Description | Writes the value(s) of one or more IO units.