[maemo-developers] Connecting RS232 devices to N800 hosting OS2008
From: Ryan Pavlik abiryan at ryand.netDate: Thu Jan 31 08:33:24 EET 2008
- Previous message: Connecting RS232 devices to N800 hosting OS2008
- Next message: Media player on N770
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Have you checked the permissions on the device file to ensure that your
user ("user") has write permissions (and/or tried running this as root?)
Ryan
James Kemp wrote:
> 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)
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> maemo-developers mailing list
> maemo-developers at maemo.org
> https://lists.maemo.org/mailman/listinfo/maemo-developers
>
- Previous message: Connecting RS232 devices to N800 hosting OS2008
- Next message: Media player on N770
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
