added safety checking so the program doesnt crash when no arduino attached
This commit is contained in:
parent
cec09d6bcb
commit
e55927dbe2
2 changed files with 23 additions and 5 deletions
0
FORZA_METHODS
Normal file
0
FORZA_METHODS
Normal file
|
|
@ -1,17 +1,35 @@
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import serial
|
import serial
|
||||||
|
import time
|
||||||
from GAME_METHODS import *
|
from GAME_METHODS import *
|
||||||
##import BEAMNG_FILES as BEAM
|
##import BEAMNG_FILES as BEAM
|
||||||
|
|
||||||
|
COM_PORT = 'COM5'
|
||||||
toPi=serial.Serial('COM5',115200) #connect to arduino
|
|
||||||
UDP_IP = "127.0.0.1"
|
UDP_IP = "127.0.0.1"
|
||||||
UDP_PORT = 4444
|
UDP_PORT = 4444
|
||||||
|
|
||||||
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
connectedArduino = False
|
||||||
sock.bind((UDP_IP,UDP_PORT))
|
connectedWebSocket = False
|
||||||
print("waiting for data:\n")
|
|
||||||
|
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:
|
while True:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue