Skip to content

Commit

Permalink
bugfix after last mod the serial port did not work anymore..,online_u…
Browse files Browse the repository at this point in the history
…sersDict will be loaded in usersDict at startup..
  • Loading branch information
marco committed Jan 4, 2017
1 parent 07c81fc commit 28c1d35
Show file tree
Hide file tree
Showing 21 changed files with 678 additions and 86 deletions.
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ versione4.53 iniziato ad usare pythonserial come libraria dopo test fatti con
modified webserver.py now the nodes will not be able to change a object status
if the current status is onoswait if object_dict[objName].getStatus()=="onoswait
now onos will not crash if there is not a serial port connected, changed Serial_connection_Handler.py

bugfix after last mod the serial port did not work anymore..
online_usersDict will be loaded in usersDict at startup..


(110, 'Connection timed out');;;
Expand Down
50 changes: 21 additions & 29 deletions scripts_folder/Serial_connection_Handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,37 @@ def __init__(self):
self.exit=0
self.uart=self.connectToPort()
self.working=1
self.exluded_port_list
i=0
while (self.uart ==0) : #while port is not connected retry to connect banana to make it clever..
print ("retry serial connection number:"+str(i))
self.uart=self.connectToPort()
if self.uart==1:
break
time.sleep(1)
if i>2: #after n tries i increase the time between the tries
time.sleep(10)
if i>4: #after n tries i increase the time between the tries
time.sleep(30)
self.exluded_port_list=[]
self.connectSerialPort()

if i >0:
if (self.searchForSerialCable(self.exluded_port_list )=="null"):
print ("error serial connection, no serial ports found")
self.uart==-1
self.working=0
return(-1)

#return(self.connectSerialPort())

i=i+1


def reconnectSerialPort():
print("reconnectSerialPort() executed")
def connectSerialPort(self):
print("connectSerialPort() executed")
self.exluded_port_list=[]
self.uart=self.connectToPort()
self.working=1
i=0
while (self.uart ==0) : #while port is not connected retry to connect banana to make it clever..
print ("retry serial connection number:"+str(i))
self.uart=self.connectToPort()
if self.uart==1:
return(1)
break
time.sleep(1)
if i>2: #after 60 tries i increase the time between the tries
time.sleep(30)
if i>4: #after 120 tries i increase the time between the tries
time.sleep(60)

if i >10:
if i >1:
if (self.searchForSerialCable(self.exluded_port_list )=="null"):
print "error serial reconnection, no serial ports found"
print ("error serial connection, no serial ports found")
self.uart==-1
self.working=0
return(-1)

i=i+1


return(1)#the connection was successful
def connectToPort(self):
print("connectSerialPort() executed")
port=self.searchForSerialCable(self.exluded_port_list )
Expand Down Expand Up @@ -109,18 +93,26 @@ def searchForSerialCable(self,list_of_port_to_not_use):
list_of_dev=os.listdir("/dev")

for dev in list_of_dev:
if (dev.find("ttyATH0")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)
if (dev.find("ttyATH")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyUSB0")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)
if (dev.find("ttyUSB")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyACM0")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)
if (dev.find("ttyACM")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyS0")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)
if (dev.find("ttyS")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)

Expand Down
Binary file modified scripts_folder/Serial_connection_Handler.pyc
Binary file not shown.
29 changes: 17 additions & 12 deletions scripts_folder/arduinoserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(self, serialport, bps):


self.ser.open()




Expand Down Expand Up @@ -186,7 +186,8 @@ def read_data(self): # thread function
print "I tried to reconnect serial port from arduinoserial module but I failed"
errorQueue.put("I tried to reconnect serial port from arduinoserial module but I failed")
#priorityCmdQueue.put( {"cmd":"reconnectSerialPort"})
self.exit=1
return()



if self.exit==1:
Expand Down Expand Up @@ -215,6 +216,7 @@ def read_data(self): # thread function
except Exception, e :
print "can't write to uart"+str(e.args)
errorQueue.put( "can't write to uart"+str(e.args) )
return()

try:
self.ser.flushOutput()
Expand All @@ -238,17 +240,18 @@ def read_data(self): # thread function
byte=-1
self.status=0
continue

if byte=="\x00":
continue

if (ord(byte)==10): # 10 is the value for new line (\n) end of packet on incoming serial buffer
print "end of serial packet for /n"
break
else:
#print "in byte="+byte+" end of in byte"
buf=buf+byte

try:
if (ord(byte)==10): # 10 is the value for new line (\n) end of packet on incoming serial buffer
print "end of serial packet for /n"
break
else:
#print "in byte="+byte+" end of in byte"
buf=buf+byte
except: #not a string , probably is null
continue

if len(buf)>5:
waitTowriteUntilIReceive=1
Expand Down Expand Up @@ -523,7 +526,9 @@ def isOpen(self):


def __del__(self):
print "class arduinoserial destroyed"
print ("class arduinoserial destroyed")
#reconnect_serial_port_enable==time.time()+60

# try:
# os.close(self.fd)
# except:
Expand Down
Binary file modified scripts_folder/arduinoserial.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions scripts_folder/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def importConfig():
mail_whiteList=readConfigurationsFromSavedFile(u"mail_whiteList")
online_server_enable=readConfigurationsFromSavedFile(u"online_server_enable")
online_usersDict.update(readConfigurationsFromSavedFile(u"online_usersDict"))
usersDict.update(online_usersDict)
timezone=readConfigurationsFromSavedFile(u"timezone")
enable_onos_auto_update=readConfigurationsFromSavedFile(u"enable_onos_auto_update")
scenarios_enable=readConfigurationsFromSavedFile(u"scenarios_enable")
Expand Down
Binary file modified scripts_folder/conf.pyc
Binary file not shown.
6 changes: 2 additions & 4 deletions scripts_folder/config_files/cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
"priority": 0,
"pw": "1234",
"user_mail": "elettronicaopensource@gmail.com"
}

},
"mauro": {
"mail_control_password": "onosm",
"priority": 0,
"pw": "12345678",
"user_mail": "elettronicaopensource@gmail.com"
}

},
"scenarios_enable": 1,
"timezone": "CET-1CEST,M3.5.0,M10.5.0/3"
}
}

0 comments on commit 28c1d35

Please sign in to comment.