Home AMX User Forum Duet/Cafe Duet

Sample Duet Code

Here is a sample module that was sent to me by Stephen Steiner from AMX. It helped me clarify a couple of things in my head, so I am posting it here (with permission) in hopes that it might help someone else. I will also be posting a sample piece of code that I am working on that works with buttons and channels to drive events.

Jeff

Comments

  • Thanks!

    Thanks for posting that source. I think this will help out a lot.

    Interesting that he chose to extend the switcher class. I thought I read previously on the forums that the utility class was meant to be used for this sort of stuff?

    Maybe, I'll try and rework the code to use the utility class instead.
  • Spire_JeffSpire_Jeff Posts: 1,917
    No problem on the post. I have had to put my java development on hold for a few months due to a couple of large jobs and a fix-it job that got wedged into the schedule, but I hear that AMX is going to be offering some form of training that addresses creating Java modules and integrating them. I got as far as a java module that would compile without problems in Cafe duet, but I was getting stuck in having it communicate with netlinx code. I did learn a lot about how AMX deals with the java code, but I'm missing that last puzzle piece :(

    As soon as I figure it out, I'll try to post a little tutorial aimed at those that are experienced in NetLinx, and have some idea of using Java, but have not had a chance to make the jump. I will say that there was a LOT of functionality I could add in Java very easily, so I regret not being able to figure it out.

    Jeff
  • Yeah... that's where I'm stuck right now too. I got that code sample to compile and I've got the module defined in my NetLinx code, but I can't get anything to happen when do a send command:
    send_command vdvMath, 'SIN=1'
    

    I'm checking the log file because there are a few statements in the Java source that look like messages are being sent there and I'm sending every command data_event that I get from the module to a text box on a panel, but I'm still not seeing any feedback.

    I think my next step is going to be to start digging into the Java debugging system and try and step through the code if that's possible.

    Derek.
  • Hmm... Well I got the debugging system working and it's starting to make some sense to me. But the execution paths still seem strange.

    It appears that based on the send_command text that I send to the virtual device, different event handlers in the Java module are triggered. For example, if I do this:
    send_command vdvMath, 'ASDF';
    
    only the handleAdvancedEvent() is triggered.

    But if I send anything with an equals sign in it:
    send_command vdvMath, 'ASDF=33';
    
    or
    send_command vdvMath, 'SIN=30';
    
    then the handleDataEvent() is triggered followed by the handleAdvancedEvent() after handleDataEvent() has exited.

    What is so special about the handleDataEvent() handler that it wouldn't be triggered in the first example, but would be in the second? Maybe I should just always use the handleAdvancedEvent() handler instead so that I'm always certain that I'll be getting all the data from the send_command?

    And why make the equals sign the thing that causes the handleDataEvent() to be triggered when AMX has always used commas as the delimiters between property names and values?

    Derek.
  • Spire_JeffSpire_Jeff Posts: 1,917
    Will a '?' mark trigger the handleDataEvent? How about '-' ? Both of those are used in AMX developed duet modules.

    Jeff
  • Hmmm... I'll have to try that and see if it makes a difference.

    I did find this though, if you mouse over the declarations for some of the methods you can get some documentation about that method. So, when I moused over the handleAdvancedEvent() this is what it says:
    void com.mak.mod.dr1_0_0.MakMod.handleAdvancedEvent(Event obj)
    Process a message that could not be interpreted by an intermediate router. Messages 
    from NetLinx devices which can not be mapped to the Standard NetLinx API will be 
    sent here. 
    
    Parameters:
    evt Event, which is a com.amx.duet.core.master.netlinx.Event
    

    So, there is some sort of pre-processing going on between the send_command in my NetLinx code and the actual event handler which is causing the JVM to choose one event handler over the other.

    Derek.
  • Not sure what made me think that the handleDataEvent() wasn't running, but it appears to be acting normally now. Anything I send to the virtual device with send_command is triggering handleDataEvent and then handleAdvancedEvent. This makes more sense now, handleAdvancedEvent appears to be a sort of 'catch all' for the event processing queue.
  • jjamesjjames Posts: 2,908
    Old thread - I know . . . but can someone compile this to a JAR so I can use it?

    Thanks!
Sign In or Register to comment.