Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[+] benqprojector/benqprojector.py - fixed telnet network support (te… #22

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion benqprojector/benqprojector.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class BenQProjector(ABC):
connection = None
busy = False
_init: bool = True
is_network = False

model = None
_mac = None
Expand Down Expand Up @@ -221,6 +222,8 @@ def __init__(
"""
assert connection is not None

self.is_network = isinstance(connection, BenQTelnetConnection)

self.connection = connection
self.model = model_hint

Expand Down Expand Up @@ -478,12 +481,20 @@ def _wait_for_prompt(self) -> bool:
# Clean input buffer
self.connection.reset()

sent_cr = False

start_time = datetime.now()
while True:
response = self.connection.readline()
if response == b"":

if self.is_network and sent_cr:
return True

self.connection.write(b"\r")
self.connection.flush()

sent_cr = True
elif response[-1:] == b">":
return True
elif response.strip(string.whitespace + "\x00") == b"":
Expand All @@ -502,12 +513,17 @@ def _wait_for_prompt(self) -> bool:

def _read_response(self) -> str:
response = b""

responses = [b"\n", b"\r", b"\x00"]
if self.is_network:
responses = [b"\n", b"\r", b"\x00", b"*"]

last_response = datetime.now()
while True:
_response = self.connection.readline()
if len(_response) > 0:
response += _response
if any(c in _response for c in [b"\n", b"\r", b"\x00"]):
if any(c in _response for c in responses):
response = response.decode()
# Cleanup response
response = response.strip(string.whitespace + "\x00")
Expand Down