'How not consider a specific value in a data stream?
I tried to program a server (UDP Socket) to allow a data exchange between my PC and a sensor in testing machine. I receive from a sensor continually a data like this:
0.00;0.966458;4.75;0.000160
0.00;0.976958;4.75;0.000160
S reached (1)
0.00;0.986958;4.75;0.000160
0.00;1.001051;-2.25;0.000160
Each second I receive from a sensor several lines of "strings". My goal: as soon the second value in a line 0.00;0.966458;4.75;0.000160 is >= than specific value (e.g. 0.98) the server shall send the next command to machine.
Part of my code:
while True:
data1, address = socket.recvfrom(1024)
data1 = data1.decode("utf-8").strip()
s = round(float(data1[5:13]), 2)
print(s)
if s >= float(0.98):
print("hello") # here shall be the next command for machine
break
The problem is, that machine send me some times
S reached (1)
This cannot be converted to float. I get error mesage:
ValueError: could not convert string to float: 'ched (1)'
Is it possible to skip or not consider the line S reached (1) in a loop , and just check the next one?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
