Home AMX User Forum Duet/Cafe Duet

I'm learning JAVA!

Well, since I'm on vacation, I decided to really put an effort into learning Java. I am working my way through Thinking in Java 4th edition. It's a very good book so far and I am very happy with my progress. I figured I would post my experiences as they happen (well, I started a couple days ago, but you get the idea) in hopes that it highlights some of the problems and issues that arise when an experienced NetLinx programmer tries to code Java :).

So far, I have been using the NetBeans IDE from Sun (I started with Cafe Duet, but I was running into problems compiling and I didn't want to start messing with the Cafe Duet settings without being more familiar with them). I like the way it auto-inserts } whenever I put in {. It also closes [, ', and " automatically. I do need to get used to the preferred layout of code in Java that seems to be:
class name {
    class name(){

    }
} 
It makes sense, that's why I'm making the switch, but I have been using:
class name 
{
    class name()
    {

    }
} 
for so long that it takes a little getting used to.

I do miss the auto variable and function completion from NS4, but the method completion dialog is nice in the information it provides.

The biggest habit I need to break myself of relates to case sensitivity. For as long as I've been coding, I ALWAYS capitalize my commands to be like : IF().. ELSE or WHILE. Well, in Java, the commands are all lowercase. IF() is meaningless, it HAS to be if(). This has momentarily confused me more than once because my brain is used to IF() being correct and it doesn't throw up a flag immediately.

Another issue I foresee in the future is the inability to treat int 0 as false and int >0 as true. Java does not allow this. It's easy to work around as I could just do if(x>0), but right now I'm used to IF(x).

I am starting to like the way arrays are handled in Java. The array is created on the fly and because of this, you don't have to specify a set size. The size can be determined at the time of creation based on the size needed. (I'm still learning about this tho and I am probably yet to learn some of the limitations)

I also like the a lot of the inherited functionality that is provided. There are a lot of common methods built-in. Say you have an array of integers and you want to send the entire array as a string to the touch panel. You can just send IntArray.toString() and it will do all the work to send the array as if you sent it like this in NetLinx: "IntArray[1],', ',IntArray[2],', ', ...".

The foreach statement is kind of nice too :).


So far that is my experience with Java.

I will post more as I am inspired to do so. I will also try to post some basic java code from Cafe Duet designed to work with touch panel and comm port communications as soon as I am able. I will also try to give an unbiased review of the functionality of Cafe Duet over Netlinx.

Jeff

