Dobry den.
Mam 10 separe programov ktore sa spustaju nezavysle na sebe. Nasledne komunikuju so zariadenim. Problem je ze nahodne sa mi obcas vyhadzuje hlaska = [WinError 10038] An operation was attempted on something that is not a socket
Restarujem komunikaciu a je to ok. Neviem prist na to v com je chyba lebo obcas to zbehne bez problemu obcas je tu ta chyba.
Pouzivam tento kod.
def connect_to_RFID(head):
global CONN_STATION_2_1
global RFID_Status
global cursor
print('Connecting on RFID head' + head)
RFID_OK_Counter = 0
try:
headnumber = str(head)
string = 'IP_CONN_STATION_2_'+head
SQL = "SELECT IP FROM RFID_Config WHERE ID = '"+head+"' "
cursor.execute(SQL)
RFID_IP = cursor.fetchone()[0]
print(RFID_IP)
CONN_STATION_2_1.connect((RFID_IP, RFID_Port))
print("RFID Station 2_1 Connection OK")
logging.warning('Station 2 Head '+RFID_Head_number_Int_Correct+' RFID Connection OK')
RFID_OK_Counter = RFID_OK_Counter + 1
time.sleep(1)
except Exception as e:
print(e)
print("RFID Station 2_1 Connection Fail")
logging.warning('Station 2 Head '+RFID_Head_number_Int_Correct+' RFID Connection Fail')
logging.warning(e)
time.sleep(1)
if (RFID_OK_Counter == 1):
RFID_Status = True
print('RFID Connection OK')
if (RFID_OK_Counter != 1):
RFID_Status = False
print('RFID Connection FAIL Restart in 3 second')
time.sleep(3)
def disconnect_from_rfid():
global CONN_STATION_2_1
global RFID_Status
CONN_STATION_2_1.close()
time.sleep(1)
CONN_STATION_2_1 = socket.socket()
time.sleep(1)
RFID_Status = False
print ('Connection is closed')
logging.warning('Station 2 '+RFID_Head_number_Int_Correct+' is disconnected')
a potom v kode mam
CONN_STATION_1.send(('$:08004110\r\n').encode())
data = CONN_STATION_1.recv(1024).decode()
jasne ze by sa dal ocesat o tom neskorsie ale nejde mi do hlavy co je tam zle. Co moze byt pricina tej chyby. tak 7 s 10 to ide ok. Vzdy len prvy krat ked sa chcem spojit a nasledne nieco poslat. Potom znova volam disconnect a connect a uz to funguje bez problemu. Ale prvy loop to obcas spadne a neviem preco.
Vie niekto poradit?