working with java

08 Dec 2010

Hi, I'm trying to build a remote java app, but don't know how to compile the applet. I'm using the javac command in the JDK and have mbedRPC.jar in my lib folder.

I have the hello world file working, but only when I use the precompiled versions supplied. I don't seem to be able to compile the applet for myself.

It just throws up the error "package org.mbed.RPC does not exist", given the first line of helloworld.java which reads "import org.mbed.RPC.*;"

Any ideas most appreciated...

08 Dec 2010

Hi

Heres a way to do it at the command line, I think - I don't do this very often but I have just tried most of it out sucessfully

So if you have your java file HelloWorld.java and mbedRPC.jar in the same folder navigate to this directory in the jdk then these are the command line instructions:

>>javac -cp mbedRPC.jar AppletHelloWorld.java

You should now have a .class file

You now need to create a manifest file with the contents as below - save this as manifest.mf in the same folder as everything else. (note you need a new line at the end of the file):

Manifest-Version: 1.0
Created-By: you
Main-Class: AppletHelloWorld
Class-path: mbedRPC.jar

Now at the command line you can create the jar

>> jar cfm hello.jar manifest.mf AppletHelloWorld.class

This should have created a hello.jar file in the folder - make sure it is 8.3 file name. To deploy it now you should put the mbedRPC.jar, the hello.jar and the HTML file onto the mbed disk drive. The HTML file applet parameters will need to be CODE="AppletHelloWorld" ARCHIVE="hello.jar"

An alternative to creating the manifest file is to unpackage the mbed.RPC jar and then compile all the source files into a single jar.

Hope this works

Here are some links I used to help http://download.oracle.com/javase/tutorial/deployment/jar/index.html http://download.oracle.com/javase/tutorial/deployment/jar/modman.html http://mydebian.blogdns.org/?p=76

08 Dec 2010

Thanks - thats a great help!

09 Dec 2010

Thanks for your help yesterday Michael - I've managed to make some good progress but have hit another brick wall.

I'm using RPCVariables within a Java Applet i'm writing, but I keep getting compile errors. It seems it will only compile if I define my RPCVariables as type Double, i.e.

  RPCVariable<Double> LNB1PositionLED;

and

LNB1PositionLED = new RPCVariable<Double>(mbed,"RemoteLNB1PositionLED");

However, I need these to be integers or ideally bools and if I define them as ints or bools it wont compile. It also apperas to be case sensitive and wont compile with <double> either.

I also note that its not possible to define the RPC Variables in the mbed compiler as bools either, this throws an error in the mbed compiler. Type ints are fine in mbed.

bool RemoteLNB1ositionLED;
RPCVariable<bool> RPC_RemoteLNB1PositionLED(&RemoteLNB1PositionLED,"RemoteLNB1PositionLED");

(the above won't compile)

I've tried every combination of variable types, but can't get it to work. I like the Applet example you gave called RemoteSensing.java, but unfortunately this doesnt use RPCVariables (only RPCFunctions) so I can't see a complete example that is functional. Any ideas most appreciated please?

 

09 Dec 2010

Hi

You can't use bools over the rpc due to the way RPC works. The RPC handler code doesn't have support for parsing "true"/"false" in the RPC strings, this means that the RPCVariables can't take a bool type. You'll have to use an int with values 0 and 1. This means that reading bools back isn't in the java mbedRPC either.

The Java Code will work with Doubles, Integers, Floats or Characters. However you define using the object not the primitive type.

RPCVariable<Integer> IntRPCVar; IntRPCVar = new RPCVariable<Integer>(mbed,"NameOfInteger");

Or using "Double" as you have found. Unfortuantly Java doesn't support templates in the same way or as well as C++ does and so although there is a single write method regardless of type, to read back you have to use the correct method for that type eg

IntRPCVar.write(1); int Result = IntRPCVar.read_int(); or double Result = LNB1PositionLED.read_Double();

This is so that the program knows how to parse the text string it receives from mbed. When I wrote the library I couldn't find a neater way of doing this in Java. Although you set the type using Integer or Double etc the result from read_Double() and read_int() etc are returned as the primitve types int and double.

I think this should work for you apart from having to be careful in the way you use integers for true or false - ie make sure that your program doesn't completly fail or become unpredictable if the value ends up as 2. May be 0 = false and anything else is true.

Michael

16 Dec 2010

Hi Michael. Thanks again for all your help - you've been really helpfull and I'm creeping there bit by bit. My problem now is with latency. I've coded that my buttons change colour on a mousepress, and when the mouse is released the applet reads the current inputs and updates the screen and the physical mbed io. but there is no consistency in timing. Sometimes the button changes colour immeiately, other times it takes a number of seconds, sometimes things get a bit out fo sinc (the phyical output changes before the button changes colour on the screen). The main problem is that latency means that if it takes a few seconds for the user to see that their action has been implemented, then they are likely to hit the button again. Latency seems to increase also and gets worse over time, unless I reboot the mbed and restart the browser. I don't expect you to fix this for me, but I need to work out where the latency is coming from. Is it in the mbed and the associated libraries? Or am I just a bad java progrmmer? Or is it general network latency that I just have to live with? The mbed pings quite fast, so I hope I can speed it up somehow? Would really appreciate to hear your wisdom please :)

08 Jun 2012

Like Rob I can get the pre-compilied to work but when I try to build my own jar by Michael's instructions I get an error when the java tries to load: "Application error org/mbed/RPC/mbedRPC there was an error while executing the application" I viewed the contents of the mbedrpc_1.jar and mbedRPC.java and mbedRPC.class are there. I am stumped! Thanks in advance for any help