diff --git a/FORZA_METHODS b/FORZA_METHODS new file mode 100644 index 0000000..e69de29 diff --git a/OutGaugeInterpreter.py b/OutGaugeInterpreter.py index 1f8cf4b..97dad3e 100644 --- a/OutGaugeInterpreter.py +++ b/OutGaugeInterpreter.py @@ -1,17 +1,35 @@ import socket import struct import serial +import time from GAME_METHODS import * ##import BEAMNG_FILES as BEAM - -toPi=serial.Serial('COM5',115200) #connect to arduino +COM_PORT = 'COM5' UDP_IP = "127.0.0.1" UDP_PORT = 4444 -sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) -sock.bind((UDP_IP,UDP_PORT)) -print("waiting for data:\n") +connectedArduino = False +connectedWebSocket = False + +while connectedWebSocket == False: + try: + sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) + sock.bind((UDP_IP,UDP_PORT)) + connectedWebSocket = True + except: + print("please check you are able to open the socket on this system") + exit() + +while connectedArduino == False: + try: + toPi=serial.Serial(COM_PORT,115200) #connect to arduino + connectedArduino = True + except: + print("please check connection to arduino and verify the correct COM port") + time.sleep(1) + +print("ready:\n") while True: