Python Forum
Sockets interferring with USB ? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Sockets interferring with USB ? (/thread-32959.html)



Sockets interferring with USB ? - epif18 - Mar-19-2021

I've written a program to create a server socket to interface with an embedded client socket in a program (stellarium) running on the same PC. Works great, I can receive and send data to stellarium. But I also want to read and process data from an arduino retrieved from the arduino via the USB. But the socket software seems to prevent reading the USB. The server routine continues to interface with stellarium but I can't read the arduino from the USB. I tried myserver_socket.setblocking(0) but no luck. Am I going to have to learn threading? The "?" highlighted block does not work even after the server receives data. Argh
Thanks
Mark

open_sockets = []

pc2Stell_socket = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
pc2Stell_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

# Configure Stellarium telescope control to use "localhost" and
# port 10001 (client port and name)

pc2Stell_socket.bind( ("localhost", 10001) )
pc2Stell_socket.setblocking(0) # doesn't help !!!
pc2Stell_socket.listen(5)
print(pc2Stell_socket.getblocking())

ser = serial.Serial('COM6',9600) # pick up data from arduino.

while true:
rlist, wlist, xlist = select.select( [pc2Stell_socket] + open_sockets, [], [] )

print("==============================================================")
# iterate on rlist once the read event occurs
print("done waiting")
for i in rlist:
? arduinoCoords = ser.readline()
? if(arduinoCoords[0]==97):
? TeleAz = arduinoCoords[2:-2]
? if(arduinoCoords[0]==98):
? TeleElev = arduinoCoords[2:-2]

? print(float(TeleAz), float(TeleElev))
if i is pc2Stell_socket:
# at this point i becomes a socket object. See the i.send() and i.recv()
new_socket, addr = pc2Stell_socket.accept()
open_sockets.append(new_socket)
print("Connected")
etc. ******************