久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='RaGfA'></small><noframes id='RaGfA'>

    <i id='RaGfA'><tr id='RaGfA'><dt id='RaGfA'><q id='RaGfA'><span id='RaGfA'><b id='RaGfA'><form id='RaGfA'><ins id='RaGfA'></ins><ul id='RaGfA'></ul><sub id='RaGfA'></sub></form><legend id='RaGfA'></legend><bdo id='RaGfA'><pre id='RaGfA'><center id='RaGfA'></center></pre></bdo></b><th id='RaGfA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RaGfA'><tfoot id='RaGfA'></tfoot><dl id='RaGfA'><fieldset id='RaGfA'></fieldset></dl></div>

  • <legend id='RaGfA'><style id='RaGfA'><dir id='RaGfA'><q id='RaGfA'></q></dir></style></legend><tfoot id='RaGfA'></tfoot>

          <bdo id='RaGfA'></bdo><ul id='RaGfA'></ul>

        如何在 Kivy 中將 android.bluetooth.socket 輸入流轉換為

        how to convert android.bluetooth.socket inputstream to python string in Kivy?(如何在 Kivy 中將 android.bluetooth.socket 輸入流轉換為 python 字符串?)

      1. <legend id='G0OAO'><style id='G0OAO'><dir id='G0OAO'><q id='G0OAO'></q></dir></style></legend>
            • <bdo id='G0OAO'></bdo><ul id='G0OAO'></ul>
              <tfoot id='G0OAO'></tfoot>

              1. <i id='G0OAO'><tr id='G0OAO'><dt id='G0OAO'><q id='G0OAO'><span id='G0OAO'><b id='G0OAO'><form id='G0OAO'><ins id='G0OAO'></ins><ul id='G0OAO'></ul><sub id='G0OAO'></sub></form><legend id='G0OAO'></legend><bdo id='G0OAO'><pre id='G0OAO'><center id='G0OAO'></center></pre></bdo></b><th id='G0OAO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='G0OAO'><tfoot id='G0OAO'></tfoot><dl id='G0OAO'><fieldset id='G0OAO'></fieldset></dl></div>
                    <tbody id='G0OAO'></tbody>

                  <small id='G0OAO'></small><noframes id='G0OAO'>

                  本文介紹了如何在 Kivy 中將 android.bluetooth.socket 輸入流轉換為 python 字符串?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在開發 Kivy 應用程序.

                  I'm working on Kivy app.

                  因為我想從藍牙適配器獲取數據,所以我使用了下面的代碼.

                  Since I want to get data from bluetooth adapter, I used code below.

                  from kivy.app import App
                  from kivy.uix.label import Label
                  from kivy.uix.scatter import Scatter
                  from kivy.properties import ObjectProperty,NumericProperty
                  from kivy.clock import Clock
                  from kivy.lang import Builder
                  from jnius import cast,autoclass
                  from kivy.logger import Logger
                  
                  BluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter')
                  bufferedreader = autoclass('android.bluetooth.BluetoothAdapter')
                  BluetoothDevice = autoclass('android.bluetooth.BluetoothDevice')
                  BluetoothSocket = autoclass('android.bluetooth.BluetoothSocket')
                  InputStreamReader = autoclass('java.io.InputStreamReader')
                  BufferedReader = autoclass('java.io.BufferedReader')
                  UUID = autoclass('java.util.UUID')
                  StringBuilder = autoclass('java.lang.StringBuilder')
                  
                  Builder.load_string('''
                  <bluetooth>:
                      Button:
                          pos:root.width/3,root.height/2
                          text: root.data
                          size: (300,100)
                  
                  
                  ''')
                  
                  class bluetooth(Scatter):
                      socket = ObjectProperty(None,allownone = True)
                      data = ObjectProperty('getting data',allownone = True)
                      recv = ObjectProperty(None,allownone = True)
                      counter = NumericProperty(0)
                  
                      def change_data(self,dt):
                          Logger.info('Im in the change_data!!')
                          self.data = 'change_data'
                          paired_devices = BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray()
                          for device in paired_devices:
                              self.data = str(device.getName())
                              Logger.info('Im in the loop!!'+str(device))
                              if device.getName() == 'HC-06':
                  
                                  self.socket = device.createRfcommSocketToServiceRecord(UUID.fromString('00001101-0000-1000-8000-00805F9B34FB'))
                                  bufferedreader = BufferedReader(InputStreamReader(self.socket.getInputStream(),"UTF-8"))
                  
                                  StringBuilder.append(bufferedreader.read())
                                  self.data = StringBuilder.toString()
                  
                          #if self.socket == None:
                          #   pass
                          #else:
                          #   self.socket.connect()
                  class myApp(App):
                      def build(self):
                          bt = bluetooth()
                          Clock.schedule_interval(bt.change_data,1)
                          return bt
                  myApp().run()
                  

                  也許我錯過了一些代碼..我不知道如何將 bluetooth.socket 輸入流轉換為 python 字符串.有人可以幫忙嗎?

                  Maybe I missed some code.. I can't find out how to get bluetooth.socket inputstream to python string. Can someone please help?

                  推薦答案

                  我終于找到了一個似乎可行的解決方案.我有一個 Kivy 應用程序通過藍牙與基于 Arduino 的設備通信.在 Arduino 上,我使用 SerialCommand 庫來接收自定義命令并做出相應的響應.當命令在主線程中發送到我的 Arduino 時,我有一個帶有循環的第二個線程,它從我的藍牙套接字讀取 InputStream.來自 Arduino 的響應包含在 <> 中,當我得到正確的響應時,我會提取括號之間的文本并將其發送到我的主線程中的一個函數.我希望這對你有幫助.

                  I have finally find a solution that seems to work. I have a Kivy app communicating with an Arduino based device over Bluetooth. On the Arduino I use the SerialCommand library to recieve custom commands and respond accordingly. While the commands is send to my Arduino in the main thread, I have a second thread with a loop that reads the InputStream from my Bluetooth socket. The response from Arduino is enclosed with <>, and when I get a proper response I extract the text between the brackets and send it to a function in my mainthread. I hope this is helpful for you.

                  from kivy.clock import mainthread
                  import threading
                  import jnius
                  
                  def get_socket_stream(self, name):
                      paired_devices =  self.BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray()
                      socket = None
                      for device in paired_devices:
                          if device.getName() == name:
                              socket = device.createRfcommSocketToServiceRecord(
                              self.UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
                              reader = self.InputStreamReader(socket.getInputStream(), 'US-ASCII')
                              recv_stream = self.BufferedReader(reader)
                              send_stream = socket.getOutputStream()
                              break
                      socket.connect()
                      return recv_stream, send_stream
                  
                  def connect(self, *args):
                      device = self.config.get('bluetooth', 'bt_name')
                      try:
                          self.recv_stream, self.send_stream = self.get_socket_stream(device)
                      except AttributeError as e:
                          print e.message
                          return False
                      except jnius.JavaException as e:
                          print e.message
                          return False
                      except:
                          print sys.exc_info()[0]
                          return False
                  
                      threading.Thread(target=self.stream_reader).start()
                  
                  def stream_reader(self, *args):
                      stream = ''
                      while True:
                          if self.stop.is_set():
                              jnius.detach()
                              return
                          if self.recv_stream.ready():
                              try:
                                  stream = self.recv_stream.readLine()
                              except self.IOException as e:
                                  print "IOException: ", e.message
                              except jnius.JavaException as e:
                                  print "JavaException: ", e.message
                              except:
                                  print "Misc error: ", sys.exc_info()[0]
                  
                              try:
                                  start = stream.rindex("<") + 1
                                  end = stream.rindex(">", start)
                                  self.got_response(stream[start:end])
                              except ValueError:
                                  pass
                  
                  @mainthread
                  def got_response(self, response):
                      do something...
                  

                  這篇關于如何在 Kivy 中將 android.bluetooth.socket 輸入流轉換為 python 字符串?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)

                  • <bdo id='mUJAO'></bdo><ul id='mUJAO'></ul>

                      <i id='mUJAO'><tr id='mUJAO'><dt id='mUJAO'><q id='mUJAO'><span id='mUJAO'><b id='mUJAO'><form id='mUJAO'><ins id='mUJAO'></ins><ul id='mUJAO'></ul><sub id='mUJAO'></sub></form><legend id='mUJAO'></legend><bdo id='mUJAO'><pre id='mUJAO'><center id='mUJAO'></center></pre></bdo></b><th id='mUJAO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='mUJAO'><tfoot id='mUJAO'></tfoot><dl id='mUJAO'><fieldset id='mUJAO'></fieldset></dl></div>

                          <tbody id='mUJAO'></tbody>
                          <tfoot id='mUJAO'></tfoot>

                          1. <legend id='mUJAO'><style id='mUJAO'><dir id='mUJAO'><q id='mUJAO'></q></dir></style></legend>

                            <small id='mUJAO'></small><noframes id='mUJAO'>

                          2. 主站蜘蛛池模板: 国产a爽一区二区久久久 | 337p日本欧洲亚洲大胆 | 欧美福利视频 | 一级黄色片免费在线观看 | 青青久久 | 玖玖视频 | 九九免费观看视频 | 国产黄色在线观看 | 国产成人99久久亚洲综合精品 | 中文字幕在线视频观看 | 国产高清一区二区三区 | 亚洲日本视频 | 涩涩片影院 | 黄免费观看视频 | 日韩色在线 | 久久99精品久久久久蜜桃tv | 欧美日韩电影在线 | 成人黄在线观看 | 久久精品日产第一区二区三区 | 欧美a在线看 | 欧美成人激情 | av一区在线观看 | 亚洲三区视频 | 国产无人区一区二区三区 | 久久色视频 | 午夜精品久久久久久久久久久久久 | 免费观看成人鲁鲁鲁鲁鲁视频 | 国产成人免费视频网站视频社区 | www.婷婷| www免费视频 | av黄色免费在线观看 | 亚洲精品综合 | 在线一区视频 | 免费av一区二区三区 | 九色网址 | 色吧久久 | 欧美成人手机视频 | 黑人巨大精品欧美一区二区免费 | 中文字幕一区二区三区乱码在线 | 国产免费一区二区三区 | 久久久久久久一区二区三区 |