Merge branch 'bt' into 'master'
Linux bluetooth rfcomm support without attaching to a /dev/rfcommN device file See merge request py_ren/pyren!15
This commit is contained in:
commit
7805333b58
@ -136,7 +136,7 @@ class Port:
|
|||||||
else try to open serial port
|
else try to open serial port
|
||||||
"""
|
"""
|
||||||
|
|
||||||
portType = 0 # 0-serial 1-tcp 2-androidBlueTooth
|
portType = 0 # 0-serial 1-tcp/bt 2-androidBlueTooth
|
||||||
ipaddr = '192.168.0.10'
|
ipaddr = '192.168.0.10'
|
||||||
tcpprt = 35000
|
tcpprt = 35000
|
||||||
portName = ""
|
portName = ""
|
||||||
@ -160,7 +160,20 @@ class Port:
|
|||||||
|
|
||||||
portName = portName.strip ()
|
portName = portName.strip ()
|
||||||
|
|
||||||
if re.match (r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}$", portName):
|
if re.match (r"^[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}$", portName):
|
||||||
|
try:
|
||||||
|
self.macaddr = portName
|
||||||
|
self.channel = 1
|
||||||
|
self.portType = 1
|
||||||
|
self.hdr = socket.socket (socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
|
||||||
|
self.hdr.settimeout(10)
|
||||||
|
self.hdr.connect ((self.macaddr, self.channel))
|
||||||
|
self.hdr.setblocking (True)
|
||||||
|
except Exception, e:
|
||||||
|
print " \n\nERROR: Can not connect to Bluetooth ELM\n\n", e
|
||||||
|
mod_globals.opt_demo = True
|
||||||
|
sys.exit()
|
||||||
|
elif re.match (r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}$", portName):
|
||||||
try:
|
try:
|
||||||
self.ipaddr, self.tcpprt = portName.split (':')
|
self.ipaddr, self.tcpprt = portName.split (':')
|
||||||
self.tcpprt = int (self.tcpprt)
|
self.tcpprt = int (self.tcpprt)
|
||||||
@ -217,11 +230,12 @@ class Port:
|
|||||||
'''
|
'''
|
||||||
if self.portType != 1: return
|
if self.portType != 1: return
|
||||||
|
|
||||||
self.hdr.close()
|
if not hasattr(self, 'macaddr'):
|
||||||
self.hdr = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
|
self.hdr.close()
|
||||||
self.hdr.setsockopt (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
self.hdr = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.hdr.connect ((self.ipaddr, self.tcpprt))
|
self.hdr.setsockopt (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||||
self.hdr.setblocking (True)
|
self.hdr.connect ((self.ipaddr, self.tcpprt))
|
||||||
|
self.hdr.setblocking (True)
|
||||||
|
|
||||||
self.write("AT\r")
|
self.write("AT\r")
|
||||||
self.expect(">",1)
|
self.expect(">",1)
|
||||||
@ -392,7 +406,7 @@ class Port:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.portType == 1: # wifi is not supported
|
if self.portType == 1: # wifi is not supported
|
||||||
print "ERROR - wifi do not support changing boud rate"
|
print "ERROR - wifi/bluetooth do not support changing boud rate"
|
||||||
return
|
return
|
||||||
|
|
||||||
# stop any read/write
|
# stop any read/write
|
||||||
|
Loading…
x
Reference in New Issue
Block a user