A random Programming Example -- DSS Music Channels
I wanted to start some posts showing actual use of some of the Netlinx programming language. I figure this might help some folks out that are trying to learn the language. Hopefully there will be additional responses that show other ways of accomplishing the same task, to further the learning experience and spark conversation regarding programming techniques.
Following is a random example of how to select Favorite Music Channels on a DSS receiver. There are several ways to do this, feel free to post other ways, or shortcuts.
Main Keywords used:
Send_Command
XCH
XCHM
ITOA
button.input.channel
DATA_EVENT
Online:
TP Setup:
The touchpanel would have a page that has individual buttons labelled with the Music Station, e.g. "The 40's, The 50's, etc...". The buttons would be assigned a Channel Code in TPD4 that is the same as the station number, e.g. "The 40's" is channel 801 on DirecTV, so you would assign the Channel Code as 801 when you design the Touchpanel page. If there are future changes to the channel lineup on the satellite TV service provider, you can adjust the channel codes on the touchpanel which will affect the button.input.channel that is sent through the XCH command.
--John
Following is a random example of how to select Favorite Music Channels on a DSS receiver. There are several ways to do this, feel free to post other ways, or shortcuts.
Main Keywords used:
Send_Command
XCH
XCHM
ITOA
button.input.channel
DATA_EVENT
Online:
TP Setup:
The touchpanel would have a page that has individual buttons labelled with the Music Station, e.g. "The 40's, The 50's, etc...". The buttons would be assigned a Channel Code in TPD4 that is the same as the station number, e.g. "The 40's" is channel 801 on DirecTV, so you would assign the Channel Code as 801 when you design the Touchpanel page. If there are future changes to the channel lineup on the satellite TV service provider, you can adjust the channel codes on the touchpanel which will affect the button.input.channel that is sent through the XCH command.
DEFINE_DEVICE
(*ACTUAL DEVICES*)
dvDSS=5001:1:0 //SONY HD DSS Receiver
(*TOUCHPANEL PAGES*)
tpDSS=10001:1:0 //DSS Page on Touchpanel
DEFINE_VARIABLE
INTEGER MUSIC_FAVORITE_CHAN[] =
{800,801,802,803,804,805,806,807,808,809,
810,811,812,813,814,815,816,817,818,819,
820,821,822,823,824,825,826,827,828,829,
830,831,832,833,834,835,836,837,838,839,
840,841,842,843,844,845,846,847,848,849,
850,851,852,853,854,855,856,857,858,859,
860,861,862,863,864,865,866,867,868,869,
870,871,872,873,874,875,876,877,878,879}
DEFINE_EVENT
DATA_EVENT[dvDSS]
{
ONLINE:
{
SEND_COMMAND dvDSS, 'XCHM-1'
}
}
BUTTON_EVENT[tpDSS,MUSIC_FAVORITE_CHAN] //Button Press - Favorite Music Channel
{
PUSH:
{
SEND_COMMAND dvDSS,"'XCH ',ITOA(Button.Input.Channel)"
}
}
--John
Comments
Keyword Discussion:
Send_Command - used to send a command to a port on the Netlinx. The device would be connected to the Netlinx port via IR, RS-232, Contact Closure, etc... This is one of the basics of sending commands to a device.
XCH - Transmit the selected channel IR codes in the format/pattern set by the 'XCHM' send command.
XCHM - Sets the pattern for the IR commands sent by 'XCH'. See Sofware History for an explanation of the Modes and Syntax.
ITOA - Converts an integer to an ASCII value.
button.input.channel - This is a button object or information that gets stored when a button is pressed. When a button is pressed, information about the button is stored in several variables which you can access. Button.input.channel will be the value of the channel code of the button that was pressed.
DATA_EVENT - This is an event handler. When Netlinx detects that an event occurs, it will look for an event handler to tell it what to do. In the programming example above it looks for an Online event to happen. When the Online event happens for dvDSS it executes the code after the Online:. Another event would be when a button is pressed on an attached Touchpanel... that would be a BUTTON_EVENT
--John
PROGRAM_NAME='SAT,Rev 1' (***********************************************************) (* FILE CREATED ON: 09/09/2004 AT: 18:32:41 *) (***********************************************************) (* FILE_LAST_MODIFIED_ON: 02/11/2005 AT: 12:04:38 *) (***********************************************************) (* FILE REVISION: Rev 1 *) (* REVISION DATE: 11/16/2005 AT: 09:39:46 *) (* *) (* COMMENTS: *) (* ExpressVu 9200 replaces 6000 *) (* *) (***********************************************************) (***********************************************************) (* CONSTANT DEFINITIONS GO BELOW *) (***********************************************************) DEFINE_CONSTANT INTEGER BT_CRSRUP_SAT = 2 INTEGER BT_CRSRRT_SAT = 5 INTEGER BT_CRSRDN_SAT = 4 INTEGER BT_CRSRLF_SAT = 6 INTEGER BT_MENU_SAT = 1 INTEGER BT_SELECT_SAT = 3 INTEGER BT_GUIDE_SAT = 7 INTEGER BT_EXIT_SAT = 30 INTEGER BT_INFO_SAT = 8 INTEGER BT_PAGEUP_SAT = 31 INTEGER BT_PAGEDN_SAT = 32 INTEGER BT_RECALL_SAT = 24 INTEGER IR_CRSRUP_SAT = 45 INTEGER IR_CRSRRT_SAT = 48 INTEGER IR_CRSRDN_SAT = 46 INTEGER IR_CRSRLF_SAT = 47 INTEGER IR_SELECT_SAT = 49 INTEGER IR_GUIDE_SAT = 53 INTEGER IR_EXIT_SAT = 58 INTEGER IR_INFO_SAT = 61 INTEGER IR_PAGEUP_SAT = 64 INTEGER IR_PAGEDN_SAT = 65 INTEGER IR_RECALL_SAT = 60 INTEGER IR_SEARCH_SAT = 56 INTEGER IR_FORMAT_SAT = 57 INTEGER IR_VIEW_SAT = 59 INTEGER IR_SYSINFO_SAT = 62 INTEGER IR_RECORD_SAT = 63 INTEGER BT_POWER_SAT = 9 INTEGER BT_CHNLUP_SAT = 22 INTEGER BT_CHNLDN_SAT = 23 INTEGER BT_NUM1_SAT = 11 INTEGER BT_NUM2_SAT = 12 INTEGER BT_NUM3_SAT = 13 INTEGER BT_NUM4_SAT = 14 INTEGER BT_NUM5_SAT = 15 INTEGER BT_NUM6_SAT = 16 INTEGER BT_NUM7_SAT = 17 INTEGER BT_NUM8_SAT = 18 INTEGER BT_NUM9_SAT = 19 INTEGER BT_NUM0_SAT = 20 INTEGER BT_ENTER_SAT = 21 INTEGER BT_CANCEL_SAT = NULLCHANNEL INTEGER VT_CHANNEL_SAT = 1 INTEGER VT_KEYPAD_SAT = 1 // Stations INTEGER BT_PS1_SAT = 130 INTEGER BT_PS2_SAT = 131 INTEGER BT_PS3_SAT = 132 INTEGER BT_PS4_SAT = 133 INTEGER BT_PS5_SAT = 134 INTEGER BT_PS6_SAT = 135 INTEGER BT_PS7_SAT = 136 INTEGER BT_PS8_SAT = 137 INTEGER BT_PS9_SAT = 138 INTEGER BT_PS10_SAT = 139 INTEGER BT_PS11_SAT = 140 INTEGER BT_PS12_SAT = 141 INTEGER BT_PS13_SAT = NULLCHANNEL INTEGER BT_PS14_SAT = NULLCHANNEL INTEGER BT_PS15_SAT = NULLCHANNEL INTEGER BT_PS16_SAT = NULLCHANNEL INTEGER BT_PS17_SAT = NULLCHANNEL INTEGER BT_PS18_SAT = NULLCHANNEL INTEGER BT_PS19_SAT = NULLCHANNEL INTEGER BT_PS20_SAT = NULLCHANNEL INTEGER BT_PS21_SAT = NULLCHANNEL INTEGER BT_PS22_SAT = NULLCHANNEL INTEGER BT_PS23_SAT = NULLCHANNEL INTEGER BT_PS24_SAT = NULLCHANNEL INTEGER BT_PS25_SAT = NULLCHANNEL INTEGER BT_PS26_SAT = NULLCHANNEL INTEGER BT_PS27_SAT = NULLCHANNEL INTEGER BT_PS28_SAT = NULLCHANNEL INTEGER BT_PS29_SAT = NULLCHANNEL INTEGER BT_PS30_SAT = NULLCHANNEL INTEGER BT_PS31_SAT = NULLCHANNEL INTEGER BT_PS32_SAT = NULLCHANNEL INTEGER BT_PS33_SAT = NULLCHANNEL INTEGER BT_PS34_SAT = NULLCHANNEL INTEGER BT_PS35_SAT = NULLCHANNEL INTEGER BT_PS36_SAT = NULLCHANNEL INTEGER BT_PS37_SAT = NULLCHANNEL INTEGER BT_PS38_SAT = NULLCHANNEL INTEGER BT_PS39_SAT = NULLCHANNEL INTEGER BT_PS40_SAT = NULLCHANNEL INTEGER BT_PS41_SAT = NULLCHANNEL INTEGER BT_PS42_SAT = NULLCHANNEL INTEGER BT_PS43_SAT = NULLCHANNEL INTEGER BT_PS44_SAT = NULLCHANNEL INTEGER BT_PS45_SAT = NULLCHANNEL INTEGER BT_PS46_SAT = NULLCHANNEL INTEGER BT_PS47_SAT = NULLCHANNEL INTEGER BT_PS48_SAT = NULLCHANNEL INTEGER BT_PS49_SAT = NULLCHANNEL INTEGER BT_PS50_SAT = NULLCHANNEL // Stations INTEGER VT_PS1_SAT = 130 INTEGER VT_PS2_SAT = 131 INTEGER VT_PS3_SAT = 132 INTEGER VT_PS4_SAT = 133 INTEGER VT_PS5_SAT = 134 INTEGER VT_PS6_SAT = 135 INTEGER VT_PS7_SAT = 136 INTEGER VT_PS8_SAT = 137 INTEGER VT_PS9_SAT = 138 INTEGER VT_PS10_SAT = 139 INTEGER VT_PS11_SAT = 140 INTEGER VT_PS12_SAT = 141 INTEGER VT_PS13_SAT = NULLCHANNEL INTEGER VT_PS14_SAT = NULLCHANNEL INTEGER VT_PS15_SAT = NULLCHANNEL INTEGER VT_PS16_SAT = NULLCHANNEL INTEGER VT_PS17_SAT = NULLCHANNEL INTEGER VT_PS18_SAT = NULLCHANNEL INTEGER VT_PS19_SAT = NULLCHANNEL INTEGER VT_PS20_SAT = NULLCHANNEL INTEGER VT_PS21_SAT = NULLCHANNEL INTEGER VT_PS22_SAT = NULLCHANNEL INTEGER VT_PS23_SAT = NULLCHANNEL INTEGER VT_PS24_SAT = NULLCHANNEL INTEGER VT_PS25_SAT = NULLCHANNEL INTEGER VT_PS26_SAT = NULLCHANNEL INTEGER VT_PS27_SAT = NULLCHANNEL INTEGER VT_PS28_SAT = NULLCHANNEL INTEGER VT_PS29_SAT = NULLCHANNEL INTEGER VT_PS30_SAT = NULLCHANNEL INTEGER VT_PS31_SAT = NULLCHANNEL INTEGER VT_PS32_SAT = NULLCHANNEL INTEGER VT_PS33_SAT = NULLCHANNEL INTEGER VT_PS34_SAT = NULLCHANNEL INTEGER VT_PS35_SAT = NULLCHANNEL INTEGER VT_PS36_SAT = NULLCHANNEL INTEGER VT_PS37_SAT = NULLCHANNEL INTEGER VT_PS38_SAT = NULLCHANNEL INTEGER VT_PS39_SAT = NULLCHANNEL INTEGER VT_PS40_SAT = NULLCHANNEL INTEGER VT_PS41_SAT = NULLCHANNEL INTEGER VT_PS42_SAT = NULLCHANNEL INTEGER VT_PS43_SAT = NULLCHANNEL INTEGER VT_PS44_SAT = NULLCHANNEL INTEGER VT_PS45_SAT = NULLCHANNEL INTEGER VT_PS46_SAT = NULLCHANNEL INTEGER VT_PS47_SAT = NULLCHANNEL INTEGER VT_PS48_SAT = NULLCHANNEL INTEGER VT_PS49_SAT = NULLCHANNEL INTEGER VT_PS50_SAT = NULLCHANNEL (***********************************************************) (* VARIABLE DEFINITIONS GO BELOW *) (***********************************************************) DEFINE_VARIABLE VOLATILE INTEGER nPowerSenseSAT[ ] = {0} VOLATILE INTEGER nTpBtShuttleSAT[ ] = {BT_CRSRUP_SAT, BT_CRSRRT_SAT, BT_CRSRDN_SAT, BT_CRSRLF_SAT, BT_MENU_SAT, BT_SELECT_SAT, BT_GUIDE_SAT, BT_EXIT_SAT, BT_INFO_SAT, BT_PAGEUP_SAT, BT_PAGEDN_SAT} // BT_RECALL_SAT} VOLATILE INTEGER nIrSlotsSAT[ ] = {IR_CRSRUP_SAT, IR_CRSRRT_SAT, IR_CRSRDN_SAT, IR_CRSRLF_SAT, IR_GUIDE_SAT, IR_SELECT_SAT, IR_GUIDE_SAT, IR_EXIT_SAT, IR_INFO_SAT, IR_PAGEUP_SAT, IR_PAGEDN_SAT} // IR_RECALL_SAT} VOLATILE INTEGER DEBUG_SAT = 1 VOLATILE INTEGER nTpBtChannelSAT[ ] = {BT_CHNLUP_SAT, BT_CHNLDN_SAT, BT_RECALL_SAT} VOLATILE INTEGER nTpBtChannelKeypadSAT[ ] = {BT_NUM1_SAT, BT_NUM2_SAT, BT_NUM3_SAT, BT_NUM4_SAT, BT_NUM5_SAT, BT_NUM6_SAT, BT_NUM7_SAT, BT_NUM8_SAT, BT_NUM9_SAT, BT_NUM0_SAT, BT_ENTER_SAT, BT_CANCEL_SAT} //VOLATILE INTEGER nTpVtKeypad_SAT = VT_KEYPAD_SAT VOLATILE INTEGER nTpVtChannel_SAT = VT_CHANNEL_SAT VOLATILE INTEGER nTpBtPresets_SAT[ ] = {BT_PS1_SAT, BT_PS2_SAT, BT_PS3_SAT, BT_PS4_SAT, BT_PS5_SAT, BT_PS6_SAT, BT_PS7_SAT, BT_PS8_SAT, BT_PS9_SAT, BT_PS10_SAT, BT_PS11_SAT, BT_PS12_SAT, BT_PS13_SAT, BT_PS14_SAT, BT_PS15_SAT, BT_PS16_SAT, BT_PS17_SAT, BT_PS18_SAT, BT_PS19_SAT, BT_PS20_SAT, BT_PS21_SAT, BT_PS22_SAT, BT_PS23_SAT, BT_PS24_SAT, BT_PS25_SAT, BT_PS26_SAT, BT_PS27_SAT, BT_PS28_SAT, BT_PS29_SAT, BT_PS30_SAT, BT_PS31_SAT, BT_PS32_SAT, BT_PS33_SAT, BT_PS34_SAT, BT_PS35_SAT, BT_PS36_SAT, BT_PS37_SAT, BT_PS38_SAT, BT_PS39_SAT, BT_PS40_SAT, BT_PS41_SAT, BT_PS42_SAT, BT_PS43_SAT, BT_PS44_SAT, BT_PS45_SAT, BT_PS46_SAT, BT_PS47_SAT, BT_PS48_SAT, BT_PS49_SAT, BT_PS50_SAT} VOLATILE INTEGER nTpVtPresets_SAT[ ] = {VT_PS1_SAT, VT_PS2_SAT, VT_PS3_SAT, VT_PS4_SAT, VT_PS5_SAT, VT_PS6_SAT, VT_PS7_SAT, VT_PS8_SAT, VT_PS9_SAT, VT_PS10_SAT, VT_PS11_SAT, VT_PS12_SAT, VT_PS13_SAT, VT_PS14_SAT, VT_PS15_SAT, VT_PS16_SAT, VT_PS17_SAT, VT_PS18_SAT, VT_PS19_SAT, VT_PS20_SAT, VT_PS21_SAT, VT_PS22_SAT, VT_PS23_SAT, VT_PS24_SAT, VT_PS25_SAT, VT_PS26_SAT, VT_PS27_SAT, VT_PS28_SAT, VT_PS29_SAT, VT_PS30_SAT, VT_PS31_SAT, VT_PS32_SAT, VT_PS33_SAT, VT_PS34_SAT, VT_PS35_SAT, VT_PS36_SAT, VT_PS37_SAT, VT_PS38_SAT, VT_PS39_SAT, VT_PS40_SAT, VT_PS41_SAT, VT_PS42_SAT, VT_PS43_SAT, VT_PS44_SAT, VT_PS45_SAT, VT_PS46_SAT, VT_PS47_SAT, VT_PS48_SAT, VT_PS49_SAT, VT_PS50_SAT} VOLATILE CHAR cDeviceFileId_SAT[20] //PERSISTENT INTEGER nLastChannel_SAT[6] //PERSISTENT INTEGER nJumpChannel_SAT[6] (***********************************************************) (* STARTUP CODE GOES BELOW *) (***********************************************************) DEFINE_START cDeviceFileId_SAT = 'dvIR_SAT' DEFINE_MODULE 'Deck[]' deckSAT_1 (vdvIR_SAT, dvIR_SAT, dvTP_SAT, nPowerSenseSAT, nTpBtShuttleSAT, nIrSlotsSAT, DEBUG_SAT) DEFINE_MODULE 'ChannelChanger[] with Presets,Rev 0' ChannelChangerSAT (vdvIR_SAT, dvIR_SAT, dvTP_SAT, dvTP, nTpBtChannelSAT, nTpBtChannelKeypadSAT, nTpVtChannel_SAT, nTpBtPresets_SAT, nTpVtPresets_SAT, cDeviceFileId_SAT, DEBUG_SAT) (***********************************************************) (* THE EVENTS GO BELOW *) (***********************************************************) DEFINE_EVENT DATA_EVENT[dvIR_SAT] { ONLINE: { SEND_COMMAND DATA.DEVICE, "'CTON',3" SEND_COMMAND DATA.DEVICE, "'CTOF',2" SEND_COMMAND DATA.DEVICE,'XCHM 0' SEND_COMMAND vdvIR_SAT,'SETDECK=1:1' SEND_COMMAND vdvIR_SAT,'SETDECK=1:2' } } BUTTON_EVENT[dvTP_SAT,BT_POWER_SAT] { PUSH: { STACK_VAR INTEGER iTp, iDevice TO[BUTTON.INPUT] iTp = GET_LAST(dvTP_SAT) iDevice=1 SEND_COMMAND vdvIR_SAT,"FORMAT('POWER=%d:TOGGLE',iDevice)" } }I somewhat do the same thing as John, except I don't use an array for the channels. I also tend to stay away from the XCH command, so I use the little routine that was shared under another thread. I'll make all the DSS (or cable) channels a specific port on the panel, and code it like so.
DEFINE_DEVICE dvTP_CAB = 10001:02:00 // Cable Channel DEFINE_EVENT BUTTON_EVENT[dvTP_CAB,BUTTON.INPUT.CHANNEL] { PUSH: CALL 'SEND DSS STATION' (BUTTON.INPUT.CHANNEL) }This will call the routine when ANY button that is on port 2 of the touch panel is pressed, and send the button number to the routine.Just a little short cut. This way, I don't have to type up an array for which channels I use, and also if the client wants channels changed, I don't need to do anything with code. It's a simple change in the TP file, and the processor doesn't need to be reloaded with a channel number change.
DEFINE_VARIABLE VOLATILE INTEGER iChannelButtons[] = { 1, 2, 3, 4 } // ...etc. VOLATILE CHAR sChannels[][3] = {{'801'}, {'802'}, {'803'}, {'804'}} ; // etc. DEFINE_EVENT BUTTON_EVENT [dvTP, iChannelButtons] { PUSH : SEND_COMMAND dvSAT, "'XCH ', sChannels[GET_LAST(iCHannelButtons)]" }All you need do is make sure the channel number in sChannels is in the same position in the array as the corresponding button channel in iChannelButtons. It's also easy to update when there is a channel lineup change. You can take it a step further, and send variable texts to the buttons with a station name the same way and never have to touch the panel file, but I like to put station logos in there - no quick way of doing that. For music channels, that's still feasible, but not any with unique logos (though I guess if you really wanted to, you could index those as well and change them around in code, but it seems easier to me just to edit the panel).My new and improved fusion powered NI-3905 has built-in Ultra extended HD TiVo DSS/MAX Mark VI content server with 500 terabyte removeable USB HD, 10kW/channel Dolby 11.1 GPS surround sound, and advanced ESP processor with alpha wave discriminator. They have also manangerd to reduce the size to a single rack space and dropped the price to $295. MSP.
Excuse me? How does defining a button with a higher number than the last undefined button burden memory and resources??? I think you are confused with declaring master port devices.
Fixed it