Home NetLinx Studio

Strings and Chars

Spire_JeffSpire_Jeff Formerly Caffeinated ProgrammerPosts: 1,917
Ok, so I was working on a new module for a JVC projector. The protocol document was a little less than clear about what was required to be sent, but I had a pretty good idea I knew what they meant. I coded everything up using constants because that was the mood I was in. Then the interesting things started happening. I know that the compiler is a little picky about how it handles chars and strings, but right now I don't have the time to figure out what it wants.
This is the statement I was using:
	SEND_STRING dvPROJ,"HEAD_OPERATION,UNIT_ID,CMD_POWER,POWER_ON,END_CMD";


Here are all of the methods I tried.
//Method 1
DEFINE_CONSTANT

CHAR 	HEAD_OPERATING[] = "$23";
CHAR 	HEAD_REFERENCE[] = "$40";

CHAR	UNIT_ID[]	=	"$89,$01";

CHAR	CMD_CHECK_CONN[]	=	"$00,$00";
CHAR	CMD_POWER[]	=	"$50,$57";
CHAR	CMD_INPUT[]	=	"$49,$50";
CHAR	CMD_REMOTE[]	=	"$52,$43";

CHAR	POWER_ON[]	=	"$31";
CHAR	POWER_OFF[]	=	"$30";

CHAR	INPUT_S_VIDEO[]	=	"$30";
CHAR	INPUT_VIDEO[]	=	"$31";
CHAR	INPUT_COMP[]	=	"$32";
CHAR	INPUT_HDMI1[]	=	"$36";
CHAR	INPUT_HDMI2[]	=	"$37";

CHAR 	REMOTE_ASPECT[]	=	"$37,$33,$37,$37";

CHAR 	END_CMD[]	=	"$0A";



//Method 2
DEFINE_CONSTANT

CHAR 	HEAD_OPERATING = $23;
CHAR 	HEAD_REFERENCE = $40;

CHAR	UNIT_ID[]	=	"$89,$01";

CHAR	CMD_CHECK_CONN[]	=	"$00,$00";
CHAR	CMD_POWER[]	=	"$50,$57";
CHAR	CMD_INPUT[]	=	"$49,$50";
CHAR	CMD_REMOTE[]	=	"$52,$43";

CHAR	POWER_ON	=	$31;
CHAR	POWER_OFF	=	$30;

CHAR	INPUT_S_VIDEO	=	$30;
CHAR	INPUT_VIDEO	=	$31;
CHAR	INPUT_COMP	=	$32;
CHAR	INPUT_HDMI1	=	$36;
CHAR	INPUT_HDMI2	=	$37;

CHAR 	REMOTE_ASPECT[]	=	"$37,$33,$37,$37";

CHAR 	END_CMD	=	$0A;




//Method 3
DEFINE_CONSTANT

CHAR 	HEAD_OPERATING = 33;
CHAR 	HEAD_REFERENCE = 63;
CHAR	HEAD_RESPONSE	=	64;

CHAR	UNIT_ID[]	=	"137,01";

CHAR	CMD_CHECK_CONN[]	=	"0,0";
CHAR	CMD_POWER[]	=	"80,87";
CHAR	CMD_INPUT[]	=	"73,80";
CHAR	CMD_REMOTE[]	=	"82,67";

CHAR	POWER_ON	=	49;
CHAR	POWER_OFF	=	48;

CHAR	INPUT_S_VIDEO	=	48;
CHAR	INPUT_VIDEO	=	49;
CHAR	INPUT_COMP	=	50;
CHAR	INPUT_HDMI1	=	54;
CHAR	INPUT_HDMI2	=	55;

CHAR 	REMOTE_ASPECT[]	=	"55,51,55,55";

CHAR 	END_CMD	=	10;


And I might have even tried one other method of declaring the constants. This was inside a module, and when I was watching the diagnostics, I saw the commands going to the device. It was a couple hours ago, but as I recall, the string being sent had commas between the .... ahh crap I think I just remembered what had to be done.....

Since I just typed all of this, I'll leave it as reference, plus someone can verify my revelation. I believe that I need to declare the char arrays like: CHAR CMD_POWER[] = {$87,$80}

