Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define the Modbus TCP/IP port number.
PLC Programming
modbus_port = [1]Attempts:
3 left
💡 Hint
Common Mistakes
Using HTTP port 80 instead of Modbus port 502.
Confusing Telnet port 23 with Modbus port.
✗ Incorrect
The standard port number for Modbus TCP/IP communication is 502.
2fill in blank
mediumComplete the code to create a Modbus TCP client connection.
PLC Programming
client = ModbusTcpClient('[1]')
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid IP address like 10.0.0.256 (256 is out of range).
Using a subnet mask instead of an IP address.
✗ Incorrect
The client must connect to a valid IP address of the Modbus server; 192.168.1.100 is a valid private IP.
3fill in blank
hardFix the error in the code to read holding registers starting at address 10.
PLC Programming
result = client.read_holding_registers([1], 5)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string '10' instead of integer 10.
Using a word 'ten' which is invalid.
✗ Incorrect
The address must be an integer; 10 is correct. Strings or words cause errors.
4fill in blank
hardFill both blanks to write values [100, 200] to holding registers starting at address 20.
PLC Programming
client.write_registers([1], [2])
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the address and values arguments.
Using incorrect address or wrong list of values.
✗ Incorrect
The first argument is the starting address 20, the second is the list of values to write.
5fill in blank
hardFill all three blanks to create a Modbus TCP client, connect, read 3 coils starting at 5, and close the connection.
PLC Programming
client = ModbusTcpClient('[1]') client.[2]() result = client.read_coils([3], 3) client.close()
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong IP address format.
Using 'start' instead of 'connect' method.
Using string instead of integer for coil address.
✗ Incorrect
The client connects to IP 192.168.0.50, calls connect() method, and reads coils starting at address 5.
