def connect(self):
try:
if self.device_id is None:
# Try to find pH device id automatically
devices = list_devices.get_ftdi_device_list()
# Check if any atlas devices are connected to device
if len(devices) == 0:
raise IOError("No atlas device found on system")
for device in devices:
# Extract id
device_id = (device.split("FTDI:FT230X Basic UART:"))[1]
# Check if device is ph sensor
with AtlasDevice(device_id) as atlas_device:
atlas_device.send_cmd("i") # get device information
time.sleep(1)
lines = atlas_device.read_lines()
if len(lines) == 0:
continue
if "EC" in lines[0]:
self.device_id = device_id
rospy.loginfo("Automatically found device id: {}".format(device_id))
self.device = AtlasDevice(self.device_id)
self.device.send_cmd("C,0") # turn off continuous mode
time.sleep(1)
self.device.flush()
rospy.loginfo("Connected to AtlasEc")
except Exception as e:
rospy.logwarn("Failed to connect to AtlasEc. Error: {}".format(e))
pass
评论列表
文章目录