Introduction to infrared communication protocol
Infrared transmission technology has been greatly developed in recent years. The currently used home appliance remote control is almost all the infrared transmission technology. As the transmission mode of the wireless LAN, the greatest advantage of the infrared mode is not subject to radio interference, and its use is not limited by the National Wireless Management Committee. However, infrared rays are poor to non-transparent objects, resulting in transmission distances.
The infrared ray is an electromagnetic wavelength between 750 nm to 1 mm. Its frequency is higher than the microwave and below visible light, is a kind of human eye that is not seen. Infrared communication generally uses near-infrared rays in the infrared band, and the wavelength is between 0.75 um to 25um. After the Infrared Data Association (IRDA), in order to ensure that the infrared product of different vendors can achieve the best communication effect, the infrared communication protocol defines the wavelength of the optical wavelength employed by the infrared data communication within 850 to 900 nm.
IRDA standards include three basic specifications and protocols: Physical Layer Link Specification, Link Access Protocol: IRLAP and Link Management Protocol: IRLMP. The physical layer specification has developed the goals and requirements in infrared communication hardware design, IRLAP and IRLMP are two software layers, responsible for setting, managing, and maintaining the link. Based on IRLAP and IRLMP, IRDA has also released some higher-level infrared protocols, such as Tinytp, Irobex, Irbus, etc. (see Figure 1), such as Tinytp, Irobex, IRBUS, etc. (see Figure 1) .
Figure 1 IRBUS infrared communication protocol layer
Palm J2ME Introduction to the Operation of the Red Outer
In fact, Sun provides two ways to design the Palm-based Java program: one is to use CLDC KJAVA; the other is to use CLDC MIDP, then convert MIDP to Palm to Palm. The former one is programmed, regardless of the function, support for Chinese characters, or runs higher than the latter, but the previous Java virtual machine KVM is monochrome, but you can use Kawt, which is fully compatible with KVM. Virtual machines make up for this shortcomings. The latter programming method does not provide class libraries or methods for infrared port operation.
Sun's J2ME's CLDC1.x, Kjava provides Palm API function package for infrared communication. In the API of Kjava, the main program in the Palm should be derived from the J2ME's Spotlet class.
Figure 2 Sun Java architecture
The Spotlet class provides a static method beamsend () that Palm transmits data through the infrared port. In the Palm application, only the data sent by the infrared line is needed to be converted to byte arrays, directly using beamsend () to send the data to other devices via the infrared port, see the program code.
....
Public Boolean Senddata (String S)
{
Boolean State = false;
IF (s! = null)
State = this.beamsend (S.GetBytes ());
Return State;
} .......
For reception of infrared data, the Spotlet class provides a beamReceive (Byte []) method, stores the data received by the infrared port into a byte array, further by an array of this byte (such as transforming it into a string Wait, you can display the obtained data and see the program code below.
// Receive Beam Data
Public void beamReceive (byte [] parm1) {
Super.beamReceive (PARM1);
BEAMDATA = New String (PARM1); System.out.Print ("The Received BEAM DATAB IS: / N" EAMDATA);
}
Palm J2ME Infrared Chat Program
Palm Infrared Data Transfer Application Depending on both sides of the infrared communication. The communication between communications must be set to BEAM Receive: ON. Both sides must install the corresponding infrared communication software.
It is assumed that both parties of communication are Palm handheld computers, and two-way use infrared chat systems. The communication between communication can use the same procedure. The main design idea of the system is: In the Palm J2ME program GUI, construct two TextField used for dialogs, one for sending data, and the other for displaying the data received by the infrared port, and then constructing several buttons, completed Data transmission, program exit, etc. (see Figure 3).
Figure 3 Palm infrared chat program
The program describes the following:
(1) Construction class beamDemo, because the entrance class of the J2ME program belonging to Palm is derived by Spotlet, while BeamDemo completes the Dialogowner class (whether it is completed by the implementation of Implements) as shown in Figure 4.
Figure 4 BEAMDEMO UML class diagram
(2) Set the program entry of BeamDemo, the code is as follows.
Public static void main (string args []) {
New beamdemo (). register (want_system_keys);
}
SPOTLET.REGISTER () system registration event can have two:
One is NO_EVENT_OPTIONS. If you register this type of event, several function keys of Palm can still be used by the Palmos operating system. Therefore, the program derived from Spotlet may not use the setup to exit, directly by the Palm's button.
The other is Want_System_Keys. If you register this type of event, several of the Palm's function keys are not used by the Palmos operating system, and can only be used by the program. Therefore, the program derived from Spotlet, the program's exit exit code must be set, such as:
Switch (Keycode) {
Case 264: // Home Button Was Pressed
System.exit (0); // EXIXTS Program
Break;
.........
Otherwise the system cannot exit. Only RESET PALM can exit the system. The system event type is using the system key. After the program runs, the function of the system key is masked, which can improve the system response speed.
(3) Construction of user interface
In order to demonstrate the communication function of Palm infrared, we only construct 3 buttons, 1 TextField and 1 TextBox (Figure 3).
....
Static graphics g = graphics.getgraphics ();
// Treate the user interface here (Figure 1)
Button Button5 = New Button ("EXIT", 117, 139);
Button Button4 = New Button ("Clear", 69, 139);
Button Button3 = New Button ("Send", 20, 139);
TextField Textfield2 = New Textfield ("Please Data HERE", 13, 96, 139, 33);
TextBox textbox1 = new textbox ("this is the message" / n systemreceived! / N / n ", 15, 8, 137, 73);
//Construction method.
Public beamdemo () {
Button5.setenabled (TRUE);
Button4.setenabled (TRUE);
Button3.seTenabled (TRUE);
Textfield2.SetupPercase (false);
Textfield2.setText ("");
Paint ();
}
(4) In order to listen to the system infrared port, you must overrun the spotlet's BEAMRECEIVE event. The data listened by Palm is the original byte. If the data is arriving, the data read bytes Data [] is constructed in Data []. Out of the string, write textbox1, the code is as follows:
Public void beamReceive (byte [] data) {
String receivedstring = new string (data);
TEXTBOX1.SETTEXT (String.Valueof (ReceiveDString));
}
Public void Dialogdismissed (String Title) {
......
}
Public void keydown (int keycode) {
IF (TextField2.hasfocus ()) {
Textfield2.handleKeyDown (Keycode);
}
Public void pendown (int x, int y) {
IF (button5.pressed (x, y)) {
System.exit (0);
}
IF (Button4.Pressed (x, y)) {
TextBox1.setText ("");
}
...
(5) Set the content transmitted through the infraction. In the BEAMDEMO program, use the contents of TextField2 as the data to be sent. Since the data is a string, you can directly convert the string into a byte array, and send it through the PALM infrared in bytes through the beamsend method.
String text = textfield2.getText ();
Boolean Chengeded = Beamsend (String.Valueof (Text) .getbytes ());
IF (TextField2.pressed (x, y)) {
}
Public void penmove (int x, int y) {
IF (TextField2.pressed (x, y)) {
}
Public void penup (int x, int y) {
}
}
to sum up
Overall, the writing of Palm J2Me infrared programs is not complex, but pay attention to the transmission of data is implemented by the static method static booolean beamsend (byte []) through the Spotlet, and the data has the ability to overload beamReceive (Byte []) Method to extract the received data. In addition, pay attention to the simulator POSE of Palm does not support the simulation of infrared communication so far, the program's debugging must be performed on two real PALMs.
In daily life, many infrared remote controls send infrared instructions to the controlled electrical appliance. The above program can be used to align the infrared remote control, and the byte of the infrared remote control is captured by Palm, and stored in the internal database of Palm, then use Static Boolean Beamsend (Byte []) to be controlled Appliances will be surprised to find that Palm can completely replace the infrared remote control. Author:
Li Luqun
source:
Saidi.com http://www.Biplip.com/default.aspx?tabid=36&mid=355&ctl=view&itemid=195