Problems encountered when developing Bluetooth in PC-side java, pcjava

Source: Internet
Author: User

Problems encountered when developing Bluetooth in PC-side java, pcjava

For project reasons, we need to develop a client that transmits data via Bluetooth on the computer. I use JAVA and JSME for development.

Client: Search for the Bluetooth signal, and find the corresponding Bluetooth signal to connect.

Server: the Bluetooth signal that the client needs to connect.

On the PC server side, an open source component BlueCove is also needed, which realizes the JSR-82 Java Bluetooth specification and shields the encapsulation of various functions of the local Bluetooth protocol stack at the underlying operating system level. The reason for this component is mainly because J2SE does not implement the JSR-82 specification protocol. I use a bluecove-2.0.3.jar.

You also need the jar package of commons-io. I use the 2.2 jar package.

Java Bluetooth API relies on java universal connection framework, which has always been a limitation of java Bluetooth API applications. However, it is recommended that GCF be added to J2SE. Java Bluetooth APIs make it possible to access more systems.

Java bluetooth API defines two packages: javax. bluetooth, the core of Java bluetooth API, and javax. obex for Object Exchange Protocol ).

Any Bluetooth Application has the following components: Stack initialization components, device management components, device discovery components, service discovery components, and communication components.

The JSR82 specification introduces two categories for device management: LocalDevice and RemoteDevice.

 

LocalDevice allows you to request static information of the bluetooth device. It relies on the javax. bluetooth. DeviceClass class to obtain the device type and the service type it provides.

 

RemoteDevice can be used to obtain information about a device in the adjacent Bluetooth zone (for example, the address of a remote Bluetooth device ). It can represent a remote device (for example, a device within the reachable range), and provides corresponding methods to obtain information about this device, including its Bluetooth address and name.

Each bluetooth device has a unique hardware address, just like the MAC address of a computer. You can set the device discovery level. By calling the setDiscoverable () method in the LocalDevice object, other Bluetooth devices can discover the current device.

Device discovery

Wireless devices require a mechanism to allow them to discover and access other devices. The DiscoveryAgent and DiscoveryListener interfaces of core Bluetooth APIs provide the necessary discovery services. You can obtain the list of accessible devices in three ways. The DiscoveryAgent. startInquiry () method sets the device to the query mode. to make full use of this mode, the application must specify an event listener to respond to the query-related events. When the query is completed or canceled, the DiscoveryListener. inquiryCompleted () method is called.

Service Discovery

Service Discovery allows you to discover nearby services, regardless of which device provides the service. The methods provided by DiscoveryAgent can be used to discover services on Bluetooth service devices and initialize service discovery transactions. Before a service can be discovered, you must register or broadcast the service on the Bluetooth service device. The service device is responsible for many tasks, including creating service records describing the services provided, accepting connections from clients, and adding new service records to the service discovery database (SDDB) of the service device.

The software I used is the ADT integrated development tool that I previously compiled for android. A 32-bit java development environment.

The PC uses a Bluetooth adapter installed with BlueSoleil _. 6. v6.4.249.

The following are my problems during PC development.

1. Because BlueCove has not been updated, this jar package can only be used in a 32-bit java environment. An error is reported in a 64-bit java development environment.

1. Port mismarch [4] and [5]

Note: The Bluetooth virtual port does not match the Bluetooth port on your PC.


Solution:

In "My device properties" of the Bluetooth adapter -- serial port -- only one serial port is left and the automatic connection is disabled. The connection direction is outbound.

Delete the remaining port numbers, or delete the Bluetooth directly through the classic Bluetooth interface and re-search for the connection.

2. connect failed

Solution:

If the driver is not installed properly, right-click the Device Manager and select install the driver online.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.