Wiley.Mobile.Python.Rapid.prototyping.of.applications.on.the.mobile.platform.Dec.2007 (779889), страница 54
Текст из файла (страница 54)
Download the script shell package marked as ‘unsignedfreedevcert’, sign it with your devcert and install it.•If you need manufacturer-approved capabilities, then you will needto obtain a manufacturer-approved devcert and recompile the PyS60script shell (interpreter) to have these capabilities. The Python for S60development team can provide advice in these cases.A.5.2 DeploymentYou can distribute your PyS60 programs in two main forms: as plainPython scripts or packaged into SIS packages signed in different ways. Bothhave their own advantages and disadvantages.
The choice of deploymentmethod depends on the capabilities you need and the type and size ofyour audience.•Distributing as a plain script is simple for the developer and makesit easy for users to edit the scripts without extra tools. However, theusers must run the program through the script shell, there is no wayfor the program to have its own icon in the application menu. Also,the capabilities available depend on the capabilities of the script shell;if the program requires more than user-grantable capabilities, peoplewho wish to test it must obtain their own devcert. This method issuitable for only for development.•Distributing as a self-signed SIS package is easy for the users to installand use – the program can have an application icon in the applicationmenu.
However, only user-grantable capabilities are available andwarnings are displayed at installation time. This method also requiresthe developer to install additional tools. Some rare phone variants288PLATFORM SECURITYdo not allow the installation of self-signed packages. This method isconvenient for both testing and deployment and can be used as longas the program doesn’t require capabilities that aren’t user-grantable.•Distributing as an unsigned SIS package that testers sign with theirown devcert allows the program to use user-grantable and free devcertcapabilities and have an icon in the application menu. However, theusers must obtain their own devcert and use the SDK signing tools toinstall the program.
This method is suitable for testing with advancedusers, but not for actual deployment.•Distributing as a Symbian Signed SIS package means that all requiredcapabilities are available and the program will install on any device.Some websites only accept Symbian Signed software for distribution.However, testing takes time and money (unless using the freewaresigning process, which takes only time). This method is suitable fordeployment of a finished program to the mass market.Appendix BBluetooth ConsoleBluetooth console makes it possible to use the PyS60 interactively fromyour PC. Instead of the typical cycle of ‘edit, upload, test’, you canevaluate lines of code in real-time on the phone.This approach is particularly useful for experimenting with the standardmodules. You can try out different functions and parameter combinationswithout having to edit or upload any files.
Since the lines are executedon the actual device, you gain a realistic understanding of how longvarious functions take to execute and how different UI elements look onthe screen.It is also a rapid way to debug custom modules by you and otherthird-party developers. You can upload a new module to the phone,import it into the Bluetooth console and start testing its functions oneby one.
If exceptions occur, they are much easier to parse on the largedisplay of your PC than on the phone.If you are interested in some hard-core hacking, note that you canautomate testing by the Bluetooth console since, after all, the console isjust receiving lines of text from the PC. Instead of you typing the lines, theycould be generated by, say, a Python script running on your computer.This might open up new possibilities for rapid prototyping and automatedtesting.If interacting with the PyS60 shell programmatically from your PCsounds useful to you, have a look at the following files that are included inthe PyS60 source distribution: extras/examples/simplebtconsole.py and core/Lib/btconsole.py.
The former is a simplified implementation of the Bluetooth console and the latter the actual implementation of it. The PyS60 source distribution can be found at http://sourceforge.net/projects/pys60/.B.1 Setting up Serial CommunicationTo use the Bluetooth console, or communicate with the PC over Bluetoothfrom your own PyS60 applications, an RFCOMM serial port must be set290BLUETOOTH CONSOLEup on the PC side. On Mac OS X and Linux, the serial port is just a specialfile under the /dev directory. On Windows, a COM port is reserved forthis purpose. In the following sections, we explain how to set up theseinterfaces.First, set up the RFCOMM port as instructed in one of the sectionsB.1.1 to B.1.3.
After you are finished with the setup, you can see if theserial port is visible to your phone as follows:1.Copy Example 55 from Chapter 7 to your phone in the usual manner.2.Run the script. You should see the name of your computer on the listof Bluetooth devices nearby. If you cannot see it, your PC cannot bediscovered. Check any settings on your PC’s Bluetooth configurationthat might affect how other devices see your computer.
Check alsothat Bluetooth is actually switched on.3.Choose your computer from the list. The script should print out a listof services found on the PC. The list should include an entry suchas ‘Serial Port’ (or ‘PyBook’, on OS X). If you can see a service likethat on the list, the serial port is set up correctly. If not, the service iseither not visible to this phone or it is not advertised correctly by thePC and you should re-check the settings.B.1.1 WindowsThe following steps should work for at least Windows 2000, 2003 andXP.
Because of differences in Bluetooth drivers, in some cases the processmay not be this straightforward and might require some further tweaking.In any case, the manual for either your computer or your Bluetoothdongle should explain how to set up the serial port for Bluetooth.B.1.21.Open the Control Panel. Open Bluetooth Configuration.2.Select the Accessibility tab and select the ‘Let Other BluetoothDevices Discover this Computer’ option.3.For the panel that specifies ‘Devices allowed to connect to thiscomputer’, you can choose ‘All devices’ for testing. Note that thisis insecure if you leave it on. Alternatively, you may select ‘AddDevice’ and add your phone to the list.4.Select the Local Services tab and select ‘Add Serial Device’. Chooseany available COM port and keep its number in mind.
You will needit later.Mac OS XThe following steps create a special file that can be used to communicatewith the phone:SETTING UP SERIAL COMMUNICATION2911. Open System Preferences dialog. Select Bluetooth.2. Select the Settings tab and enable the ‘Discoverable’ box.3. Select the Devices tab and, unless you have done this before, pairyour Mac with your phone using the ‘Set up new device’ button.Select the Sharing tab, select Add Serial Port Service and name it‘PyBook’ and for type, choose RS-232.After you have gone through the above steps, you should see a dialoglike the one in Figure B.1, which includes the new ‘PyBook’ item. As aresult, a file at /dev/tty.pybook has been created that provides anRFCOMM interface.Figure B.1B.1.3RFCOMM setup on Mac OS XLinuxSome Linux distributions may provide a graphical control panel that letsyou configure the RFCOMM port, similarly to Mac OS X.
However, herewe perform the configuration on the command line, as this works onany distribution that has the Bluetooth tools (package bluez-utils inmany distributions) installed.Note that you should establish a Bluetooth pairing between yourcomputer and the phone – see Section 7.1 for instructions.
When you292BLUETOOTH CONSOLEhave paired the devices successfully, you can execute the followingcommands as the root user:•hciconfig hci0 piscan – sets the device discoverable•sdptool add–channel=3 SP – advertises the available serial port onchannel 3.•rfcomm listen/dev/rfcomm0 3 – listens for incoming connections onchannel 3. Note that this command does not return until you connectto the PC and close the connection on the phone side.You should open another terminal in which you can run a serverapplication of your own or the Bluetooth console.