2 """Use the TCPSocket class to establish a serial connection with a compatible device via USB port.""" 4 from __future__
import print_function
10 """Establish a TCP/IP connection with a connected device.""" 13 Initialize reader class for serial connection. 14 :param host: String: IP address of the device you want to communicate with 15 :param port: Int (default=10001): port to use for the connection 22 self.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
23 self.sock.connect((self.
host, self.
port))
26 """Open a socket to establish TCP/IP connection.""" 29 self.sock.connect((self.
host, self.
port))
31 print(
'Unable to open socket connection with: ' + self.
host +
', ' + self.
port)
34 """Close the socket.""" 37 self.sock.shutdown(socket.SHUT_RDWR)
40 print(
'Unable to close socket connection with: ' + self.
host +
', ' + self.
port)
44 Send message to the socket. 45 :param msg: String: message to be sent to the socket 50 print(
'Unable to send message to socket.')
54 Return a single line from the TCP stream with a custom end-of-line character. 55 :param eol_character: Bytes: character or sequence to use as end-of-line character. 56 :return: Bytes: the most recent line that has been sent via the socket connection 72 if line[-leneol:] == eol:
def __init__(self, host, port=10001)
def get_line(self, eol_character)