From 21c22f517be023e01434fb0333e16c6c759e39f9 Mon Sep 17 00:00:00 2001
From: eisler <eisler@users.noreply.github.com>
Date: Mon, 8 Jun 2020 10:00:58 +0000
Subject: [PATCH] 44_TEK603: Added patch for TEK603 not prevent FHEM start if
 USB device is not reachable and change to use DevIo

git-svn-id: https://svn.fhem.de/fhem/trunk@22136 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
 fhem/FHEM/44_TEK603.pm | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/fhem/FHEM/44_TEK603.pm b/fhem/FHEM/44_TEK603.pm
index 074c8b3ea..80739e379 100644
--- a/fhem/FHEM/44_TEK603.pm
+++ b/fhem/FHEM/44_TEK603.pm
@@ -27,6 +27,7 @@ package main;
 
 use strict;
 use warnings;
+use DevIo;
 
 use Digest::CRC; # libdigest-crc-perl
 
@@ -42,8 +43,6 @@ sub TEK603_reconnect($);
 sub TEK603_Initialize($) {
 	my ($hash) = @_;
 
-	require $attr{global}{modpath} . '/FHEM/DevIo.pm';
-
 	$hash->{ReadFn}		= 'TEK603_read';
 	$hash->{ReadyFn}	= 'TEK603_ready';
 	$hash->{DefFn}		= 'TEK603_define';
@@ -139,16 +138,28 @@ sub TEK603_undef($$) {
 }
 
 
-sub TEK603_ready($) {
+sub TEK603_ready() {
 	my ($hash) = @_;
 	my $name = $hash->{NAME};
 	return if (IsDisabled($name));
 	return DevIo_OpenDev($hash, 1, 'TEK603_doInit') if($hash->{STATE} eq 'disconnected');
 
 	# This is relevant for windows/USB only
+	my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags);
 	my $po = $hash->{USBDev};
-	my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status;
-	return ($InBytes > 0);
+
+	if ($po) {
+		($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status;
+		return ($InBytes > 0);
+	}
+
+	# Someone set us up the bomb
+	Log3($hash->{NAME}, 1, qq[Can't read from $hash->{DeviceName}]);
+
+	# disable device
+	Log3($hash->{NAME}, 1, qq[Disabled device due read errors]);
+	CommandAttr(undef, $hash->{NAME} . ' disable 1');
+	return;
 }
 
 sub TEK603_read($) {