Regardless, it all worked when I just used: SEND_STRING dvPROJ,"33,137,01,80,87,49,10";


Jeff

Comments

  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    Spire_Jeff wrote:
    Since I just typed all of this, I'll leave it as reference, plus someone can verify my revelation. I believe that I need to declare the char arrays like: CHAR CMD_POWER[] = {$87,$80}
    Correct and it's verified in Tech Note 531.
  • a_riot42a_riot42 AMX Wizard Posts: 1,619
    Joe Hebert wrote:
    Correct and it's verified in Tech Note 531.


    I have been using something like this. It seems to work, but I wonder if its non-standard?

    char strCmds[cnPowerOff] = "$02,$33,$30,$30,$35,$41,$31,$00,$30,$00,$03"
  • HedbergHedberg Junior Member Posts: 671
    a_riot42 wrote:
    I have been using something like this. It seems to work, but I wonder if its non-standard?

    char strCmds[cnPowerOff] = "$02,$33,$30,$30,$35,$41,$31,$00,$30,$00,$03"

    Double quotes denote a string expression and not a string constant. Expressions should not be allowed in define_constant and the compiler should throw an error. It does in define_variable. If you use the debugger to look at the value of strCmds that results from the above assignment, you'll see that it's probably not what was intended.
  • a_riot42a_riot42 AMX Wizard Posts: 1,619
    That line is in define_start actually and seems to work fine. How should it be initialized if that is not correct?
    Paul
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    a_riot42 wrote:
    I have been using something like this. It seems to work, but I wonder if its non-standard?

    char strCmds[cnPowerOff] = "$02,$33,$30,$30,$35,$41,$31,$00,$30,$00,$03"
    a_riot42 wrote:
    That line is in define_start actually and seems to work fine. How should it be initialized if that is not correct?
    That line won?t compile in DEFINE_START or even DEFINE_VARIABLE for that matter. The only place it will compile is in DEFINE_CONSTANT in which case you are initializing a 43 byte char array that includes dollar signs and commas. If your intention is an 11 byte array then you need to use braces instead of double quotes as Tech Note 531 describes.
  • HedbergHedberg Junior Member Posts: 671
    Joe Hebert wrote:
    That line won?t compile in DEFINE_START or even DEFINE_VARIABLE for that matter. The only place it will compile is in DEFINE_CONSTANT in which case you are initializing a 43 byte char array that includes dollar signs and commas. If your intention is an 11 byte array then you need to use braces instead of double quotes as Tech Note 531 describes.

    The fact that it compiles in define_constant is a bug. Surely nobody would code that expecting the result that actually occurs.
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    Hedberg wrote:
    The fact that it compiles in define_constant is a bug. Surely nobody would code that expecting the result that actually occurs.
    The fact that it compiles in DEFINE_CONSTANT is the cause for this thread to begin with and possibly the reason for the Tech Note. For some reason the compiler seems to be interpreting the double quotes as single quotes and is treating the initialization as a string literal. I agree no one would code that expecting the results that occurs and hence the reason for this thread.

    And don't call me Shirley... :)
  • a_riot42a_riot42 AMX Wizard Posts: 1,619
    Sorry it was a typo. The char keyword should not have been there. I only included it to show the type.
    This compiles fine and does what it should. Is there a problem doing it this way?

    define_variable
    volatile char strCmds[iNumCmds][30]

    define_start
    strCmds[cnPowerOff] = "$02,$33,$30,$30,$35,$41,$31,$00,$30,$00,$03"
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    a_riot42 wrote:
    Sorry it was a typo. The char keyword should not have been there. I only included it to show the type.
    This compiles fine and does what it should. Is there a problem doing it this way?

    define_variable
    volatile char strCmds[iNumCmds][30]

    define_start
    strCmds[cnPowerOff] = "$02,$33,$30,$30,$35,$41,$31,$00,$30,$00,$03"
    No problem at all. Initializing as part of the declaration under DEFINE_CONSTANT (or DEFINE_VARIABLE) is a different animal than the direct assignment you are using in DEFINE_START.
Sign In or Register to comment.