3

私を始めるためのいくつかの指針を探しています。

左手にはICSを実行しているSGS2があります。SL4Aを起動して実行し、Python2.6.2をインストールしました

私の右手には、一般的な中国のBluetoothRFIDリーダーがあります。それは動作し、タグを読み取り(ディスプレイがあります)、電話とペアリングされます。

私は彼らにうまくプレイしてもらいたいです-私はデバイスを監視し続け、送信されるコードをキャプチャする何かをスクリプト化したいです。

私はPythonの専門家ではありませんが、Webサーバー上で単純なI / Oジョブを構築するためにしばらくの間それを使用しているので、自分の道を見つけることができます。

ただし、異常なことに、これを実行するのに実際の問題が発生しています。永続的な接続を確立して出力を監視する最初のステップを乗り越えるための「BluetoothとSL4Aの使用を開始する」リソースが見つかりません。

任意のヒント?

4

1 に答える 1

8

必要なのはBluetoothファサードのようです。これがあなたに役立つかもしれないBluetoothに関連するいくつかのコマンドです:

bluetoothAccept
bluetoothActiveConnections
bluetoothConnect
bluetoothDiscoveryCancel
bluetoothDiscoveryStart
bluetoothGetConnectedDeviceName
bluetoothGetLocalAddress
bluetoothGetLocalName
bluetoothGetRemoteDeviceName
bluetoothGetScanMode
bluetoothIsDiscovering
bluetoothMakeDiscoverable
bluetoothRead
bluetoothReadBinary
bluetoothReadLine
bluetoothReadReady
bluetoothSetLocalName
bluetoothStop
bluetoothWrite
bluetoothWriteBinary
checkBluetoothState
toggleBluetoothState


これらのコマンドのいずれかを呼び出すには、次のようにします。

import android
droid = android.Android()
#call your commands with droid.bluetoothcommand
droid.bluetoothDiscoveryStart()
#or
droid.toggleBluetoothState(True)


これはいくつかのBluetooth関数の例で、SL4Aに含まれていますが、わかりやすくするためにコメントを追加しました。

import android #for bluetooth functions
import time #for waiting

#get everything setup
droid = android.Android()

#turn on bluetooth
droid.toggleBluetoothState(True)

#ask user
droid.dialogCreateAlert('Be a server?')
droid.dialogSetPositiveButtonText('Yes')
droid.dialogSetNegativeButtonText('No')
droid.dialogShow()

#get user response to question
result = droid.dialogGetResponse()

#if the result is 'Yes' ('positive') then is_server is set to True
is_server = result.result['which'] == 'positive'

if is_server:
  #so if is_server is true make the device discoverable and accept the next connection
  droid.bluetoothMakeDiscoverable()
  droid.bluetoothAccept()
else:
  #attempts to connect to a device over bluetooth, the logic being that if the phone
  #is not receiving a connection then the user is attempting to connect to something
  droid.bluetoothConnect()


if is_server:
  result = droid.getInput('Chat', 'Enter a message').result #Gets a message to send 
  #via bluetooth
  if result is None:
    droid.exit() #exit if nothing is in the message
  droid.bluetoothWrite(result + '\n') #otherwise write the message

while True: #receives a message
  message = droid.bluetoothReadLine().result
  droid.dialogCreateAlert('Chat Received', message)
  droid.dialogSetPositiveButtonText('Ok')
  droid.dialogShow()
  droid.dialogGetResponse()
  result = droid.getInput('Chat', 'Enter a message').result
  if result is None:
    break
  droid.bluetoothWrite(result + '\n')

droid.exit()


最後に、Bluetoothコマンドの完全なリストについては、http://code.google.com/p/android-scripting/wiki/ApiReferenceを確認し、Bluetoothファサードまでスクロールダウンしてください。頑張ってください!

于 2012-08-22T01:36:29.610 に答える