Robotics StackExchange | Archived questions

Coonection plc with ros, how can i send data plc?I have errors.

I have following errors:

ERROR] [1667558574.007022]: bad callback: <function callback at 0x7faf62c35d50> Traceback (most recent call last):   File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback     cb(msg)   File "/home/kavurlar/catkin_ws/src/humble/script/status_to_plc.py", line 20, in callback     plc.db_write(0,6,number)   File "/home/kavurlar/.local/lib/python2.7/site-packages/snap7/client.py", line 25, in f     code = func(*args, **kw)   File "/home/kavurlar/.local/lib/python2.7/site-packages/snap7/client.py", line 159, in db_write     size = len(data) TypeError: object of type 'bool' has no len()

Below is the code:

#! /usr/bin/python
import rospy
import snap7
import struct
from std_msgs.msg import Bool

ip = '192.168.0.2'
db = 6
plc = snap7.client.Client()
plc.connect(ip, 0, 1)

def callback(data): #Real yazma 
    global number
    number = bool
    number = data.data
    plc.db_write(0,6,number)
    rospy.init_node("plc_tcp","listener")
    return

def cmd_vel_listener():
    rospy.init_node("tcp_plc", anonymous=True)
    rospy.Subscriber("chatter", Bool, callback)
    rospy.spin()

if __name__ == "__main__":
    cmd_vel_listener()

Below is the publisher:

#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from std_msgs.msg import Float32
from std_msgs.msg import Bool

def talker():
    pub = rospy.Publisher('chatter',Bool,queue_size=10) #yayıncımızı olusrutduk.
    rospy.init_node('talker')
    rate = rospy.Rate(1) #10hz

    i = 0
    fruits = [1,2,3,4,5]            
    for i in fruits:
        rospy.loginfo(True)    
        pub.publish(True) #mesaji yayinlar    
        rate.sleep()


if __name__ == '__main__':
    try:
        talker()    
    except rospy.ROSInterreptException:    
        pass

Asked by turkoahmet on 2022-11-04 05:52:08 UTC

Comments

number = bool

It should be number = Bool(). There are other errors as well. I recommend checking Writing a Simple Publisher and Subscriber (Python)

Asked by ravijoshi on 2022-11-05 08:19:03 UTC

Answers