Home AMX User Forum NetLinx Studio
Options

New and Needy

Hi guys, I'm new to all this and I'm trying to figure out how to do this AMX programming malarky!

I'm using an NI700 a tablet by Hannspad with TPControl on the demo licence and I'm trying to control an NEC300W projector. I'm not doing to badly, i've got the thing switching on and off and switching inputs. What I can't quite figure out is how see the responses from the projector so I can start doing some feedback.

Is there a simple way to see what the projector is responding with after I send it a string? As far as I know all this info goes to data.text but can't seem to monitor the data.

Help would be gratefully received!

Comments

  • Options
    HedbergHedberg Posts: 671
    Use diagnostics. "enable Netlinx device notifications"

    Or, program a string handler into a data event.

    This is all explained in the documentation.
  • Options
    Which documentation? I wish I could find a some decent docs on this then it would be a lot less trial and error! For example, if I switch on the device notifications all I get is input status on the touch panel.
  • Options
    Nomski, as Hedberg said:
    Hedberg wrote: »
    Use diagnostics. "enable Netlinx device notifications"
    +add your device in the list. Deselect the notification messages for "All" devices and select only the In and Out Strings for your device
    Hedberg wrote: »
    Or, program a string handler into a data event.
    you should know how to do that if you had the Programmer I and Programmer II courses. Or even if you don't:
    Hedberg wrote: »
    This is all explained in the documentation.

    Kostas
  • Options
    HedbergHedberg Posts: 671
    All the documentation is available on the AMX website. You need to read the documentation on Netlinx Studio which will tell you everything you need to know about the Studio interface, diagnostics, the de-bugger, etc. You also need the documentation on the Netlinx programming language which will tell you everything about events, devices, etc. Also, if you go poking around in the archived technical manuals you will find an Axcent language primer. Axcent is obsolete, but the information in that primer (about devices, syntax, etc) is entirely useful to figuring out Netlinx programming.

    Somewhere in the miasma that is these forums there is a reference to a Netlinx primer, but I can't find it and the search function in these forums sucks so bad that I have little hope of finding it. Perhaps someone not quite so brain dead as I will post a link.

    It's Friday afternoon. If you've never seen an AMX system, and even if you can't spell it, if someone gave you a basic system to program by Monday, you should be able to figure it out with the documentation easily available on the web site. If you can't, hire somebody.

    Call me Curt.

    Harold

    edit:

    I have attached a zip file which contains a pdf of a document that was available on the AMX site back in 2004. It wasn't a help to me at the time, but it may be to you as it explains a whole lot of Netlinx programming concepts, including at least a bit about string handlers in data events.
  • Options
    Nearly there?

    Ok so I've got a lot further thanks to Hedberg's PDF gift. I am now able to use the first location in data.text or a buffer to get button feedback on my panel. The odd bit is that none of the other locations work. I.e.in the watch window I can see what is in my buffer and it's 22 individual hex bytes. I know which ones are the ones I need and to test them I am using a little switch case to try and get a location to turn on a button. It's not pretty but I'm just trying to get it to work so I know I'm getting something right.

    data_event [dvProj]
    {
    STRING:
    {
    cmybuffer = data.text
    SWITCH (cmybuffer[2])
    {
    case 'BF': on [dvtp,1]
    case '$BF': on [dvtp,2]
    case 'OH MY GOD WHY ISN'T THIS WORKING!': on [dvtp,3]
    }
    }
    }

    In the watch window I can see the 22 byte response and the only one that reacts to anything is byte number 1. So, if my bit of testing code says" says:

    data_event [dvProj]
    {
    STRING:
    {
    cmybuffer = data.text
    SWITCH (cmybuffer[1])
    {
    case 'BF': on [dvtp,1]
    case '$BF': on [dvtp,2]
    case ' ': on [dvtp,3]
    }
    }
    }

    It works on button 3.

    Anything else doesn't work. The second location in the buffer (according to the watch window) is "BF" and with or without the $ sign it simply doesn't work.

    Any ideas? I'm losing my mind!
  • Options
    jjamesjjames Posts: 2,908
    Single quotes denote a string literal. You'll want your CASEs to be $BF, not 'BF' or any variation of it. You won't be able to use strings in that CASE.

    Check page 60 in the manual.
  • Options
    AMAZING!

    Thanks you so much, I was pulling my hair out! On page 60 it says;

    "the SWITCH expression is tested against each CASE value (which must be a numeric constant or a
    string literal)."

    So surely that means that you can use the ' ' for string literals? Either way, it works now so I'm very happy!

    Just got to do some level events and I'm laughing, cue more epic trauma!

    I'm sorry if I appear stupid but I do really appreciate the help I've had on here so far.
  • Options
    Nomski wrote: »
    data_event [dvProj]
    {
    STRING:
    {
    cmybuffer = data.text
    SWITCH (cmybuffer[1])
    {
    case 'BF': on [dvtp,1]
    case '$BF': on [dvtp,2]
    case ' ': on [dvtp,3]
    }
    }
    }
    Sometimes SWITCH..CASE statements are tricky when comparing single bytes. When i need to compare 1 byte values i either use a SELECT..ACTIVE or IF statements.

    So, with the tip from JJames, your code will be:
    data_event [dvProj]
    {
        STRING:
        {
    	cmybuffer = data.text
            IF(cmybuffer[2] == $BF)
            {
               on[dvtp,1]
            }
            ELSE IF (cmybuffer[2] == ' ')
            {
               on[dvtp,3]
    	}
        }
    }
    


    or even:
    data_event [dvProj]
    {
        STRING:
        {
    	cmybuffer = data.text
            [dvtp,1] = (cmybuffer[2] == $BF)
            [dvtp,3] = (cmybuffer[2] == ' ')
        }
    }
    

    Kostas

    P.S. While you were writing your response i was also writing my post :) So, it really nice to know your code worked !
  • Options
    mpullinmpullin Posts: 949
    papadouk wrote: »
    Sometimes SWITCH..CASE statements are tricky when comparing single bytes. When i need to compare 1 byte values i either use a SELECT..ACTIVE or IF statements.
    The only trick is that you cannot mix data types. All integers, all chars, all char arrays.... these are fine.
    switch(cLetter){
         case 'A': doStuffA(); break; //
         case 'B': doStuffB(); break; // this is good.  All single chars.
         case 'C': doStuffC(); break; //
    }
    
    switch(REMOVE_STRING(DATA.TEXT,'=',1)){
         case 'POWER=': doStuffWithPower(DATA.TEXT); break; //
         case 'INPUT=': doStuffWithInput(DATA.TEXT); break; // this is good.  All char arrays.
         case 'VERSION=': doStuffWithVersion(DATA.TEXT); break; //
    }
    
    switch(strwithrandomlength){
         case 'GUIDE': sendIRtoTV(56); break;
         case 'MENU': sendIRtoTV(44); break;
         case '0': sendIRtoTV(10); break; // This will cause compiler errors in NetLinx.  You can't have a single char and a char array as cases of the same switch.
    }
    
    switch("'&',strwithrandomlength"){
         case '&GUIDE': sendIRtoTV(56); break;
         case '&MENU': sendIRtoTV(44); break;
         case '&0': sendIRtoTV(10); break; // Now it's ok because everything is a char array.
    }
    
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    mpullin wrote: »
    switch(strwithrandomlength){
         case 'GUIDE': sendIRtoTV(56); break;
         case 'MENU': sendIRtoTV(44); break;
         case '0': sendIRtoTV(10); break; // This will cause compiler errors in NetLinx.  You can't have a single char and a char array as cases of the same switch.
    }
    

    That won't cause compiler errors. You can have a single character and multiple characters as long as you put them in the order that you did with the single character at the end.

    This will cause a compiler error:
    switch(strwithrandomlength){
         case '0':  break; // This will cause compiler errors in NetLinx.  You can't have single characters mixed with multiple characters unless the single characters are at the end of the switch
         case 'GUIDE':  break;
         case 'MENU':  break;
    }
    

    Just remember smallest at the bottom.
  • Options
    ...so why confusing myself with the "special" behavior of the SWITCH..CASE when i can do it with other ways?
    :)
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    papadouk wrote: »
    ...so why confusing myself with the "special" behavior of the SWITCH..CASE when i can do it with other ways?
    :)

    If you are looking to match strings of varying length, SWITCH..CASE seems to be the fastest. Here are some benchmark results: http://www.amxforums.com/showthread.php?5307

    You have to look at the last set of results for the strings of various lengths results.

    If you have a situation where there are multiple conditions, but only 1 or 2 occur the majority of the time, it might be faster to use a SELECT..ACTIVE.

    Jeff
  • Options
    Spire_Jeff wrote: »
    If you are looking to match strings of varying length, SWITCH..CASE seems to be the fastest. Here are some benchmark results: http://www.amxforums.com/showthread.php?5307
    Thank you Jeff for pointing out that thread. I had read it in the past and it was inspiring.

    I made also some tests myself but not as thoroughly as yours. Only with numeric data types and for quite large arrays. My results showed me that SWITCH..CASE was slightly slowest than the other 2 methods. IF..ELSE and SELECT..ACTIVE were the same (something like comparing 0.0002 to 0.0003).

    Spire_Jeff wrote: »
    If you have a situation where there are multiple conditions, but only 1 or 2 occur the majority of the time, it might be faster to use a SELECT..ACTIVE.
    Totally agree with you. And also i agree with what you pointed out in the thread you suggested to me:
    Spire_Jeff wrote: »
    This reinforces my tendency to put conditions I think will occur most often first.


    At the end of the day i am using different methods for different things.
    SWITCH..CASE for collapsing results
    SELECT..ACTIVE when i mix a lot of conditions and evaluated expressions in the same block
    and
    IF..ELSE for quick comparisons.

    Kostas
Sign In or Register to comment.