Home AMX User Forum Duet/Cafe Duet

Build a complete java application to run on an ni master

Ok, so maybe not totally duet, but a utility module (bypassing snapi) and then netlinx that only imports that module, and the rest all done in java.

Anybody done this before here? I know AMX has with a few of their customers.

Im looking for a good example to get started off of, im new to duet, however have a past in java and can handle most any netlinx project, so now I want to bump up and use java, plus the customer requested it for other reasons.

Any and all pro's and con's are accepted.

Comments

  • PhreaKPhreaK Posts: 966
    This is definitely possible. Get yourself nice and familiar with OSGi if you haven't already done so - Neil Bartlett's awesome OSGi in Practice is a good start. From there you can roll your own OSGi bundles that perform different bits of your system functionality and they can communicate purely on the Java side via the services registry. This approach will let you maintain system modularity and also keep you compatible with any Duet device device modules so that you're not having to re-invent the wheel or have one set of device comms code you use on java projects and one for your NetLinx / hybrid jobs.
  • PhreaK wrote: »
    This is definitely possible. Get yourself nice and familiar with OSGi if you haven't already done so - Neil Bartlett's awesome OSGi in Practice is a good start. From there you can roll your own OSGi bundles that perform different bits of your system functionality and they can communicate purely on the Java side via the services registry. This approach will let you maintain system modularity and also keep you compatible with any Duet device device modules so that you're not having to re-invent the wheel or have one set of device comms code you use on java projects and one for your NetLinx / hybrid jobs.

    Thanks for the tip's Kim, I am reading up on the oscar OSGi framework, but with little to no duet background, I am still figuring out how to make it all fit more or less...

    Any other tips or examples, etc are greatly welcomed!
  • Is there anything within the AMX Masater that will block communications from outside applications that could be built for monitoring or controlling things within the NI Master?
  • rrdbstudiosrrdbstudios Posts: 160
    Is there anybody really good with Duet able to answer some questions???

    Ok, so I am on a mission to write an entire application (just a small one to start) with duet.

    Basically, where Im at:

    I've created a utilty only module, so no snapi is included. I have activator.java and my utility_test.java and utility test_dr1_0_0.axs files.

    Within my java files I know I need to add my devices and TP's, such as:
    NetLinxDevice dvTP = new NetLinxDevice(new DPS(10001,1,0),false);
    dvTP.initialize();

    catch events

    dvTP.addButtonListener(this);
    dvTP.addDataListener(this);


    From what I understand, I need to place my module inside my normal netlinx code.

    "DEFINE_MODULE 'utility test_dr1_0_0'( WHAT GOES HERE )"

    BUT, if im adding all my physical devices within the java code, what do I add into the "DEFINE_MODULE" area... Im adding many devices.. Do I leave this empty, it wont compile though...


    Any thoughts on this would be beyound helpful to really get me going... I havent taken a duet class, but I have the software and want to learn what I can while I have time prior to any classes.

    Thanks all!
  • PhreaKPhreaK Posts: 966
    Duet modules are actually instantiated by a module stub. If you have a look inside the package explorer in Cafe Duet (left hand side by default) you will see a *.axs file in the project root. This is a stock standard NetLinx module and what you are actually instantiating with your define_module line. It's job is to form up the module properties that will be passed to Duet to allow OSGi to do it's magic.

    Now, as this is a normal NetLinx module you can change the parameter list to add in additional data which you can push into that properties array and read out within the java side. Alternatively, in your case you may want to just nuke the dvPhysicalDevice parameter so that you only have to pass a Duet virtual to the module for instantiation. If you do this just pop a dummy physical device in the properties array.
  • rrdbstudiosrrdbstudios Posts: 160
    Ok, Im starting to see what you mean.

    Just for reference and so others can follow for the future:
    // Load up device numbers as strings
    DUET_PROPERTIES[1] = "'Physical-Device=',FORMAT('%d:',dvPhysicalDevice.NUMBER),FORMAT('%d:',dvPhysicalDevice.PORT),FORMAT('%d',dvPhysicalDevice.SYSTEM)";
    DUET_PROPERTIES[2] = "'Duet-Device=',FORMAT('%d:',dvDuetDevice.NUMBER),FORMAT('%d:',dvDuetDevice.PORT),FORMAT('%d',dvDuetDevice.SYSTEM)";
    
    // Load Duet Module
    LOAD_DUET_MODULE(DUET_PROPERTIES)
    

    ..now do I HAVE TO pass any parameters from netlinx? Can I just import the com.amx.duet.core.* and com.amx.duet.da.*; packages and access all ports this way? (please correct me if I say anything incorrect)


    Is there any reason to ever do anything with the activator.java file? In a traditional OSGi bundle, there is a start() and stop() method within the class.


    Does it seem like im on the right path, or am I looking the wrong direction...

    Thanks!
  • sonnysonny Posts: 208
    I've got a couple of pure Java systems running, but they're not doing any AMX ui. I'm just passing a dummy vdv and dv in DEFINE_MODULE statements. I've used multiple modules in order to better organize functionality. In addition, I abstract all AMX specific code out of functional code in order to better ensure portability. Keep in mind that the Oscar bundle isn't used in version 4.x firmware, it uses some form of a bundle from Knoplerfish.

    As far as outside communications, I'm using some home-grown socket stuff as well as creating a Jetty instance to service http requests.
  • rrdbstudiosrrdbstudios Posts: 160
    Sonny,

    I havent touched this idea in a while since jumping into a new project, but would you be willing to send an example or stripped down application?

    Is it possible to take standard bundles created and upload them and activate them? you mentioned jetty not being used in 4.x, well why not in a new bundles manifest, import the package there and build the new bundle encapsulating the required package? Im not sure how netlinx would handle this, but a thought...
  • sonnysonny Posts: 208
    I haven't tried it in a while, but at one point I was able to upload a standard .jar in v3 and load classes from it. v4 rejected this as not being a valid Duet Module. You could probably assemble it as a bundle, but I haven't dug that deep. If I can get my hands on the source, I just include it in a generic "Utility" duet module.

    For v4 I would probably just embed Tiny Java Web Server vs. Jetty, I've used it in a Duet module as well. I think I tried creating an instance of the http server that is in v4, don't remember, but I might have gotten a security violation.
  • PhreaKPhreaK Posts: 966
    sonny wrote: »
    I haven't tried it in a while, but at one point I was able to upload a standard .jar in v3 and load classes from it. v4 rejected this as not being a valid Duet Module.

    Try setting AMX-Type: Duet in your jar manifest. See [post=8076]this post[/post] for more info.
Sign In or Register to comment.