Using ?Emulate a Device? to test your parsing routines
John Gonzales
Posts: 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.
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
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.
- Open up debug and load the variable bTVPowerFlag so that you can monitor it.
- 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). - 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?. - 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. - 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
0
Comments
--John
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!
Pros:
Able to save RS232 command strings for later use.
Easy way to change commando's
Able to "repeat" a commando over and over again.
Cons:
None
Anyways, thanks for the tips John!
No no, shouldn't it be...
Cons:
Costs ~$72
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?
Thx
Rich Abel
Thanks, I'll give that a try.
Rich
really? i got it from work so...
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.