Home AMX User Forum NetLinx Studio

Parasound zTuner

ondrovicondrovic Junior MemberPosts: 217
I writing a program to handle the Parasound zTuner. I am having an issue tyring to use the system keypad for direct station entry.

The keypad will return the following
92.7
-or-
100.7

But the zTuner's command to go to a direct frequency is the following
W 1 6 92 70
-or-
W 1 6 100 70

Here is what I have so far but could really use some help getting it to parse correctly
PROGRAM_NAME='zTuner'
(***********************************************************)
(***********************************************************)
(*  FILE_LAST_MODIFIED_ON: 04/05/2006  AT: 09:00:25        *)
(***********************************************************)
(* System Type : NetLinx                                   *)
(***********************************************************)
(* REV HISTORY:                                            *)
(***********************************************************)
(*
    $History: $
    
    200ms delay between commands or unit will lock up
    
    Version 1:
    ----------
    
    Control of the device; Presets, Tune, Band & Feedback
    
    Version 2:
    ----------
    
    Ability to push and hold Preset # and change the station
*)
(***********************************************************)
(*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_DEVICE

dvZtuner	=	5001:1:0
dvPanel		=	10024:1:0
(***********************************************************)
(*               CONSTANT DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_CONSTANT

Volatile Integer nZtuner_Preset_Buttons[]=
{
    500,	/// Preset 1
    501,	/// Preset 2
    502,	/// Preset 3
    503,	/// Preset 4
    504,	/// Preset 5
    505,	/// Preset 6
    506,	/// Preset 7
    507,	/// Preset 8
    508,	/// Preset 9
    509,	/// Preset 10
    510,	/// Preset 11
    511,	/// Preset 12
    512,	/// Preset 13
    513,	/// Preset 14
    514,	/// Preset 15
    515,	/// Preset 16
    516,	/// Preset 17
    517,	/// Preset 18
    518,	/// Preset 19
    519,	/// Preset 20
    520,	/// Preset 21
    521,	/// Preset 22
    522,	/// Preset 23
    523,	/// Preset 24
    524,	/// Preset 25
    525,	/// Preset 26
    526,	/// Preset 27
    527,	/// Preset 28
    528,	/// Preset 29
    529		/// Preset 30
    
}

Volatile Integer nZtuner_Tune_Buttons[]=
{
    530,	/// Auto Tune Up
    531,	/// Auto Tune Down
    532,	/// Manual Step Up
    533		/// Manual Step Down
}

Volatile Integer nZtuner_Band_Buttons[]=
{
    534,	/// FM
    535,	/// AM
    536		/// Band Toggle
}

Volatile Integer nZtuner_VText_Fields[]=
{
    1,		/// Display 1
    2,		/// Display 2
    3,		/// Display 3
    4		/// Display 4
}

Volatile Integer nZtuner_Preset_Control_Buttons[]=
{
    537,	/// Next Preset
    538		/// Previous Preset
}


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

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

Persistent Integer Debug_Status

(***********************************************************)
(*               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_Function Char debug(Char sMsg[])
{
    If(Debug_Status)
	Send_String 0,"'Debug : ',' Line : ',Itoa(__Line__),' :: ',sMsg"
}

Define_Function SysKP_Parsing(Char sQue[100])
{
    
    Local_Var Char sWork[25]
    Local_Var Char sTrash[25]
    
    If(Debug_Status)
	debug("'SysKP_Parsing :: ','sQue : ',sQue")
    
    sFormat(sQue)
    
    If(Debug_Status)
	debug("'SysKP_Parsing :: ','sQue : ',sQue")
    Send_String dvZtuner,"sQue,13"
}

Define_Function sFormat(Char sQue[100])
{
    Local_Var Char sWork[25]
    Local_Var Char sTrash[25]
    Local_Var Char sWork_Temp_1[25]
    Local_Var Char sWork_Temp_2[25]
    Local_Var Char sNum_1[4]
    Local_Var Char sNum_2[2]
    
    If(Debug_Status)				/// Debug information
	debug("'sFormat :: ','Formatting data.'")
    Select
    {
	Active(Find_String(sQue,'.',1)):
	{
	    If(Debug_Status)
		debug("'sFormat :: ','Found a . in the data.'")
	    
	}
	Active(!(Find_String(sQue,'.',1))):
	{
	    If(Debug_Status)
		debug("'sFormat :: ','Not a . in the data.'")
	    sNum_1 = Left_String(sQue,2)
	    If(Debug_Status)
		debug("'sFormat :: ','sNum_1 : ',sNum_1")
	    sNum_2 = Right_String(sQue,2)
		If(Debug_Status)
		    debug("'sFormat :: ','sNum_2 : ',sNum_2")
	    sQue = "sNum_1,' ',sNum_2"
		If(Debug_Status)
		    debug("'sFormat :: ','sQue : ',sQue")
	}
    }
}
(***********************************************************)
(*                STARTUP CODE GOES BELOW                  *)
(***********************************************************)
DEFINE_START

(***********************************************************)
(*                THE EVENTS GO BELOW                      *)
(***********************************************************)
DEFINE_EVENT

Data_Event[dvZtuner]
{
    Online:
    {
	Send_Command dvZtuner,"'SET BAUD 9600,N,8,1'"
	If(Debug_Status)
	    debug("'Device Online :: Setting Communication'")
    }
    String:
    {
	Local_Var Char sBuffer[500]
	Local_Var Char sTrash[500]
	Local_Var Char sTemp[500]
	
	Local_Var Char sStation[10]
	Local_Var Char sBand[2]
	
	sBuffer = Data.Text
    }
}

Data_Event[dvPanel]
{
    String:
    {
	Local_Var Char sQue[1000]
	Local_Var Char sTrash[100]
	Local_Var Char sResponse[100]
	
	sQue = Data.Text
	
	If(Debug_Status)
	    debug("'Data.Text : ',Data.Text")
	    
	Select
	{
	    Active(Find_String(sQue,'Radio-',1)):
	    {
		sTrash = Remove_String(sQue,'Radio-',1)
		
		If(Debug_Status)
		    debug("'Keypad Detection :: ','Set the keypad to Radio mode.'")
	    }
	    Active(Find_String(sQue,'KEYP-',1)):
	    {
		sTrash = Remove_String(sQue,'KEYP-',1)
		sResponse = Remove_String(sQue,sQue,1)
		If(Debug_Status)
		    debug("'Keypad Detection :: ','Send the keypad string to the function.',' sResponse : ',sResponse")
		SysKP_Parsing(sResponse)
	    }
	    Active(Find_String(sQue,'KEYB-',1)):
	    {
		sTrash = Remove_String(sQue,'KEYB-',1)
		sResponse = Remove_String(sQue,sQue,1)
		If(Debug_Status)
		    debug("'Keypad Detection :: ','Send the keyboard string to the function.',' sResponse : ',sResponse")
		SysKP_Parsing(sResponse)
	    }
	}
    }
}


Button_Event[dvPanel,nZtuner_Preset_Buttons]
{
    Push:
    {
	/// Do Nothing :)
    }
    Release:
    {
	Local_Var Integer nButton
	Local_Var Char sCmd[15]
	
	nButton = Get_Last(nZtuner_Preset_Buttons)
	
	sCmd = "'W 1 3 1 ',ITOA(nButton)"
	
	If(Debug_Status)
	    debug("'Radio Presets :: ','sCmd : ',sCmd")
	
	Send_String dvZtuner,"sCmd,13"
    }
    Hold[20]:
    {
	Local_Var Integer nButton
	Local_Var Char sCmd[15]
	
	nButton = Get_Last(nZtuner_Preset_Buttons)
	
	sCmd = "'W 1 3 2 ',Itoa(nButton)"
	
	If(Debug_Status)
	    debug("'Memorizing Channel into preset :: ','sCmd : ',sCmd")
	
	Send_String dvZtuner,"sCmd,13"
    }
}

Button_Event[dvPanel,nZtuner_Tune_Buttons]
{
    Push:
    {
	Local_Var Integer nButton
	Local_Var Char sCmd[15]
	
	nButton = Get_Last(nZtuner_Tune_Buttons)
	
	sCmd = "'W 1 7 ',ITOA(nButton)"
	
	If(Debug_Status)
	    debug("'Radio Tune :: ','sCmd : ',sCmd")
	
	Send_String dvZtuner,"sCmd,13"
    }
}

Button_Event[dvPanel,nZtuner_Band_Buttons]
{
    Push:
    {
	Local_Var Integer nButton
	Local_Var Char sCmd[15]
	
	nButton = Get_Last(nZtuner_Band_Buttons)
	
	
	If(nButton == 3)
	    nButton = 10
	
	sCmd = "'W 1 8 ',Itoa(nButton)"
	
	If(Debug_Status)
	    debug("'Radio Band :: ','sCmd : ',sCmd")
	    
	Send_String dvZtuner,"sCmd,13"
    }
}

Button_Event[dvPanel,nZtuner_Preset_Control_Buttons]
{
    Push:
    {
	Local_Var Integer nButton
	Local_Var Char sCmd[15]
	
	nButton = Get_Last(nZtuner_Preset_Control_Buttons) + 2
	
	sCmd = "'W 1 3 ',Itoa(nButton)"
	
	If(Debug_Status)
	    debug("'Radio Preset Control :: ','sCmd : ',sCmd")
	    
	Send_String dvZtuner,"sCmd,13"
    }
}

(***********************************************************)
(*            THE ACTUAL PROGRAM GOES BELOW                *)
(***********************************************************)
DEFINE_PROGRAM

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

Thanks

Comments

  • ErikJackmanErikJackman Junior Member Posts: 31
    Is the 92.7 coming from the turner or is tat the buttons pressed on the touch panel? If its just buttons pressed you could skip the step of formating the string one way just to reformat it later. Just keep track of the buttons pressed and build the string on the fly. Nothing says you can't build the human readable 92.7 string for the feedback and the rs-232 command at the same time from the same button presses. :D
  • ondrovicondrovic Junior Member Posts: 217
    Is the 92.7 coming from the turner or is tat the buttons pressed on the touch panel? If its just buttons pressed you could skip the step of formating the string one way just to reformat it later. Just keep track of the buttons pressed and build the string on the fly. Nothing says you can't build the human readable 92.7 string for the feedback and the rs-232 command at the same time from the same button presses. :D

    Buttons pressed on the touch panel ( im using the system keypad )

    But never mind I just worked it out
  • ErikJackmanErikJackman Junior Member Posts: 31
    ondrovic wrote: »
    Buttons pressed on the touch panel ( im using the system keypad )

    But never mind I just worked it out

    If it works great, but I think you did more work then you needed to. Good practice though. :D
  • ondrovicondrovic Junior Member Posts: 217
    I have finished everything with the code but I am having an issue displaying the feedback on the panel. I will upload the full workspace with panel. Here is the issue I am having:

    The feedback is correctly updating if I use the following code :
    Send_Command dvPanel,"'^TXT-',Itoa(nZtuner_VText_Fields[5]),',0,',sRadio_Data.sBand" ;
    

    It will display a
    1
    
    for FM and a
    2
    
    for AM

    However it will not work when trying to do this :
    Switch(sRadio_Data.sBand)
        {
    	Case 1:	{Send_Command dvPanel,"'^TXT-',Itoa(nZtuner_VText_Fields[5]),',0,','FM'"	Break}
    	Case 2:	{Send_Command dvPanel,"'^TXT-',Itoa(nZtuner_VText_Fields[5]),',0,','AM'"	Break}
        }
    

    What am I doing wrong?

    Thanks for the advice / help
  • Spire_JeffSpire_Jeff Formerly Caffeinated Programmer Posts: 1,917
    It looks like the 1 and 2 are ascii versions. Try this:
    Switch(ATOI(sRadio_Data.sBand))
        {
    	Case 1:	{Send_Command dvPanel,"'^TXT-',Itoa(nZtuner_VText_Fields[5]),',0,','FM'"	Break}
    	Case 2:	{Send_Command dvPanel,"'^TXT-',Itoa(nZtuner_VText_Fields[5]),',0,','AM'"	Break}
        }
    

    Or, you could do this:
    Switch(sRadio_Data.sBand)
        {
    	Case '1':	{Send_Command dvPanel,"'^TXT-',Itoa(nZtuner_VText_Fields[5]),',0,','FM'"	Break}
    	Case '2':	{Send_Command dvPanel,"'^TXT-',Itoa(nZtuner_VText_Fields[5]),',0,','AM'"	Break}
        }
    

    You could also add a default condition that alerts you to the fact that there was a problem.

    Jeff
  • ondrovicondrovic Junior Member Posts: 217
    I will give that a try and let you know thanks Jeff
  • DHawthorneDHawthorne Old Timer Posts: 4,584
    Just as an aside, the BREAK statements are not necessary in NetLinx. I suppose it doesn't hurt, but NetLinx won't drop through to the next case ever anyway. The same goes for SELECT...ACTIVE statements.
  • ondrovicondrovic Junior Member Posts: 217
    Spire_Jeff wrote: »
    It looks like the 1 and 2 are ascii versions. Try this:
    Switch(sRadio_Data.sBand)
        {
    	Case '1':	{Send_Command dvPanel,"'^TXT-',Itoa(nZtuner_VText_Fields[5]),',0,','FM'"	Break}
    	Case '2':	{Send_Command dvPanel,"'^TXT-',Itoa(nZtuner_VText_Fields[5]),',0,','AM'"	Break}
        }
    

    You could also add a default condition that alerts you to the fact that there was a problem.

    Jeff

    Worked like a charm thanks again
  • ondrovicondrovic Junior Member Posts: 217
    Having an issue with the am tuning when done from a keypad. It only works on some of the am channels, any adive based on the code i have? Seems like it isn't working with 3-digit am stations works fine with 4-digits ones.

    Thanks

    *** EDIT : Fixed it :) ***
  • ondrovicondrovic Junior Member Posts: 217
    Would really like to turn this into a module instead of a include file, but I haven't ever made a module before could someone who has experience with modules help me out?

    Thanks

    Chris Ondrovic
  • ondrovicondrovic Junior Member Posts: 217
    Module Progress

    Here is as far as I have gotten. ( First attempt @ writing a module )

    I can successfully control the zTuner via the CP4 & MVP.
    The MVP I have control, debug statements & feedback.
    The CP4 controls the device but will not update the feedback, it will also not trigger the debug that is programmed into the code.

    Any ideas?

    Main Program
    PROGRAM_NAME='zTuner'
    (***********************************************************)
    (***********************************************************)
    (*  FILE_LAST_MODIFIED_ON: 04/05/2006  AT: 09:00:25        *)
    (***********************************************************)
    (* System Type : NetLinx                                   *)
    (***********************************************************)
    (* REV HISTORY:                                            *)
    (***********************************************************)
    (*
        $History: $
        
        200ms delay between commands or unit will lock up [x]
        
        Version 1: - Done
        ----------
        
        Control of the device; Presets, Tune, Band & Feedback [x]
        
        Version 2: - Still locks up tuner
        ----------
        
        Ability to push and hold Preset # and change the station : Locks up tuner
        
        Version 3: - Still locks up tuner
        ----------
        
        Add . to FM Stations for display []
        Add Preset stored notification to panel when new preset is stored [x] : not using because it locks up the tuner
        
        Version 4: - Done
        ----------
        
        AM stations with only 3-digits aren't working so need from keypad parsing, need to enter 0, then station to getit
        to work properly [x]
        
        Version 5: - Still locks up tuner
        ----------
        
        Need to get Preset Storing working correctly
    	a.> Push & Hold Sets Current Station to Preset 
    	b.> Updates Panel Information 
    	c.> Add vText that tells you the station has been added 
        
        Version 6: - Done
        ----------
        
        Rewritting string parsing to see if i can make it more efficent ( ztuner locks up and physically needs
        to be unplugged for 3 mins to clear everything : Its an issue with the ztuner itself, thats why they release new
        version of the protocol and firmware )
        
        Version 7: - Not Done; controling on cp4 but not updating feedback
        ----------
        
        Add CP4 Panels, create a way to determine which panel is being used
        and only update that panel
        
        Version 8:
        ----------
        
        Turning into a module
        
    *)
    (***********************************************************)
    (*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_DEVICE
    
    dvZtuner	=	5001:1:0
    dvMVP		=	10024:1:0
    
    dvCP4_1a	=	128:1:1
    dvCP4_1b	=	129:1:1
    dvCP4_1c	=	130:1:1
    dvCP4_1d	=	131:1:1
    
    dvCP4_2a	=	132:1:1
    dvCP4_2b	=	133:1:1
    dvCP4_2c	=	134:1:1
    dvCP4_2d	=	135:1:1
    
    (***********************************************************)
    (*               CONSTANT DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_CONSTANT
    
    Volatile Integer nZtuner_Preset_Buttons[]=
    {
        209,	/// Preset 1
        210,	/// Preset 2
        211,	/// Preset 3
        212,	/// Preset 4
        213,	/// Preset 5
        214,	/// Preset 6
        215,	/// Preset 7
        216,	/// Preset 8
        217,	/// Preset 9
        9999,	/// Preset 10
        9999,	/// Preset 11
        9999,	/// Preset 12
        9999,	/// Preset 13
        9999,	/// Preset 14
        9999,	/// Preset 15
        9999,	/// Preset 16
        9999,	/// Preset 17
        9999,	/// Preset 18
        9999,	/// Preset 19
        9999,	/// Preset 20
        9999,	/// Preset 21
        9999,	/// Preset 22
        9999,	/// Preset 23
        9999,	/// Preset 24
        9999,	/// Preset 25
        9999,	/// Preset 26
        9999,	/// Preset 27
        9999,	/// Preset 28
        9999,	/// Preset 29
        9999	/// Preset 30
        
    }
    
    Volatile Integer nZtuner_Tune_Buttons[]=
    {
        206,	/// Auto Tune Up
        207,	/// Auto Tune Down
        9999,	/// Manual Step Up
        9999	/// Manual Step Down
    }
    
    Volatile Integer nZtuner_Band_Buttons[]=
    {
        9999,	/// FM
        9999,	/// AM
        208		/// Band Toggle
    }
    
    Volatile Integer nZtuner_VText_Fields[]=
    {
        1,		/// Power Status : Not used
        2,		/// Current Status
        3,		/// Current Preset #
        4,		/// Current Frequencey
        5,		/// Current Band
        6		/// Station Preset Info
    }
    
    Volatile Integer nZtuner_Preset_Control_Buttons[]=
    {
        9999,	/// Next Preset
        9999	/// Previous Preset
    }
    (***********************************************************)
    (*              DATA TYPE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_TYPE
    (***********************************************************)
    (*               VARIABLE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_VARIABLE
    
    Dev dvPanel[]= {dvCP4_1a,dvCP4_2a,dvMVP}
    (***********************************************************)
    (*               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>) *)
    (***********************************************************)
    (***********************************************************)
    (*                STARTUP CODE GOES BELOW                  *)
    (***********************************************************)
    DEFINE_START
    
    DEFINE_MODULE 'Z-Tuner Mod' modTuner1(dvCP4_1a, dvZtuner, nZtuner_Preset_Buttons ,nZtuner_Tune_Buttons,nZtuner_Band_Buttons,nZtuner_VText_Fields,nZtuner_Preset_Control_Buttons)
    DEFINE_MODULE 'Z-Tuner Mod' modTuner2(dvCP4_2a, dvZtuner, nZtuner_Preset_Buttons ,nZtuner_Tune_Buttons,nZtuner_Band_Buttons,nZtuner_VText_Fields,nZtuner_Preset_Control_Buttons)
    DEFINE_MODULE 'Z-Tuner Mod' modTuner3(dvMVP, dvZtuner, nZtuner_Preset_Buttons ,nZtuner_Tune_Buttons,nZtuner_Band_Buttons,nZtuner_VText_Fields,nZtuner_Preset_Control_Buttons)
    (***********************************************************)
    (*                THE EVENTS GO BELOW                      *)
    (***********************************************************)
    DEFINE_EVENT
    (***********************************************************)
    (*            THE ACTUAL PROGRAM GOES BELOW                *)
    (***********************************************************)
    DEFINE_PROGRAM
    (***********************************************************)
    (*                     END OF PROGRAM                      *)
    (*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
    (***********************************************************)
    

    Module
    MODULE_NAME='Z-Tuner Mod'	(Dev dvTP,
    				 Dev dvDevice,
    				 Integer nPreset_Buttons[],
    				 Integer nTune_Buttons[],
    				 Integer nBand_Buttons[],
    				 Integer nVText_Fields[],
    				 Integer nPreset_Control_Buttons[]
    				)
    (***********************************************************)
    (***********************************************************)
    (*  FILE_LAST_MODIFIED_ON: 04/04/2006  AT: 11:33:16        *)
    (***********************************************************)
    (* System Type : NetLinx                                   *)
    (***********************************************************)
    (* REV HISTORY:                                            *)
    (***********************************************************)
    (*
        $History: $
    *)    
    (***********************************************************)
    (*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_DEVICE
    
    //dvZtuner = 5001:1:1
    (***********************************************************)
    (*               CONSTANT DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_CONSTANT
    (***********************************************************)
    (*              DATA TYPE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_TYPE
    
    Structure _Radio_Information
    {
        Char sPower[1]
        Char sPreset[2]
        Char sFrequency[12]
        Char sStatus[1]
        Char sBand[1]
    }
    (***********************************************************)
    (*               VARIABLE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_VARIABLE
    
    Integer Debug_Status
    Integer nPanel
    Persistent _Radio_Information sRadio_Data
    (***********************************************************)
    (*               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_Function Char debug(Char sMsg[])
    {
        If(Debug_Status)
    	Send_String 0,"'Debug : ',sMsg"
    }
    
    Define_Function SysKP_Parsing(Char sQue[100])
    {
        
        Local_Var Char sWork[25]
        Local_Var Char sTrash[25]
        
        If(Debug_Status)
    	debug("':: Line : ',Itoa(__Line__),' SysKP_Parsing :: ','sQue : ',sQue")
        
        If(Length_String(sQue = 3))
    	sQue = "'0',sQue"
        
        sFormat(sQue)
        
        If(Debug_Status)
    	debug("':: Line : ',Itoa(__Line__),' SysKP_Parsing :: ','sQue : ',sQue")
        Send_String dvDevice,"sQue,13"
    }
    
    Define_Function sFormat(Char sQue[100])
    {
        Local_Var Char sWork[25]
        Local_Var Char sTrash[25]
        Local_Var Char sWork_Temp_1[25]
        Local_Var Char sWork_Temp_2[25]
        Local_Var Char sNum_1[4]
        Local_Var Char sNum_2[2]
        
        If(Debug_Status)				/// Debug information
    	debug("':: Line : ',Itoa(__Line__),' sFormat :: ','Formatting data.'")
        Select
        {
    	
    	Active(Find_String(sQue,'.',1)):
    	{
    	    If(Debug_Status)
    		debug("':: Line : ',Itoa(__Line__),' sFormat :: ','Found a . in the data.'")
    	    sWork_Temp_1 = Remove_String(sQue,'.',1)
    	    If(Debug_Status)
    		debug("':: Line : ',Itoa(__Line__),' sFormat :: ','sWork_Temp_1 : ',sWork_Temp_1")
    	    sNum_1 = Left_String(sWork_Temp_1,Length_String(sWork_Temp_1) -1)
    	    If(Debug_Status)
    		debug("':: Line : ',Itoa(__Line__),' sFormat :: ','sNum_1 : ',sNum_1")
    	    sNum_2 = sQue
    	    If(Debug_Status)
    		debug("':: Line : ',Itoa(__Line__),' sFormat :: ','sNum_2 : ',sNum_2")
    	    sQue = "'W 1 6 ',sNum_1,' ',sNum_2,'0'"    
    	}
    	Active(!(Find_String(sQue,'.',1))):
    	{
    	    If(Debug_Status)
    		debug("':: Line : ',Itoa(__Line__),' sFormat :: ','Not a . in the data.'")
    	    sNum_1 = Left_String(sQue,2)
    	    If(Debug_Status)
    		debug("':: Line : ',Itoa(__Line__),' sFormat :: ','sNum_1 : ',sNum_1")
    	    sNum_2 = Right_String(sQue,2)
    		If(Debug_Status)
    		    debug("':: Line : ',Itoa(__Line__),' sFormat :: ','sNum_2 : ',sNum_2")
    	    sQue = "'W 1 6 ',sNum_1,' ',sNum_2"
    		If(Debug_Status)
    		    debug("':: Line : ',Itoa(__Line__),' sFormat :: ','sQue : ',sQue")
    	}
        }
    }
    
    (* Read Commands 
    	
        'R 1 1',13		= Display Power Status : 0=Off; 1=On [X]
        'R 1 3 1',13	= Display Current Preset :  Preset Number 1 -30 [X]
        'R 1 6',13		= Display Current Frequency : Frequency Number [X]
        'R 1 9',13		= Display Current Stereo Status : 1=Stereo; 2=Mono [X]
        'R 1 8',13		= Display Current Band : 1=FM; 2=AM [X]
    
    *)
    
    Define_Function Update_Feedback_V2()
    {
        If(Debug_Status)
    	debug("':: Line : ',Itoa(__Line__),' Updating Feedback on panel'")
        (* Send Preset Info to Panel *)
        Send_Command dvTP,"'^TXT-',Itoa(nVText_Fields[3]),',0,','P',sRadio_Data.sPreset" ;
        (* Send Frequency Info to Panel *)
        Send_Command dvTP,"'^TXT-',Itoa(nVText_Fields[4]),',0,',sRadio_Data.sFrequency" ;
        (* Send Band Info to Panel*)
        Switch(sRadio_Data.sBand)
        {
    	Case '1':	{Send_Command dvTP,"'^TXT-',Itoa(nVText_Fields[5]),',0,','FM'"	Break}
    	Case '2':	{Send_Command dvTP,"'^TXT-',Itoa(nVText_Fields[5]),',0,','AM'"	Break}
        }
        Switch(sRadio_Data.sStatus)
        {
    	Case '1':	{Send_Command dvTP,"'^TXT-',Itoa(nVText_Fields[2]),',0,','STEREO'"	Break}
    	Case '2':	{Send_Command dvTP,"'^TXT-',Itoa(nVText_Fields[2]),',0,','MONO'"	Break}
        }
        Switch(sRadio_Data.sPower)
        {
    	Case '0':	{Send_Command dvTP,"'^TXT-',Itoa(nVText_Fields[1]),',0,','OFF'"	Break}
    	Case '1':	{Send_Command dvTP,"'^TXT-',Itoa(nVText_Fields[1]),',0,','ON'"	Break}
        }
    
    }
    
    Define_Function Char Poll ()
    {
        If(Debug_Status)
    	debug("':: Line : ',Itoa(__Line__),' Poll :: ','Checking power status'")
        Send_String dvDevice,"'R 1 1',13"
        Wait 5
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Poll :: ','Checking current preset'")
    	Send_String dvDevice,"'R 1 3 1',13"
        Wait 10
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Poll :: ','Checking current frequency'")
    	Send_String dvDevice,"'R 1 6',13"
        Wait 15
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Poll :: ','Checking current mode'")
    	Send_String dvDevice,"'R 1 9',13"
        Wait 20
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Poll :: ','Checking current band'")
    	Send_String dvDevice,"'R 1 8',13"
        Wait 25
    	Update_Feedback_V2()
    }
    
    (***********************************************************)
    (*                STARTUP CODE GOES BELOW                  *)
    (***********************************************************)
    DEFINE_START
    
    (***********************************************************)
    (*                THE EVENTS GO BELOW                      *)
    (***********************************************************)
    DEFINE_EVENT
    
    Data_Event[dvDevice]
    {
        Online:
        {
    	Send_Command dvDevice,"'SET BAUD 9600,N,8,1'"
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Device Online :: Setting Communication'")
        }
        String:
        {
    	Local_Var Char sWork1[25]
    	Local_Var Char sWork2[25]
    	Local_Var Char sWork3[25]
    	Local_Var Char sWork4[25]
    	
    	Local_Var Char sTrash1[25]
    	Local_Var Char sTrash2[25]
    	Local_Var Char sTrash3[25]
    	Local_Var Char sTrash4[25]
    	
    	Local_Var Char sTmp1[25]
    	Local_Var Char sTmp2[25]
    	Local_Var Char sTmp3[25]
    	Local_Var Char sTmp4[25]
    	
    	sWork1 = Remove_String(Data.Text,"13",1)
    	sRadio_Data.sPower = Left_String(sWork1,1)
    	
    	sWork2 = Remove_String(Data.Text,"13",2)
    	sRadio_Data.sPreset = Left_String(sWork2,1)
    	
    	sTrash1 = Remove_String(Data.Text,"13",2)
    	sTmp1 = Right_String(sTrash1,Length_String(sTrash1) - 1)
    	sTrash2 = Remove_String(Data.Text,"13",2)
    	sTmp2 = Right_String(sTrash2,Length_String(sTrash2) - 1)
    	sTmp3 = Left_String(sTmp1,Length_String(sTmp1) - 1)
    	sTmp4 = Left_String(sTmp2,Length_String(sTmp2) - 1)
    	
    	sWork3 = Remove_String(Data.Text,"13",3)
    	sRadio_Data.sStatus = Left_String(sWork3,Length_String(sWork3) - 1)
    	
    	sWork4 = Remove_String(Data.Text,"13",4)
    	sRadio_Data.sBand = Left_String(sWork4,Length_String(sWork4) - 1)
    	
    	Switch(sRadio_Data.sBand)
    	{
    	    Case '1': {sRadio_Data.sFrequency = "sTmp3,'.',sTmp4,' MHz'"	Break}
    	    Case '2': {sRadio_Data.sFrequency = "sTmp3,sTmp4,' kHz'"		Break}    
    	}
        }
    }
    
    Data_Event[dvTP]
    {
        Online:
        {
    	Wait 25
    	    Poll()
        }
        String:
        {
    	Local_Var Char sQue[1000]
    	Local_Var Char sTrash[100]
    	Local_Var Char sResponse[100]
    	
    	sQue = Data.Text
    	
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Data.Text : ',Data.Text")
    	    
    	Select
    	{
    	    Active(Find_String(sQue,'Radio-',1)):
    	    {
    		sTrash = Remove_String(sQue,'Radio-',1)
    		
    		If(Debug_Status)
    		    debug("':: Line : ',Itoa(__Line__),' Keypad Detection :: ','Set the keypad to Radio mode.'")
    		Wait 5
    		    Poll()
    	    }
    	    Active(Find_String(sQue,'KEYP-',1)):
    	    {
    		sTrash = Remove_String(sQue,'KEYP-',1)
    		sResponse = Remove_String(sQue,sQue,1)
    		If(Debug_Status)
    		    debug("':: Line : ',Itoa(__Line__),' Keypad Detection :: ','Send the keypad string to the function.',' sResponse : ',sResponse")
    		SysKP_Parsing(sResponse)
    	    }
    	    Active(Find_String(sQue,'KEYB-',1)):
    	    {
    		sTrash = Remove_String(sQue,'KEYB-',1)
    		sResponse = Remove_String(sQue,sQue,1)
    		If(Debug_Status)
    		    debug("':: Line : ',Itoa(__Line__),' Keypad Detection :: ','Send the keyboard string to the function.',' sResponse : ',sResponse")
    		SysKP_Parsing(sResponse)
    	    }
    	}
        }
    }
    
    
    Button_Event[dvTP,nPreset_Buttons]
    {
        Push:
        {
    	/// Do Nothing :)
        }
        Release:
        {
    	Local_Var Integer nButton
    	Local_Var Char sCmd[15]
    	
    	nButton = Get_Last(nPreset_Buttons)
    	
    	sCmd = "'W 1 3 1 ',ITOA(nButton)"
    	
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Radio Presets :: ','sCmd : ',sCmd")
    	
    	Send_String dvDevice,"sCmd,13"
    	
    	Wait 5
    	    Poll()
        }
        Hold[10]:
        {
    	Local_Var Integer nButton
    	Local_Var Char sCmd[15]
    	
    	nButton = Get_Last(nPreset_Buttons)
    	
    	sCmd = "'W 1 3 2 ',Itoa(nButton)"
    	
    	If(Debug_Status)
    	     debug("':: Line : ',Itoa(__Line__),' Memorizing Channel into preset :: ','sCmd : ',sCmd")
    	
    	Send_Command dvTP,"'@PPG-[Tuner] - Preset;Main Page'"
    	Send_Command dvTP,"'^TXT-',Itoa(nVText_Fields[6]),',0,','Station ',sRadio_Data.sFrequency,' stored into Preset # ',Itoa(nButton)"
    	
    	Send_String dvDevice,"sCmd,13"
    	
        }
    }
    
    Button_Event[dvTP,nTune_Buttons]
    {
        Push:
        {
    	Local_Var Integer nButton
    	Local_Var Char sCmd[15]
    	
    	nButton = Get_Last(nTune_Buttons)
    	
    	sCmd = "'W 1 7 ',ITOA(nButton)"
    	
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Radio Tune :: ','sCmd : ',sCmd")
    	
    	Send_String dvDevice,"sCmd,13"
        }
        Release:
        {
    	Wait 5
    	  Poll()
        }
    }
    
    Button_Event[dvTP,nBand_Buttons]
    {
        Push:
        {
    	Local_Var Integer nButton
    	Local_Var Char sCmd[15]
    	
    	nButton = Get_Last(nBand_Buttons)
    	
    	
    	If(nButton == 3)
    	    nButton = 10
    	
    	sCmd = "'W 1 8 ',Itoa(nButton)"
    	
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Radio Band :: ','sCmd : ',sCmd")
    	    
    	Send_String dvDevice,"sCmd,13"
        }
        Release:
        {
    	Wait 5
    	    Poll()
        }
    }
    
    Button_Event[dvTP,nPreset_Control_Buttons]
    {
        Push:
        {
    	Local_Var Integer nButton
    	Local_Var Char sCmd[15]
    	
    	nButton = Get_Last(nPreset_Control_Buttons) + 2
    	
    	sCmd = "'W 1 3 ',Itoa(nButton)"
    	
    	If(Debug_Status)
    	    debug("':: Line : ',Itoa(__Line__),' Radio Preset Control :: ','sCmd : ',sCmd")
    	    
    	Send_String dvDevice,"sCmd,13"
        }
        Release:
        {
    	Wait 5
    	    Poll()
        }
    }
    
    Button_Event[dvTP,1000]
    {
        Push:
        {
    	Debug_Status = Debug_Status + 1
    	If(Debug_Status > 1)	{Debug_Status = 0}
    	
    	Switch(Debug_Status)
    	{
    	    Case 0:	{Off[dvTP,1000]	Break}
    	    Case 1:	{On[dvTP,1000]	Break}
    	}
        }
    }
    (***********************************************************)
    (*            THE ACTUAL PROGRAM GOES BELOW                *)
    (***********************************************************)
    DEFINE_PROGRAM
    
    (***********************************************************)
    (*                     END OF PROGRAM                      *)
    (*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
    (***********************************************************)
    

    Thanks for the help...... again :)

    Chris Ondrovic
  • ondrovicondrovic Junior Member Posts: 217
    Never mind just figured it out :) hooray
Sign In or Register to comment.