def test_functions_with_closed_port(self): # type: () -> None """Test pyads functions with no open port.""" pyads.open_port() adr = pyads.get_local_address() pyads.close_port() self.assertIsNotNone(adr) self.assertIsNone(pyads.get_local_address()) self.assertIsNone(pyads.read_state(adr)) self.assertIsNone(pyads.read_device_info(adr)) self.assertIsNone( pyads.read_write(adr, 1, 2, pyads.PLCTYPE_INT, 1, pyads.PLCTYPE_INT)) self.assertIsNone(pyads.read(adr, 1, 2, pyads.PLCTYPE_INT)) self.assertIsNone(pyads.read_by_name(adr, "hello", pyads.PLCTYPE_INT)) self.assertIsNone( pyads.add_device_notification(adr, "test", pyads.NotificationAttrib(4), lambda x: x))
def test_functions_with_closed_port(self): # type: () -> None """Test pyads functions with no open port.""" pyads.open_port() adr = pyads.get_local_address() pyads.close_port() self.assertIsNotNone(adr) self.assertIsNone(pyads.get_local_address()) self.assertIsNone(pyads.read_state(adr)) self.assertIsNone(pyads.read_device_info(adr)) self.assertIsNone( pyads.read_write(adr, 1, 2, pyads.PLCTYPE_INT, 1, pyads.PLCTYPE_INT) ) self.assertIsNone(pyads.read(adr, 1, 2, pyads.PLCTYPE_INT)) self.assertIsNone(pyads.read_by_name(adr, "hello", pyads.PLCTYPE_INT)) self.assertIsNone( pyads.add_device_notification( adr, "test", pyads.NotificationAttrib(4), lambda x: x ) )
cnt = contours[len(perimeters) - 1] cv2.drawContours(black_img, [cnt], 0, (255, 255, 255), 1) #bounding box rect = cv2.minAreaRect(cnt) box = cv2.boxPoints(rect) box = np.int0(box) cv2.drawContours(black_img, [box], 0, (255, 255, 255), 1) angle = int(rect[2]) - 3 print("Angle of orientation: ", angle) x = str(angle * -1) ser.write(x.encode('utf-8', 'ignore')) pyads.write_by_name(adr, 'MAIN.partAngle', str(angle), pyads.PLCTYPE_STRING) pyads.write_by_name(adr, 'MAIN.partReadyToPick', True, pyads.PLCTYPE_BOOL) print("Completed...") pyads.write_by_name(adr, 'MAIN.partReadyToRot', False, pyads.PLCTYPE_BOOL) #cv2.imshow("thresh",thresh_img) #cv2.imshow("black_img",black_img) cam.release() ser.close() cv2.waitKey(0) pyads.close_port() cv2.destroyAllWindows() print("Exit..")
def __del__(self): pyads.close_port()