Comments

  • Spire_JeffSpire_Jeff Posts: 1,917
    I almost forgot, in Java, statements have to be terminated with ;

    This isn't that foreign to me as I used to program in C++ years ago. Also, when Cafe Duet was released, I've been trying to add the ; in my NetLinx code as it is supported, just not required. I do find I occasionally miss a ; , but the compiler is kind enough to let me know and it actually points DIRECTLY TO THE OFFENDING CODE! :0 .

    That brings up one very nice thing about the NetBeans IDE. The compiler has been VERY good at getting me directly to the problematic code line and it even gives me useful clues as to what it expects! :)

    Jeff
  • a_riot42a_riot42 Posts: 1,624
    Good for you, Java can be a mindbender at times.
    Spire_Jeff wrote:
    class name {
        class name(){
    
        }
    } 
    

    Actually you only use the word 'class' once at the top of the file as in:
    class Classname {
        public Classname() {
    
        }
    } 
    

    Spire_Jeff wrote:
    The biggest habit I need to break myself of relates to case sensitivity.

    It's a good habit to get rid of. I have never understood why Netlinx code is written in all caps. On the internet, that's shouting! Like they say, code is read far more often than it is written so to me that means it has to be readable.
    Spire_Jeff wrote:
    Another issue I foresee in the future is the inability to treat int 0 as false and int >0 as true. Java does not allow this. It's easy to work around as I could just do if(x>0), but right now I'm used to IF(x).

    Not much of an issue without functions like fork() etc. and I prefer to use boolean variables when boolean logic is required and integers for their purpose.

    I use Jetbrains IDE and think it is great compared to the others out there.
    Paul
  • Spire_JeffSpire_Jeff Posts: 1,917
    a_riot42 wrote:
    Good for you, Java can be a mindbender at times.

    I find that most of the time I am over complicating things. Sometimes it really is as simple as do.allTheWorkForMe() :).


    a_riot42 wrote:
    Not much of an issue without functions like fork() etc. and I prefer to use boolean variables when boolean logic is required and integers for their purpose.

    I use Jetbrains IDE and think it is great compared to the others out there.
    Paul

    In most of the instances that came to mind when dealing with treating ints as boolean, I was using the integers to store an actual integer value (not just 0 or 1). For example, I store the video output for a room in a variable (integer). The, when a device is selected, I check to see if the room has a video output. If it does, I send the video switching commands, if not, I move to the next step.

    Thanks for the encouragement tho. Hopefully the weather will allow me to stay focused on programming for the next couple days and I'll be ready to write my first Cafe Duet module before the year is over :)

    Jeff
  • GSLogicGSLogic Posts: 562
    Hi Jeff

    I've been playing (learning) Java for sometime now and I've gotten in the habit of using lowerCaseLettersWithVariables so much so, that I went back and changed many of my AMX modules just because it was driving me nuts to see UPPERCASE letters. I still drop the { after each command, I hate it when they're on the same line, it's to hard to follow.
    if(~~)
    {
    
    }
    
    The only thing in Java that I don't like (unless there is a way I don't know about) is you can't use STRUCTURES like in C++.

    Happy New Years and lets do lunch again soon!
  • jweatherjweather Posts: 320
    Jeff, you don't have to change indentation styles unless you want to. The AMX-endorsed style of
    if (this)
    {
      do that
    }
    

    is an acceptable indentation scheme for Java-like languages. I grew up with the opposite indentation:
    if (this) {
      do that
    }
    

    and so that's how I tend to write NetLinx code, to the dismay of my instructors.

    NetBeans should have a place to change the indentation settings. If you want more autocomplete/intellisense features, try Eclipse. I'm happy with NetBeans personally for the GUI designer features, which Eclipse is lacking, but I've heard good things about Eclipse's editor.

    Some other random points... most C-derived languages are case-sensitive, most Basic-derived languages are not. Visual Studio tries to correct your case when writing C#, most IDEs just fail to autocomplete if you start typing a variable name in the wrong case.

    Regarding array allocation and booleans, NetLinx has a lot more in common with C than with Java -- C does not have built-in dynamic data types, and has no native boolean type (0 = false, anything else = true).

    Congratulations for making the jump to another language. The more languages you learn, the easier it is to learn new languages (just as with spoken languages). You're also expanding your mind in the process, learning tricks which will help you understand and solve problems down the road.

    If you really want to blow your mind, learn LISP (or Scheme) ;)
  • jjamesjjames Posts: 2,908
    Spire_Jeff wrote:
    I do need to get used to the preferred layout of code in Java that seems to be:
    class name {
        class name(){
    
        }
    } 
    
    It makes sense, that's why I'm making the switch...
    I know I'm going to start a debate here - but how does pecking around, looking for where a opening bracket (or closing bracket) make sense when you can just look straight up (or down) the code at the specified indent? I never really understood this style, and it makes no sense to me.

    But - yay for you and learning Java; something I need to learn DESPERATELY!
  • Spire_JeffSpire_Jeff Posts: 1,917
    jweather wrote:
    NetBeans should have a place to change the indentation settings. If you want more autocomplete/intellisense features, try Eclipse. I'm happy with NetBeans personally for the GUI designer features, which Eclipse is lacking, but I've heard good things about Eclipse's editor.

    Some other random points... most C-derived languages are case-sensitive, most Basic-derived languages are not. Visual Studio tries to correct your case when writing C#, most IDEs just fail to autocomplete if you start typing a variable name in the wrong case.

    Regarding array allocation and booleans, NetLinx has a lot more in common with C than with Java -- C does not have built-in dynamic data types, and has no native boolean type (0 = false, anything else = true).

    Congratulations for making the jump to another language. The more languages you learn, the easier it is to learn new languages (just as with spoken languages). You're also expanding your mind in the process, learning tricks which will help you understand and solve problems down the road.

    If you really want to blow your mind, learn LISP (or Scheme) ;)

    Right now, I'm really only usig NetBeans to work through the exercises in the book without corrupting Cafe Duet :) I expect that after I get comfortable with Java and Cafe Duet, I will probably look to writing Java code to interact with netlinx processors on some level and at that time, I will probably just keep using NetBeans unless I find it lacking some feature I really need.

    I used to program C++ and I like linux (Altho, at the moment I don't use it on a daily basis), so case sensitivity doesn't bother me, I just got into the bad HABIT of CAPITALIZING NETLINX COMMANDS :) Also, NetBeans doesn't seem to autocomplete commands (Like if(),switch(), ...) for me. Is there a setting for this?

    I have heard of LISP, but I never really had a need to learn it. I used to code in Basic, Pascal, Assembly Language, C, C++, and even SQL :) I just missed the Visual basic and C classes as they made the switch at the university 1-2 years after I took the classes :( Ohh and I also used to program LOGO way back when Atari ST computers existed ... That was when I would make a 1200 baud modem connection to the local BBS if I was REALLY lucky :) I just looked up LOGO's wiki and it seems it is derived from LISP, so in a way I did program LISP :)

    [/tripDownMemoryLane]

    Back to the bills, but after I finish the financial crap, I can continue with the Java!

    Happy New Year everyone,
    Jeff
  • Spire_JeffSpire_Jeff Posts: 1,917
    GSLogic wrote:
    Hi Jeff

    I've been playing (learning) Java for sometime now and I've gotten in the habit of using lowerCaseLettersWithVariables so much so, that I went back and changed many of my AMX modules just because it was driving me nuts to see UPPERCASE letters. I still drop the { after each command, I hate it when they're on the same line, it's to hard to follow.
    if(~~)
    {
    
    }
    
    The only thing in Java that I don't like (unless there is a way I don't know about) is you can't use STRUCTURES like in C++.

    Happy New Years and lets do lunch again soon!

    I'll give you a call some time about lunch, it's be cool to talk about Java, or more importantly, ***** about programming and customers :)

    What portion of the C++ Structure can you not duplicate? It's been a while, but I think you can create a class that acts just like a structure (assuming we are talking the same thing). Are you trying to basically group a couple of variables together (kind of like the DEFINE_TYPE section with STRUCTURE in NetLinx)? If so, this should work:
    class autopatchOutputStatus {
       int curInput;
       int volume;
       int bassLevel;
       int trebLevel;
       boolean mute;
       String name;
       String inputName;
       autopatchOutputStatus(){
        //Set Default Values upon creation. Add additional constructors if needed.
       }
    }
    
    ...
    
     autopatchOutputStatus[] dvAp1 = new autopatchOutputStatus[18];
     dvAp1[1].name = "Family Room";
     dvAp1[2].name = "Living Room";
    
     for(autopatchOutputStatus s : dvAp1){
      dvTP.display(s.name, NAME_DISP_BTN)
     }
     
    

    At least I think that will work.... :)

    Jeff
  • Spire_JeffSpire_Jeff Posts: 1,917
    jjames wrote:
    I know I'm going to start a debate here - but how does pecking around, looking for where a opening bracket (or closing bracket) make sense when you can just look straight up (or down) the code at the specified indent? I never really understood this style, and it makes no sense to me.

    But - yay for you and learning Java; something I need to learn DESPERATELY!


    It's all about the indenting. To me, the opening bracket being on it's own line is only a force of habit. Looking at the Java layout, to me, is just as easy as the NetLinx standard, it just uses one less line and as a result, one less keystroke :)

    You were learning Visual C#, right? From what I understand, it shouldn't be that big of a jump to Java. The biggest jump is obtaining Cafe Duet :)

    Jeff
  • jjamesjjames Posts: 2,908
    Spire_Jeff wrote:
    It's all about the indenting. To me, the opening bracket being on it's own line is only a force of habit. Looking at the Java layout, to me, is just as easy as the NetLinx standard, it just uses one less line and as a result, one less keystroke :)

    You were learning Visual C#, right? From what I understand, it shouldn't be that big of a jump to Java. The biggest jump is obtaining Cafe Duet :)

    Jeff
    Ahh - I see now . . . but still - I'd rather have my extra keystroke and extra line. I'm a very "visual" programmer, and when things don't line up or look the way at least someone similar to how I do it - I get all confused!

    Yes, I was learning C#, I haven't played with it in some time, but still know the basics (sorta.) But yeah - getting Cafe Duet - LMAO! That's a joke. I'm personally not going to spend that much, and I know the company won't either . . . kinda have the philosophy - if it ain't broke . . . well, you know. A great resource, yes - but - there's no way we could justify it.
  • GSLogicGSLogic Posts: 562
    I'm concerned about the "HOLE" Java/duet modules/find device idea.
    In a perfect world it's a great idea, but needless to say I can't see it working except in small projects. It sounds really cool to the consumer that if he changes his Plasma years from now all the code will update too... I'll wait and see.

    I still have not used a Duet module in a large project because of it being such a resource hog and once again I hate locked modules. Bottom line is, Java will open more doors for more AMX programmers.

    Off the track a little but there's my 2 1/2 cents!
  • Spire_JeffSpire_Jeff Posts: 1,917
    I agree with you on the whole find devices thing. My time in the past with Plug and Pray computer devices has made me very leery of such technology. I have used the duet comm modules, because I have also used NetLinx comm modules which are locked. I know the duet modules are a little more resource intensive, but in the situations I used them, they seemed to work better than the older NetLinx module they replaced. If not, then I wouldn't leave them in.

    The reasons I am interested in Java are as follows:

    -Much more conducive to more than one programmer working on the project.
    -Classes available that simplify some programming chores.
    -Easier to find programmers with experience. (From a business perspective)
    -The ability to write programs for AMX processors, web servers and client computers. (Something that I hope will allow me to write applications to allow the homeowner to interface easier with the NetLinx system ... in the near future)
    -The ability to be a little more dynamic with data processing as well as make the code easier to update and maintain.

    I am probably setting the bar a little high, but I live for disappointment (that's why I work with the general public ;) )

    Jeff
  • travtrav Posts: 188
    Good IDE and Tutorials

    Jeff, and for anyone else making the jump to JAVA, first off, Download Eclipse, that is the IDE that Cafe Duet uses, Duet is basically just another plugin for Eclipse, you can have C++, Java and various others.

    Eclipse Home Page

    Also, for those unfamilliar with java and eclipse, also covering objects and inheritance, working with classes taking you through all the nice stuff in eclipse and also Test driven development...

    Eclipse and Java free tutorials

    Also really good for brushing up on java if you haven't touched it for nearly a decade.
  • Spire_JeffSpire_Jeff Posts: 1,917
    Thanks for the links. I will definitely check them out...

    UPDATE

    I am almost done with the tutorials and I must say, they are very well done. (At least the 16 introductory videos so far) I am following them easily and they repeat everything I've learned to this point (tho not as in depth as I have been going) so it is nice to have some reinforcement for the learning I have done. I would have to say that knowing the inner workings of the language is ultimately the best way to avoid problems, this tutorial gets you well on the way to being able to write some basic Java nicely. The place where it really shines is introducing the Eclipse interface and pointing out a bunch of shortcuts and helper features that I didn't have any clue about!

    I HIGHLY RECOMMEND THEM!


    Jeff
  • ericmedleyericmedley Posts: 4,177
    Spire_Jeff wrote:
    I find that most of the time I am over complicating things. Sometimes it really is as simple as do.allTheWorkForMe() :).

    Ha! My father, an avionics engineer, always told me the plane builder's credo.

    Always simplicate... add lightness

    I think this credo could be used by us programmers as well...
  • DHawthorneDHawthorne Posts: 4,584
    a_riot42 wrote:
    It's a good habit to get rid of. I have never understood why Netlinx code is written in all caps. On the internet, that's shouting! Like they say, code is read far more often than it is written so to me that means it has to be readable.

    It's a holdover from Axcent, where caps were required. NetLinx is actually case in sensitive: "DEFINE_FUNCTION" is the same thing as "DeFiNe_FuNcTiOn." Whatever style is easier for you to read is the "right" way for you.

    My tendency is to put constants and language keywords in all caps, a la Axcent. For variables and function names I use a pseudo-Hungarian notation - which is to say, the first letters in lower case will tell me what type of variable or function it is, but I use my own abbreviations, not the standard ones.
  • a_riot42a_riot42 Posts: 1,624
    DHawthorne wrote:
    It's a holdover from Axcent, where caps were required. NetLinx is actually case in sensitive: "DEFINE_FUNCTION" is the same thing as "DeFiNe_FuNcTiOn." Whatever style is easier for you to read is the "right" way for you.

    My tendency is to put constants and language keywords in all caps, a la Axcent. For variables and function names I use a pseudo-Hungarian notation - which is to say, the first letters in lower case will tell me what type of variable or function it is, but I use my own abbreviations, not the standard ones.

    I was never an Axcent programmer so it seems odd to me but like you say Netlinx doesn't care. I follow the Java spec just because I am used to it now at this point and other languages use it too. I basically won't ever capitalize anything unless there is some compelling reason to do so. This is what my code tends to look like:
    button_event[dvAllUIs, iHouseMusicZones]
    {
      push: 
        {    
          stack_var integer zone
    		
          zone = get_last(iHouseMusicZones)
          [dvAllUIs, button.input.channel] =! [dvAllUIs, button.input.channel]
          strHouseMusic.iActiveZones[zone] =  [dvAllUIs, button.input.channel]
        }
    }
    

    Here is a quote from the AMX iPod module for comparison:
    IF((nCURRENT_INDEX_NUM[nCURRENT_MENU]+(nCURRENT_INDEX_LENGTH * 2)) <= nMENU_RECORD_COUNT[nCURRENT_MENU]) // If the list is less than 2x the list length from the end
    {
      nCURRENT_INDEX_NUM[nCURRENT_MENU] = nCURRENT_INDEX_NUM[nCURRENT_MENU] + nCURRENT_INDEX_LENGTH // changed from 10 for dynamic listing
      SEND_CMD("'RETRIEVE_CATEGORIZED_DB_RECORDS?',ITOA(nCURRENT_CATEGORY2[nCURRENT_MENU]),':',ITOA(nCURRENT_INDEX_NUM[nCURRENT_MENU]-1),':',ITOA(nCURRENT_INDEX_LENGTH - 1)") // -1 and 9 was 10
      fnUPDATE_INDEX_LEVEL(nCURRENT_INDEX_NUM[nCURRENT_MENU])
      //SEND_STRING 0,"'in the IF'"
    }
    

    I find that so difficult to read due to the capitalization. The brain needs the different caps to help determine what the content is.
  • Spire_JeffSpire_Jeff Posts: 1,917
    Ok, here is the latest cool thing I have learned (from the tutorials at Eclipse... thanks again for the link trav). Eclipse keeps old versions of the code files and allows you to compare the current version to any of the previous versions! This would have come in handy more than once in the past few years of using NS4.

    I think I am ready to start writing an actual duet module, but it will have to wait until tomorrow as I am getting very sleepy :)

    Jeff
  • mkipemkipe Posts: 10
    Is Cafe Duet Required

    If Cafe Duet is an extension of the Eclipse IDE, is it necesary to purchase Duet? What does Duet add to the system?
  • jjamesjjames Posts: 2,908
    I'm assuming you purchase the license, and not the actual IDE.
  • a_riot42a_riot42 Posts: 1,624
    jjames wrote:
    I'm assuming you purchase the license, and not the actual IDE.

    I installed Duet a year ago or so and from what I remember it works as a plug-in for Eclipse. When you buy the CD it installs it all (both Eclipse and the plugin) for you so I am not sure what happens to your Eclipse installation if you already have one. Don't quote me but that is what my memory is telling me.
    Paul
  • mkipemkipe Posts: 10
    Duet

    Let me rephrase my question. Is Cafe Duet required to develop applications for AMX controllers? Can I write an app and load it without or do I need the class interfaces that come with Cafe Duet?

    I'm planning on buying Cafe Duet, I just want to know what I'm getting for $1000.
  • mighemighe Posts: 39
    You need Duet to develop for AMX Controllers.
    With Duet you get libraries to interact with Netlinx; Duet also packs your classes as a module compatible with Netlinx.

    I Usually develop logic with Eclipse 3.3 then I import my packages in Duet to load them on a controller.
  • JeffJeff Posts: 374
    I'm sitting in class at Sun's education center in Arlington VA right now, taking Fundamentals of the Java programming language, solely to get towards Duet programming. The class is taught entirely in NetBeans.

    From what I'm hearing y'all say, when I finish this class, if I'm going to continue working on my skills, I should go ahead and switch to Eclipse instead of NetBeans? I want the transition to Duet to be as seamless as possible. Java is my first real language, unless you count NetLinx as a real language, so I want to avoid as many roadblocks as possible.

    J
  • a_riot42a_riot42 Posts: 1,624
    You will have no choice but to use Eclispe. Eclipse is the only IDE that I know of that has the Netlinx plugin. I don't like Eclipse and have already paid for a much better IDE so it rankles me that the IDE to use is forced upon me. Good luck with the Java! You'll need it if Netlinx is the only language you have programmed so far :)
    Paul
  • sonnysonny Posts: 208
    Jeff wrote:
    I'm sitting in class at Sun's education center in Arlington VA right now, taking Fundamentals of the Java programming language, solely to get towards Duet programming.

    I've been doing Java programming for about 10 years but the biggest issue I had to overcome with Duet is poor documentation and lack of training. The one little example they give you doesn't cover much, and the help files are very minimal. In addition, there are bugs in the framework that can really irritate you, mostly in events/commands to/from Netlinx.

    Some of the device classes aren't documented at all, so you just have to use trial/error and a boatload of log commands to figure out how they interact with Netlinx.

    But it is very powerful and I can now whip out a driver in Cafe Duet in probably a quarter of the time I could do it in Netlinx. Plus there is a bevy of helper libraries and classes available for tasks like IP communications, sorting, list/queue management, parsing, etc.
  • MattSmithMattSmith Posts: 6
    Framework Bugs?

    What kind of bugs in the framework have you found? Can you give any examples?
  • Spire_JeffSpire_Jeff Posts: 1,917
    Coming at you live from Texas :)

    Well, I'm in the duet class and I figured I would attempt to enhance my comprehension of the concepts by attempting to repeat some of the things I have learned thus far.

    - Creating a new project: When you create a new module, use the New>Duet Module Project option. Use the defaults on the first and second pages of the wizard. On the third page, MAKE SURE you fill in the Make and Model sections. Leave the name, version and revision as they are. The category section is just meta-data used by programs like VA, so you don't have to worry about it unless developing modules for the such. GUID is used by AMX and is not of us to us mortals :) The next page let's you choose the type of device (Utility is the catch all for undefined uses). The last page let's you choose which methods you want to override (these can be added after the wizard as well, so just pick the ones you know you need).

    - When the manifest editor opens, close it! :) This is very important and can mess up the functionality of the module if you don't know what you are changing. As I learn more about these changes, I'll post them, but for basic modules, this should not be an issue.

    - Open the MakeModelVersion.axs file. Right click on it and choose Duet>Compile Module Stub.

    - Open the MakeModel.java file (should be the top entry in the tree under the project name. This is where all the good stuff goes :)

    - The isDeviceOnLine() function is used by the processor to decide if it is safe to kill the module and free the memory. DO NOT let this flutter between true and false too easily. If you aren't doing dynamic device allocation, you could just set this to return true.

    - The isDataInitialized() function is used by the processor to know if the module considers itself up to date with the physical device and all of its settings. This and isDeviceOnLine both need to be true before the processor will allow control over the device from the NetLinx program. This could also be hard coded to true, but depending on the device, it is probably not recommended ;)

    - If the device is serially controlled, doNetLinxDeviceInitialization() must return true. For IP controlled devices, this can be false. This is really asking: Does this module require the D:P:S of the device?

    - In the MakeModel(with variables) function, you can assign the NetLinxDevice to a variable for use within the module. *See tips below regarding this.

    - In the doAddNetLinxDeviceListeners() section, add a nd.addDataListener(this); where nd is the variable that is holding the NetLinxDevice from the previous line. This allows you to get strings back from the device. This should cause problems for the compiler. In the autofix, be sure to choose the option that implements the IDataListener. This will then require you to add some additional overrides.

    - Add the necessary code to the various functions that are called by the SNAPI. For example:
    	public void setPower(PowerState ps) {
    		if(ps.equals(PowerState.ON)){
    			myNd.sendString((char)2 + ">POWcON      F4" + (char)3);
    			bPowerState = true;//Unreliable power state tracking
    		}
    		else if(ps.equals(PowerState.OFF)){
    			myNdev.sendString((char)2 + ">POWcOF      EC" + (char)3);			
    			bPowerState = false;//Unreliable power state tracking
    		}
    	super.setPower(ps);
    	}
    

    - The handleDataEvent section is roughly the equivalent of the NetLinx Data_Event[dvDevice]. This is where you can deal with online, offline, and string events. here is an example:
    	public void handleDataEvent(Event arg0) { //DATA_EVENT[dvDVD]
    		switch(arg0.type){
    			case Event.E_ONLINE:{
    				myNdev.sendCommand("SET BAUD 9600,N,8,1");
    				myNdev.sendCommand("HSOFF");
    				break;
    			}
    			case Event.E_STRING:{
    				String rx = new String((byte[])arg0.dataValue);
    				System.out.println(rx);
    				break;
    			}
    		
    		}
    		
    	}
    
    There are better ways to handle the incoming string, but I will post that info I start to understand it.

    - Once you have everything set, right click on the code and choose Duet>Pack Module... Choose Next and then Finish to pack the module for use.

    - Add the module to your NetLinx code.



    *********************************Tips************************

    - To use non-printable characters (think "10,13" from NetLinx), typecast them to char. For example: "POW" + nPowState + (char)13 + (char)10

    - Use .equal() instead of == for logical comparisons. == will often check to see if the two variables point to the same object, not compare the values of the objects. For example: variable.equals("test text");

    - switch()..case statements in Java only work on intrinsic variables.

    - insert break; statements at the end of each case: in a switch case, or all cases after the matching case will be executed.

    - When using the .substring command, remember that java indexes start at 0, not 1. Also, when providing the second int, the command does not return the last value. So, if you do someString.substring(0,7) you will get the first seven chars in the string.


    I am sure there are more items, but that is all that comes to mind right now.

    Jeff
  • santisanti Posts: 2
    Use something else other than Netbeans.

    I recommend that you use eclipse for all your Java development.
  • Jorde_VJorde_V Posts: 393
    santi wrote: »
    I recommend that you use eclipse for all your Java development.

    you kicked up a nearly 2 year old thread

    What I am curious about though, why are you recommending Eclipse over Netbeans? Personal preference or?

    Netbeans is/was made by Sun and is very usable in my opinion. As well as extensions for it. My experience with Eclipse has been the same. (for C++ development).
Sign In or Register to comment.