Home AMX User Forum AMXForums Archive Threads Tips and Tricks

Using ?Emulate a Device? to test your parsing routines

John GonzalesJohn Gonzales Junior MemberPosts: 609
I know most know to do this, but just thought I?d post it in the tips and tricks section for those that didn?t remember or realize this particular use of the ?emulate a device? feature.

Here?s the situation: You?ve finished writing a nice piece of code to control a device and process the return data, but you have no way of knowing if your parsing routines work properly on the incoming data until you plug in to the actual equipment on site, right? By using emulate a device you can mimic the device you?re trying to control and send response strings to your NI Controller to see if it reacts properly (with a few caveats). Here?s an example of how to do it:

If you?re trying to control a television, we?ll assume you?ve defined the television in your program as dvTelevision = 5001:1:0 and it will be connected to serial port 1 on the master. Now, the control strings you send out are visible in diagnostics/notifications so they?re easy to deal with and you can verify that they?re being sent properly there. Next, by looking at the protocol document for the device, you see that the TV is supposed to respond with
?$7F, $70, $80, $F8, $03, $01, $80, $01, $13? if it?s turned on, or
?$7F, $70, $80, $F8, $03, $01, $80, $02, $12? if it?s turned off.

You've written a routine in your program to parse the incoming response from the television and it?s supposed to activate a flag or feedback channel based on power status. In other words when the TV responds that it?s on, your program is supposed to parse the data and set bTVPowerFlag = 1 or if it responds that it?s off, set bTVPowerFlag = 0.
  1. Open up debug and load the variable bTVPowerFlag so that you can monitor it.
  2. Open up the ?Emulate a Device? window in diagnostics. Once in there, set the
    device number to 5001, the port to 1, and the system to 1 (assuming that the
    master is set as system 1) and that matches the dvTelevision definition of
    5001:1:0 (remember 0 as a system number is a shortcut that just means ?this system?
    but you can?t use it in control/emulate a device ? you have to specify the actual system
    number for the master you?re using).
  3. In the ?Message(s) to Send? window type in:
    ?$7F, $70, $80, $F8, $03, $01, $80, $01, $13?,
    select ?String? for Message Type, and put a checkmark in the box ?String Expressions?.
  4. Now, click ?Send to Master?, and that response string will be sent as though it?s
    coming from the actual device connected to serial port 1 ( 5001:1:0) which will be/is
    our television. The program will go through it?s parsing routine and you should see
    bTVPowerFlag change to 1.
  5. Type ?$7F, $70, $80, $F8, $03, $01, $80, $02, $12? into the ?Message(s) to send? window
    and click ?Send to Master? and you should see the variable bTVPowerFlag change to 0.
    You?ll see the incoming string in Notifications as though it just came from the TV connected
    to serial port 1 on the master.

You can use this for web scraping or IP data too. After you?ve written your nice parsing routine, you would enter the TCP/IP port you defined (0:2:1 for example ? though you probably used the shortcut 0:2:0 in your program) in the d[noparse]:p:s[/noparse] boxes for ?emulate a device?. 0 for device number, 2 for port number and 1 for the system number. Select ?String? for the data, uncheck the ?String Expressions? box, and enter the HTML or XML code you want to parse into the ?Message(s) to send? window, click ?Send to Master? and see if your program parses it properly.

You can grab the HTML/XML code from a website by using ?view page source? in your browser, then copying to the clipboard. This allows you to test an offline IP controlled device or a website without having to deal with all the connection issues or you can simulate different webpages.



  • John GonzalesJohn Gonzales Junior Member Posts: 609
    One of the caveats by the way is that if the data contains $00, then everything gets screwed up and this method doesn't work. This is true as of Netlinx Studio v 2.5.

  • yuriyuri Junior Member Posts: 861
    yeah, sending $00 can't be done...

    this is the way I do it:

    Load Docklight (http://www.docklight.de/)
    Open a previous command list, or create a new one.
    Connect RS232 cable from PC to Netlinx Controller
    Send and test!


    Able to save RS232 command strings for later use.
    Easy way to change commando's
    Able to "repeat" a commando over and over again.

    None :)

    Anyways, thanks for the tips John!
  • jjamesjjames Just another dude Posts: 2,906
    yuri wrote: »
    None :)

    No no, shouldn't it be...
    Costs ~$72 :(

  • Rich AbelRich Abel Junior Member Posts: 104
    Emulate a device - Duet Module?

    Any reason why this approach (using Diagnostics-Emulate a Device) wouldn't work to test your data_event for a Duet module?

    I've had good success using the approach outlined by John Gonzales for serial controlled real devices, but I'm not having any luck using it to test the command Data-Event for a inConcert sourced Duet module.

    Should this work?

    Rich Abel
  • TurnipTruckTurnipTruck Junior Member Posts: 1,485
    Try creating a variable that will hold your test string. Use a virtual channel to cause the test string to send out. You can edit the test string in debug at will then resend.
  • viningvining X Member Posts: 4,368
    When I'm being lazy (normally) I just create a flag var and a string var like this:
    dvSomeDEV	= 5001:1:0 ;
    VOLATILE INTEGER cVarStrToSend[128] ;
         nSomeVAR = 0 ;
         SEND_STRING dvSomeDEV,cVarStrToSend ;
    Then in the debug window I'll drop in the 2 vars, change the string as desired and then fire the string by just changing nSomeVAR to 1.
  • Rich AbelRich Abel Junior Member Posts: 104
    using emulate device....

    Thanks, I'll give that a try.

  • yuriyuri Junior Member Posts: 861
    jjames wrote: »
    No no, shouldn't it be...
    Costs ~$72 :(


    really? i got it from work so... ;)
  • HedbergHedberg Junior Member Posts: 671
    Another nice terminal/telnet client is Indigo by shadeblue.http://www.shadeblue.com/ It has lots of capabilities and is easy to use. It's also about $26 for a licensed copy. I've been using it for about four years and updates have always been free.

    Also, it seems to be quite "AMX friendly." I'm told that the person who is responsible for it has a lot of experience with AMX, which would explain why.
  • jjamesjjames Just another dude Posts: 2,906
    yuri wrote: »
    really? i got it from work so... ;)
    Yeah - for a true "licensed" version it'll cost that much. ;)
Sign In or Register to comment.