Strings and Chars
Spire_Jeff
Posts: 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:
Here are all of the methods I tried.
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
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
0
Comments
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.
Paul
The fact that it compiles in define_constant is a bug. Surely nobody would code that expecting the result that actually occurs.
And don't call me Shirley...
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"