Home AMX User Forum Duet/Cafe Duet

Duet Module Writing


I just got a hold of Cafe Duet (after an arm and a leg) and have begun writing my first module. I read almost every document that is available and came to a dead end.

Q: Where do you actually write the hex codes that need to be sent out to the device?

I am writing an RS-232 module for a Denon DCM-390 5-disc changer. I chose the DiscDevice as the component from the SNAPI.

The only thing I can assume is that you overwrite the methods from IDiscDeviceComponent such as setDisc with enQueing the actual hex command to set the disc to that number.

I have training in a couple of weeks and want to make the most of it since there seems to be virtually no support for Cafe Duet.

Thanks in advance for your help!

PS: Do any of you have any module samples? the Math sample doesn't really help much. Thanks!


  • karageurkarageur Posts: 97
    I promote your idea!

    We have also recently bought an Cafe Duet. For already two weeks im tring to write a simple module for Opticis OHM66 matrix switcher. In netlinx i would have already written this stuff with no problems. I cannot uderstand the position of AMX. They sell Cafe Duet and there is no any tutorial or somekind of step-by-step guide for real module with real device! So what's the point for integrator (who cannot take additional courses in because of geographical position) to buy such a tool that is not inexpensive and there is no any theoretical support ? ? ?
  • invostarinvostar Posts: 9
    My understanding is that they are intentionally holding it back because the majority of dealers are very comfortable in Netlinx and would struggle learning Java. Also, it seems like they are trying to avoid the training of their support and technical staff in Java because of the foreseen headaches.

    Now as dealers who came from a software engineering background who know the power of Java and other OO languages we think Cafe Duet makes a lot of sense. I know that there are a probably a good number of dealers around the country who think the same way but are stuck in the exact same trap - how can we implement without support and why pay all of that money for an open source eclipse product?

    AMX should embrace Java, which is a proven technology with a huge programmer base. Instead they are trying to chase the rest of the AV industry and create wizard tools. In the age of IT convergence in the AV world it seems that taking a different approach and going out of the box that AMX could really set themselves apart - and also up for success.

    Just my two pennies.

    PS - We will be attending a Duet training and I hope that this really jump starts our efforts. It would still be nice to have some better documentation and tutorials but this is currently all that AMX offers. We'll share our experiences as we go and would appreciate any feedback from those who have already been through this process.
  • invostarinvostar Posts: 9

    Well, after fighting along and asking people (thanks Spire_Jeff) for more information, I wrote my first working module.

    It's in its baby stages, but at least I got the entire process flow from Touch Panel -> NetLinx -> Duet Module -> Serial Port down.

    First of all, to answer my own question:
    Yes, the way to write the actual hex commands is by overriding the methods from the extended device class.
    The way to do this is as follows:
    1. Right click on the ManufacturerModule.java file (yours will have a different name).
    2. Go to Source -> Override/Implement Methods...
    3. Select the method(s) you want to add (I selected setDisc)

    The empty methods get added to the end of the file (if you have that setting).

    Then you write the actual hex codes you want to send to the device like so:
    	public void setDisc(int discNumber) 
    		byte[] sMsg = {0, (byte)'L', (byte)(discNumber+48), 0, 0, 0, ETX, 0, 0};

    This is for a Denon DCM390 5-disc changer. Ideally you would not send the command straight to the device but rather queue it. PriorityQueue (under AMXTools com.amx.duet.tools.util) is a great candidate for this. That is my next goal.

    About the super.setDisc. This actually calls the method inside the device class (DiscDevice in this case). If you take a look at the methods, most of them are empty. So in reality there is no fault in calling it. I'm just going to get used to do it in case there's a class with non-empty methods.

    Another useful tip. Keep things simple. At first you might feel tempted to use all the opportunities that Java offers, but take it slow. My enQueue didn't work and was breaking the module.

    Lastly, I hope the few of us that are privileged enough to understand the advantage of Java bond together and use this forum as a community and support site. Frankly, we have no other option.

    I look forward to working with you!
  • a_riot42a_riot42 Posts: 1,619
    Calling super should really be the first thing the constructor/method does.
  • On the same sort of theme as the above (lack of decent documentation an all) I have a question regarding IP in Duet.

    When wanting to create an IP connection do you use Java.IO and Java.Net and create your socket directly or do you pipe it back to your defined netlinx device (ie dvIPDEVICE = 0:11:0).

    If it's the latter, do you have any idea how to set up comms? I'm lacking a little in operating manual!!!
  • invostarinvostar Posts: 9
    a_riot42 wrote: »
    Calling super should really be the first thing the constructor/method does.

    Paul: I see how that makes sense. What about for functions with a return?

    For example:
    public DiscTransport getDiscTransport() {
    			case 'A':
    				return DiscTransport.PLAY;
    			case 'B':
    				return DiscTransport.STOP;
    			case 'C':
    				return DiscTransport.PAUSE;
    		return super.getDiscTransport();

    You have to put it at the end in those cases, right?
  • Something very much worth mentioning here is the concept of 'Design Patterns.' Understanding this will help a great deal to comprehend the reasons behind the way the Duet classes have been designed. Having this knowledge in your back pocket will make it easier to go through the class documentation for the duet classes. An excellent book for learning about using Design Patterns in Java is:"Head First Design Patterns", (O'Reilly). Of the books I've gone through on the subject, this was by far the best.
  • a_riot42a_riot42 Posts: 1,619
    invostar wrote: »
    Paul: I see how that makes sense. What about for functions with a return?

    You have to put it at the end in those cases, right?

    No, you are just reading the superclass' variable so it doesn't really matter. The special keywords 'this' and 'super' have very specific usage though, so other than their typical applications you won't use them much. Super is only generally used in the subclasses constructor to init the superclass as in:
    class Rectangle  {
      int width;
      int height;
      public Rectangle (int width, int height) {
        this.height = height;
        this.width = width;
      public int getArea()
        return width * height;
    class Square extends Rectangle {
      public Square (int width) {
        super(width, width)  // initing the superclass with the width and height 
    Overuse of 'this' or 'super' usually means something is amiss somewhere.
  • wengerpwengerp Posts: 29
    On the same sort of theme as the above (lack of decent documentation an all) I have a question regarding IP in Duet.

    When wanting to create an IP connection do you use Java.IO and Java.Net and create your socket directly or do you pipe it back to your defined netlinx device (ie dvIPDEVICE = 0:11:0).
    I usually use the classes in the javax.microedition.io package, which is part of J2ME for IO stuff. I'm attaching a simple hmtl-parsing module which shows one way of how to use this package. The following code snippet shows how to use this module in NS:
    dvTP1		= 10001:1:0
    vdvHtmlParser	= 41001:1:0
    vdvHtmlParserFb	= 41002:1:0
    DEFINE_MODULE 'wc_HtmlParser_dr1_0_0' mdlHtmlParser(vdvHtmlParser,vdvHtmlParserFb)
    	SEND_COMMAND vdvHtmlParser, 'PARSEURL-http://amx.wepcom.ch/request.php?userid=1'
    	SEND_COMMAND vdvHtmlParser, 'PARSEFILE-index.html'
    	stack_var char inbuf[2048]
    	stack_var char tag[48]
    	stack_var char text[2000]
    	inbuf = DATA.TEXT
    	tag = DuetParseCmdParam(inbuf)
    	text = DuetParseCmdParam(inbuf)
    	send_string 0,"'tag::',tag,'  text::',text"
    I fully agree that there is very little public accessible information available about AMX Duet developing. If there are others who like the (earlier mentioned) idea of sharing Duet code samples, I'd be pleased to join such an initiative.

  • Thanks for the info and sample. I would definately not protest AMX supplying a few more duet code samples just to see how they tick!

    Till then it's trial and error I guess...

    We can but hope!
  • Module Examples

    I have some experience with java eclipse but am missing the link to AMX. Is there any examples that someone may have?
  • While I agree that having some sample code from AMX would be helpful, the beauty of Java, including Duet's Java, is that there are many, many online resources for Java examples. I regularly will search for a particular term or process within generic Java websites and then apply that to Duet. There are some things that you can't do in Java, but generally, they are not things you would want to do anyway (such as communicating to another remote Java app). Someone asked how to do IP communications in Java. When I needed this, I searched on "Java TCP/IP", found some sample code, dropped it into my program and with very minor tweaks, I was able to send/receive packets in a matter of minutes.

    Here's a good place to start:


    At the training, you will receive many examples of how to do the things that generally you need to do. But don't think that Duet is strictly for simple module writing to control a single device. Yes, it can do that, but it can do so much more if you want it to.

    Don't fear Duet. Yes, it does take just a bit to get up and running, but once you do, you'll find it far superior to Netlinx code.

    Sheldon Samuels
    SchoolView Technologies, LLC
  • I think that my biggest issue is the link between AMX and Java. Processing of events like push,Data chan etc and doing something. Ex. How do I take a button press and call up a class to do something such as send a string. I think that once I see this in then it in action it will make complete sense. Thanks for the reply. Thoughts? Am I completely looking at this the wrong way. I have been know to do that from time to time.
  • It depends somewhat on how you have defined your devices. If your TP is defined in Netlinx only, then you receive your button event through your Netlinx program. Based on the button or function to be executed, you will most likely pass a SEND_COMMAND to your Duet module. Or you might pass a Channel event to your module (simple ON[dvDuet,ch] or OFF[dvDuet,ch]). In your duet module, you will receive these via either a handleDataEvent or a handleChannelEvent. Add a listener to your dvDuet device when you initialize your module (within Duet).

    If you define your TP in Duet, first be aware that the TP will only trigger events within Duet at that point. But you can always define port 1 for Netlinx buttons and port 2 for Duet buttons, etc. If you define the TP in Duet, add a button listener in Duet and process the buttons directly in Duet.

    dvDuetTP = new NetLinxDevice(new DPS("10001:1:0"),false);

    or you can get a bit more detailed with adding your listeners by doing the following:

    dvDuetTP.addDataListener(new IDataListener() {
    public void handleDataEvent(Event evt)
    do something here or call another class

    Be sure to define your listeners before the initialize() statement. It makes a difference.

    Hope this helps.

    Sheldon Samuels
Sign In or Register to comment.