最简单的蓝牙操作步骤

来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 15:56 点击:
最简单的蓝牙操作步骤,一步一步教你如何操作,它的流程很清晰,而且也很容易理解,你可以试着做一下。。。


 Simple Bluetooth Communication

     In this article, I will try to explain the simple Bluetooth communication standards and show how you can create a simple wrapper class around Bluetooth technology. This article is for those peoples who want to write a J2ME Bluetooth application by understanding its API and protocols.
Wireless Technologies
    The most famous wireless technologies are infraree, Bluetooth, WiFi, and Zigbee. Infrared is the technology that you can see in TV remote controls or air conditioner remotes where the communication should be pointed to the target device. WiFi technology is used for strong and wide area communication where wireless communication can be made. Zigbee is the most recent technology; it's cheaper than all the other wireless media. Bluetooth technology is the most used temporary communication technology, especially inside mobile devices, palm tops, pocket PCs, and so forth. It can be used to exchange objects, packets, or a simple stream.
Bluetooth Communication Types
  
    There are three types of communication protocols defined inside Bluetooth technology:
OBEX: The "Object Exchange" communication protocol is used to exchange physical data such as files, images, and so on in binary format.
L2CAP: The "Logical Link Control and Adaptation Protocol" used to send packets between host and client.
RFCOMM: The "Radio Frequency COMMunication" is very easy and uncomplicated; it is used to stream simple data.
Java Bluetooth API

     Sun Java has introduced the Bluetooth JSR82 API package. The JSR82 API has capability to provide all three kinds of communications: either Obex, L2CAP, or RFCOMM. This article will focus on the simplest protocol, RFCOMM, and send only string data between the devices.
Client and Server

The technique to communicate any device will follow the good old-fashioned rule of Client and Server. You will open the Server and then wait for the client to connect; after that, the server and client both can communicate with each other easily. In Bluetooth, you have to do the same technique; the application must allow the user to select it as either the server or client.
Code and Explanation
1. Server

Every Bluetooth device contains the local Bluetooth object that helps communicate between devices. In JSR82, the LocalDevice.getLocalDevice(); function returns the object of the local Bluetooth device. The local device object should call the setDiscoverable(DiscoveryAgent.GIAC); function, in which the mode is set as GIAC. In simple words, by doing this you give permission to the current device to find other devices.

To open the Bluetooth connection, you have to build a Bluetooth URL string that will be called inside the Connector.open(URL) function; this function will return the StreamConnectionNotifier Object. The URL actually is the way to initialize the communication protocol for Bluetooth, just like on an Internet Explorer search box. You just type http://www.address.com, where http:// is the protocol and the rest is the address of the target place. In Bluetooth, you will do something like this:
     
Java代码 
<span style="font-size: small;">URL = "btspp://localhost:" + UUID + ";name=rfcommtest;authorize=true";</span>  

Here,

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Java编程语言的八大优点
      • JVM对象生命周期详细介绍
      • Java平台上的CRM系统
      • Java 算数测试小程序
      • Command(命令模式)
      • Java 一个简单的画图程序
      • Java环境 使用Resin在NT环境下配置JSP环境
      • Java 日历的小程序
      • Java 统计代码的小工具
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1