Exemplo n.º 1
0
                                    pub_topic="modbus_wrapper/input")
    modclient.setReadingRegisters(ADDRESS_READ_START, NUM_REGISTERS)
    modclient.setWritingRegisters(ADDRESS_WRITE_START, NUM_REGISTERS)
    rospy.loginfo("Setup complete")

    # start listening to modbus and publish changes to the rostopic
    modclient.startListening(unit=0x01)
    rospy.loginfo("Listener started")

    #################
    # Example 1
    # Sets an individual register using the python interface, which can automatically be reset, if a timeout is given.
    register = 40020
    value = 1
    timeout = 0.5
    modclient.setOutput(register, value, timeout, unit=0x01)
    rospy.loginfo("Set an individual output")
    #################

    #################
    # Example 2
    # Create a listener that show us a message if anything on the readable modbus registers change
    rospy.loginfo("All done. Listening to inputs... Terminate by Ctrl+c")

    def showUpdatedRegisters(msg):
        rospy.loginfo("Modbus server registers have been updated: %s",
                      str(msg.data))

    sub = rospy.Subscriber("modbus_wrapper/input",
                           HoldingRegister,
                           showUpdatedRegisters,
Exemplo n.º 2
0
                                    pub_topic="modbus_wrapper/input")
    modclient.setReadingRegisters(ADDRESS_READ_START, NUM_REGISTERS)
    modclient.setWritingRegisters(ADDRESS_WRITE_START, NUM_REGISTERS)
    rospy.loginfo("Setup complete")

    # start listening to modbus and publish changes to the rostopic
    modclient.startListening()
    rospy.loginfo("Listener started")

    #################
    # Example 1
    # Sets an individual register using the python interface, which can automatically be reset, if a timeout is given.
    register = 40020
    value = 1
    timeout = 0.5
    modclient.setOutput(register, value, timeout)
    rospy.loginfo("Set and individual output")
    #################

    #################
    # Example 2
    # Create a listener that show us a message if anything on the readable modbus registers change
    rospy.loginfo("All done. Listening to inputs... Terminate by Ctrl+c")

    def showUpdatedRegisters(msg):
        rospy.loginfo("Modbus server registers have been updated: %s",
                      str(msg.data))

    sub = rospy.Subscriber("modbus_wrapper/input",
                           HoldingRegister,
                           showUpdatedRegisters,
Exemplo n.º 3
0
 modclient = ModbusWrapperClient(host,port=port,rate=50,reset_registers=False,sub_topic="modbus_wrapper/output",pub_topic="modbus_wrapper/input")
 modclient.setReadingRegisters(ADDRESS_READ_START,NUM_REGISTERS)
 modclient.setWritingRegisters(ADDRESS_WRITE_START,NUM_REGISTERS)
 rospy.loginfo("Setup complete")
 
 # start listening to modbus and publish changes to the rostopic
 modclient.startListening()
 rospy.loginfo("Listener started")
 
 #################
 # Example 1
 # Sets an individual register using the python interface, which can automatically be reset, if a timeout is given.
 register = 40020
 value = 1
 timeout = 0.5
 modclient.setOutput(register,value,timeout)
 rospy.loginfo("Set and individual output")
 #################
 
 
 
 #################
 # Example 2
 # Create a listener that show us a message if anything on the readable modbus registers change
 rospy.loginfo("All done. Listening to inputs... Terminate by Ctrl+c")
 def showUpdatedRegisters(msg):
     rospy.loginfo("Modbus server registers have been updated: %s",str(msg.data))
 sub = rospy.Subscriber("modbus_wrapper/input",HoldingRegister,showUpdatedRegisters,queue_size=500)
 #################
 
 #################