2 using java applet for communication – SENA HD1200 User Manual

Page 49

Advertising
background image

Starter Kit and User Manual for the HelloDevice 1200

46

commandBuf[3] = tmp ;


tmp = length & 0x00FF ;

commandBuf[4] = tmp ;


commandBuf[5]

=0xAA;

// 0: Do not generate Interrupt to device, AA: Generate

interrupt

for (i=0; i<length; i++)

commandBuf[i+6] = data[i] ;

commandLen = 6 + strlen(data) ;


// Send command to the HelloDevice

err

=

sendto

(

sock,
&commandBuf,
commandLen,
0,
(struct

sockaddr*)&clientAddr,

sizeof(clientAddr)
)

;


if (err == -1 )

{
perror("\nsend

error\n");

exit

(1);

}
}

6.4.2 Using Java applet for communication

The program source codes with Java applets, as demonstrated in section 5.2, are Simulator.java, RamPanel.java,

Util.java, ValueDisplayPanel.java and DPRComm.java located at “the HelloDevice installation folder\Src\java”

folder. You can access a web site and control the linked device remotely by creating web pages and inserting

applets written with these source codes into html files.

The following example shows how to implement Internet socket interface for sending and receiving signals

through TCP Port 6001 of the HelloDevice to control Dual-Port RAM with Java applets.

public synchronized byte[] readValue(int addr, int length) {

int inputData = 0;

int tmp = 0;


byte rxData[] = new byte[length+4];

byte retData[] = new byte[length];

byte[] data = new byte[5];


if (length > 0xff) length = 0xff;

data[0] = COMMAND_GET;

data[1] = (byte) ((addr >> 8) & 0x000000ff);

data[2] = (byte) (addr & 0x000000ff);

data[3] = (byte) ((length >> 8) & 0x000000ff);

data[4] = (byte) (length & 0x000000ff);

try

{

socketTCP.getOutputStream().write(data, 0, data.length);

tmp = instream.read(rxData, 0, rxData.length);

if (tmp != -1)

{

Advertising