summaryrefslogtreecommitdiffstats
path: root/serial/test-serial
blob: 06e5da552a6809d3027293d85bfe3c5f1050b2d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python

import sys
import time
import dbus

bus = dbus.SystemBus()

manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'),
							'org.bluez.Manager')

conn = manager.ActivateService('serial')

serial = dbus.Interface(bus.get_object(conn, '/org/bluez/serial'),
						'org.bluez.serial.Manager')

if (len(sys.argv) < 2):
	print "Usage: %s <address> [service]" % (sys.argv[0])
	sys.exit(1)

address = sys.argv[1]

if (len(sys.argv) < 3):
	service = "spp"
else:
	service = sys.argv[2]

uuidbase = "-0000-1000-8000-00805F9B34FB"

if (service == "spp"):
	service = "00001101" + uuidbase

if (service == "dun"):
	service = "00001103" + uuidbase

device = serial.ConnectService(address, service)

print "Connected %s to %s" % (device, address)

print "Press CTRL-C to disconnect"

try:
	time.sleep(1000)
	print "Terminating connection"
except:
	pass

serial.DisconnectService(device)