I am new to python and I am having to code my 1st task in python. I promise that I will learn it inside out after I finish this but I need your help now.
My code is currently looks like this:
comSocket.send("\r")
sleep(1)
comSocket.send("\r")
sleep(2)
comSocket.settimeout(8)
try:
comSocket.recv(256)
except socket.timeout:
errorLog("[COM. ERROR] Station took too long to reply. \n")
comSocket.shutdown(1)
comSocket.close()
sys.exit(0)
comSocket.send("\r\r")
sleep(2)
comSocket.settimeout(8)
try:
comSocket.recv(256)
except socket.timeout:
errorLog("[COM. ERROR] Station took too long to reply. \n")
comSocket.shutdown(1)
comSocket.close()
sys.exit(0)
errorLog is another method. I want to rewrite this code by making a new method so that I can pass the message, reference to the socket and then return what I receive from the socket.
Any help?
Thank you 🙂
A simple solution would be