Home AMX User Forum NetLinx Studio

Help with file_open command & xch

Writing this to use with Directv XM channels

2 Things I need help with:

1. Its Listing the first 8 Channels need to have it list the next 8 or previous 8 when the page up / page down buttons are pressed *** Still working on it :)

2. The xch is only sending 2 pluses need it to send at least 3 ( ex 823 ) maybe 4 ( enter ) **** FIXED Thanks to Ricardo
PROGRAM_NAME='Sat Music'
(***********************************************************)
(* System Type : NetLinx                                   *)
(***********************************************************)
(* REV HISTORY:                                            *)
(***********************************************************)

(***********************************************************)
(*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_DEVICE

dvTP = 10001:1:1
dvSatM = 5001:10:1
(***********************************************************)
(*               CONSTANT DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_CONSTANT

(***********************************************************)
(*              DATA TYPE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_TYPE

STRUCTURE _PRESET
{
    CHAR NAME[75]
    INTEGER NUMBER
}

(***********************************************************)
(*               VARIABLE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_VARIABLE

INTEGER INC
INTEGER SettingPreset
_PRESET PRESET[78]
(***********************************************************)
(*               LATCHING DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_LATCHING

(***********************************************************)
(*       MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW           *)
(***********************************************************)
DEFINE_MUTUALLY_EXCLUSIVE

(***********************************************************)
(*        SUBROUTINE/FUNCTION DEFINITIONS GO BELOW         *)
(***********************************************************)
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)

DEFINE_CALL 'Refresh Preset Display'
{
    //INTEGER INC
    FOR(INC=1;INC<=78; INC++)
    {
	SEND_COMMAND dvTP,"'!T',70 + INC,Preset[INC].Name"
    }
}

DEFINE_CALL 'Recall Preset' (INTEGER NUM)
{
    SEND_COMMAND dvTP,"'!T',60,Preset[NUM].Number"
    SEND_COMMAND dvTP,"'!T',70,Preset[NUM].Name"
    SEND_COMMAND dvSatM,"'XCH',ITOA(Preset[NUM].Number)"
}

(***********************************************************)
(*                STARTUP CODE GOES BELOW                  *)
(***********************************************************)
DEFINE_START

(* System Information Strings ******************************)
(* Use this section if there is a TP in the System!        *)
(*
    SEND_COMMAND TP,"'!F',250,'1'"
    SEND_COMMAND TP,"'TEXT250-',__NAME__"
    SEND_COMMAND TP,"'!F',251,'1'"
    SEND_COMMAND TP,"'TEXT251-',__FILE__,', ',S_DATE,', ',S_TIME"
    SEND_COMMAND TP,"'!F',252,'1'"
    SEND_COMMAND TP,"'TEXT252-',__VERSION__"
    SEND_COMMAND TP,"'!F',253,'1'"
    (* Must fill this (Master Ver) *)
    SEND_COMMAND TP,'TEXT253-'
    SEND_COMMAND TP,"'!F',254,'1'"
    (* Must fill this (Panel File) *)
    SEND_COMMAND TP,'TEXT254-'
    SEND_COMMAND TP,"'!F',255,'1'"
    (* Must fill this (Dealer Info) *)
    SEND_COMMAND TP,'TEXT255-'
*)
(***********************************************************)
(*                THE EVENTS GO BELOW                      *)
(***********************************************************)
DEFINE_EVENT

BUTTON_EVENT[dvTP,1]
{
    PUSH:
    {
	SLONG Handle
	SLONG Result
	CHAR ONELINE[50]
	//INTEGER INC
	Handle = FILE_OPEN('xm.csv',1)
	IF(Handle > 0)
	{
	    FOR(INC = 1;INC<=78; INC ++)
	    {
		RESULT = FILE_READ_LINE(Handle,ONELINE,MAX_LENGTH_ARRAY(ONELINE))
		IF(Result > 0)
		{
		    Preset[Inc].Name = REMOVE_STRING(oneline,',',1)
		    SET_LENGTH_STRING(Preset[INC].Name,LENGTH_STRING(Preset[Inc].Name)-1)
		    Preset[INC].Number = ATOI(ONELINE)
		}
		ELSE
		{
		    SEND_STRING 0,"'UH OH:FILE READ BAD',ITOA(Handle)"
		    BREAK
		}
	    }
	}
	ELSE
	{
	    SEND_STRING 0,"'UH OH:FILE READ BAD',ITOA(Handle)"
	    
	    CALL 'Refresh Preset Display'
	}
    }
}


BUTTON_EVENT[dvTP,71]
BUTTON_EVENT[dvTP,72]
BUTTON_EVENT[dvTP,73]
BUTTON_EVENT[dvTP,74]
BUTTON_EVENT[dvTP,75]
BUTTON_EVENT[dvTP,76]
BUTTON_EVENT[dvTP,77]
BUTTON_EVENT[dvTP,78]
{
    PUSH:
    {
	SettingPreset = 0
    }
    RELEASE:
    {
	IF(NOT SettingPreset)
	{
	    CALL 'Recall Preset' (Button.Input.Channel - 70)
	}
	
    }
}
(***********************************************************)
(*            THE A CTUAL PROGRAM GOES BELOW               *)
(***********************************************************)
DEFINE_PROGRAM

(***********************************************************)
(*                     END OF PROGRAM                      *)
(*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
(***********************************************************)


Just made a simple tp interface to test

Any suggestions or ideas would be great

Thanks everyone

Comments

  • DHawthorneDHawthorne Posts: 4,584
    There is an XCHM command to set the format of channels sent to your device via XCH. Look it up in Software History for the right one for your device.

    The way I do scrolling lists is just to track an index based on where in the list my first item is right now, then calculate what I need to display based on how many lines my list holds. Then the up and down buttons increment/decrement the index accordingly. So, to start you set it to 1 (and you can make it a persistent variable so it always remembers where it was last). If you have 10 lines of presets to display, you don't need to read your entire file, you just read 1-10. I make the list size a variable so it can be transfered to different panels, so the FOR loop would read something like:
    FOR(nDisplayLine = nIndex; nDisplayLine <= (nIndex + nListLength - 1); nDisplayLine ++)
    <<read data and display on panel here>>
    
    When you read your actual file values, you will need to test you haven't hit the end of the list, then black out the extra lines. Your increment function would be something like:
    IF(nIndex + nListLength < nListSize)
         nIndex = nIndex + nListLength
    
    ... and the decrement:
    IF(nIndex > nListLength) 
        nIndex = nIndex - nListLength
    
  • Make sure there is a space after the XCH:
    SEND_COMMAND dvSatM,"'XCH',ITOA(Preset[NUM].Number)" //YOUR CODE
    
    SEND_COMMAND dvSatM,"'XCH ',ITOA(Preset[NUM].Number)"  //CODE WITH SPACE
    

    This should fix the XCH sending only 2 digits. I did the same mistake in the past.

    Consider also defining the XCHM mode type like this (see Software History on a NI IR for more info):
    DATA_EVENT[dvCABLE_MediaRoom ]
    {
        ONLINE:                 //IR device comes ONLINE
        {
            SEND_COMMAND dvSatM ,'SET MODE IR'
            SEND_COMMAND dvSatM ,'CARON'
            SEND_COMMAND dvSatM ,"'CTON',3"
            SEND_COMMAND dvSatM ,"'CTOF',3"
            SEND_COMMAND dvSatM ,'XCHM-1'     // there are 5 modes 0, 1, 2, 3, 4
        }
    }
    

    Make sure your structure is loaded with all the channels you want, use the debug window to see your structure. You may also consider loading your structure when the Master starts instead of on a button push. I hope the above helps,

    Ricardo
  • ondrovicondrovic Posts: 217
    Thanks for the help guys I will give your suggestions a try and report back :)
  • ondrovicondrovic Posts: 217
    DHawthorne wrote:
    There is an XCHM command to set the format of channels sent to your device via XCH. Look it up in Software History for the right one for your device.

    The way I do scrolling lists is just to track an index based on where in the list my first item is right now, then calculate what I need to display based on how many lines my list holds. Then the up and down buttons increment/decrement the index accordingly. So, to start you set it to 1 (and you can make it a persistent variable so it always remembers where it was last). If you have 10 lines of presets to display, you don't need to read your entire file, you just read 1-10. I make the list size a variable so it can be transfered to different panels, so the FOR loop would read something like:
    FOR(nDisplayLine = nIndex; nDisplayLine <= (nIndex + nListLength - 1); nDisplayLine ++)
    <<read data and display on panel here>>
    
    When you read your actual file values, you will need to test you haven't hit the end of the list, then black out the extra lines. Your increment function would be something like:
    IF(nIndex + nListLength < nListSize)
         nIndex = nIndex + nListLength
    
    ... and the decrement:
    IF(nIndex > nListLength) 
        nIndex = nIndex - nListLength
    



    Thanks for the suggestion, but I think my brain said 'Oh No You Dont, Not Today'
    I will continue to work on it and hopefully it will click with me
  • ondrovicondrovic Posts: 217
    I have one morre weird thing that is going on

    After I update the code and reload it into the master it's set up to update the text on the TP
    DATA_EVENT[dvTP]
    {
        ONLINE:
        {
    	SEND_COMMAND dvTP,"'!T',70 + INC,Preset[INC].Name"
    	SEND_COMMAND dvTP,"'!T',71 + INC,Preset[INC].Name"
    	SEND_COMMAND dvTP,"'!T',72 + INC,Preset[INC].Name"
    	SEND_COMMAND dvTP,"'!T',73 + INC,Preset[INC].Name"
    	SEND_COMMAND dvTP,"'!T',74 + INC,Preset[INC].Name"
    	SEND_COMMAND dvTP,"'!T',75 + INC,Preset[INC].Name"
    	SEND_COMMAND dvTP,"'!T',76 + INC,Preset[INC].Name"
    	SEND_COMMAND dvTP,"'!T',77 + INC,Preset[INC].Name"
    	SEND_COMMAND dvTP,"'!T',78 + INC,Preset[INC].Name"
        }
    }
    
    or
    
    DATA_EVENT[dvTP]
    {
           ONLINE:
           { 
           CALL 'Refresh Preset Display'
           }
    }
    

    but for some reason the only way I am able to update the display is if I ftp to the master and delete the xm.csv the hit the refresh button and it updates correctly any ideas?
  • Joe HebertJoe Hebert Posts: 2,159
    File_close

    You need a FILE_CLOSE when you?re done reading the file.
Sign In or Register to comment.