[maemo-developers] Connecting RS232 devices to N800 hosting OS2008

From: James Kemp j.kemp at alliedtranstech.com
Date: Thu Jan 31 06:23:46 EET 2008
I'm using a N810, but the problem of connecting a RS232 device is probably
the same.

I'm getting close to getting a RS232 connection working using Bluetooth and
Python2.5. The code below is getting me close. I can receive RS232 string
over Bluetooth using this code. I just can't seem to figure out how to send
string out. If I try and use PySerial package I get an error when trying to
open the port.

#! /usr/bin/env python2.5
import dbus
import time
import sys
import thread
#import serial

PortOpen = 0
ser = ""

#
=============================================================================
def OpenPort ( COM_Port ):
    global ser, PortOpen
    try:
    print "Opening %s port" % COM_Port
    #ser = serial.Serial( COM_Port, 115200, timeout=0, parity=
serial.PARITY_NONE, rtscts=0)
        ser = open( COM_Port, 'r+' )
        PortOpen = 1
    except:
        print "Error opening serial port."
        exit()


#
=============================================================================
def CommThread ( tid ):
    """ This function is designed to be run as a thread task. """
    global gTID, PortOpen
    gTID = tid
    i = 0
    while PortOpen:
        s = ser.readline( ).strip( '\r\n' )
        print s
    print "CommThread Ending %d" % PortOpen

bus = dbus.SystemBus()
bmgr = dbus.Interface( bus.get_object('org.bluez', '/org/bluez'), '
org.bluez.Manager')
bus_id = bmgr.ActivateService('serial')
serial = dbus.Interface(bus.get_object( bus_id, '/org/bluez/serial'), '
org.bluez.serial.Manager')

# Service connection, read the serial API to check the available patterns
address = "00:01:95:06:CF:88"
service = "spp"

# Bind to the default local adapter
device = serial.ConnectService( address, service )
print "Connected %s to %s" % (device, address)

time.sleep(1)
OpenPort( device )
thread.start_new( CommThread, (1234,) )

print "Press CTRL-C to disconnect"

while(1):
    s = raw_input()
    print "Writting %s" % s
    ser.write(s)
    ser.flush()

serial.DisconnectService(device)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maemo.org/pipermail/maemo-developers/attachments/20080130/7aed55e4/attachment.htm 
More information about the maemo-developers mailing list