SONY 232
Anyone has a sample of how to use the 232 KDL protocol?
I'm not familiar with the checksum method
trying to control power on/off
input switching
Aspect modes
Help is greatly appreciate it
thanks
I'm not familiar with the checksum method
trying to control power on/off
input switching
Aspect modes
Help is greatly appreciate it
thanks
0
Comments
DEFINE_DEVICE dvTelevision = 5001:1:0 dvTP = 10001:1:0 DEFINE_CONSTANT INTEGER nTPButtons[] = { 81, //Video 1 82, //Video 2 83, //Video 3 84, //Component 1 85, //Component 2 86, //HDMI 1 87, //HDMI 2 88, //HDMI 3 89, //HDMI 4 90 // PC } DEFINE_EVENT DATA_EVENT[dvTelevision] { ONLINE: { SEND_COMMAND dvTelevision,'SET BAUD 9600,N,8,1' } } BUTTON_EVENT[dvTP,nTPButtons] { PUSH: { STACK_VAR INTEGER nButtonPressed nButtonPressed=GET_LAST(nTPButtons) SWITCH (nButtonPressed) { CASE 1: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$02,$01,$03" //(*$8C = STX, $00 = Category (always $00 for this device), $02 = command for "Input Select", $03 = Length of Data to follow including checksum (3 bytes in this case), $02 = "Video", $01 = "#1 input", $03 = $02+$01) CASE 2: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$02,$02,$04" CASE 3: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$02,$03,$05" CASE 4: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$03,$01,$04" CASE 5: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$03,$02,$05" CASE 6: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$04,$01,$05" CASE 7: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$04,$02,$06" CASE 8: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$04,$03,$07" CASE 9: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$04,$04,$08" CASE 10: SEND_STRING dvTelevision, "$8c,$00,$02,$03,$05,$01,$06" } } }I'm confident that this would work. If someone else has a functioning code block hopefully they'll post it for you but this should get you started in the meantime.
--John
Here's the code I'm using, you can just drop this in an include file (the Structure for the Sony vars is not defined here) and reference the channel event for on/off:
DEFINE_VARIABLE CHAR sSonyXBR5_Header[] = {$8C,$00} CHAR sSonyXBR5_Function[] = {$00,$01,$02} CHAR sSonyXBR5_Length CHAR sSonyXBR5_Cmd[] = {$00,$01,$02,$03,$04,$05} CHAR sSonyXBR5_Checksum INTEGER nHeaderPos CHAR sSonyXBR5_NewCmd[20] PERSISTENT _Display stSonyXBR5 DEFINE_FUNCTION fnSonyXBR5MsgBuild(INTEGER nArgFunc, INTEGER nArgState, INTEGER nArgSub) {// Funcs 1=power,2=enable,3=inputs,4=channel,5=volume,6=muting STACK_VAR CHAR sMyLength STACK_VAR CHAR sMyData1 STACK_VAR CHAR sMyData2 STACK_VAR CHAR sMyMsg[20] STACK_VAR CHAR sMyCheckSum SWITCH(nArgFunc) { CASE 1: // power { sMyLength = $02 sMyData1 = sSonyXBR5_Cmd[nArgState+1] } CASE 2: // enable { sMyLength = $02 sMyData1 = sSonyXBR5_Cmd[nArgState+1] } CASE 3: // input { IF(nArgState<=2) // length is two { sMyLength = $02 sMyData1 = sSonyXBR5_Cmd[nArgState+1] } ELSE { sMyLength = $03 sMyData1 = sSonyXBR5_Cmd[nArgState+1] sMyData2 = sSonyXBR5_Cmd[nArgSub] } // add rest of funcs! } } // Build string sMyMsg = "sSonyXBR5_Header,sSonyXBR5_Function[nArgFunc],sMyLength,sMyData1" sMyChecksum = fnSonyXBR5CheckSum(sMyMsg) stSonyXBR5.TxBuf = "stSonyXBR5.TxBuf,sMyMsg,sMyChecksum" } DEFINE_FUNCTION CHAR fnSonyXBR5CheckSum(CHAR sArgCmd[]) { STACK_VAR CHAR sCheckSum STACK_VAR INTEGER nLength STACK_VAR INTEGER nCount nLength = LENGTH_STRING(sArgCmd) FOR(nCount=1;nCount<=nLength;nCount++) { sCheckSum = sCheckSum+sArgCmd[nCount] } RETURN sCheckSum; } DEFINE_FUNCTION INTEGER fnSonyXBR5AckParse(CHAR sArgAck) { STACK_VAR INTEGER nMyReturn SWITCH(sArgAck) { CASE $00: { nMyReturn=1 } CASE $01: // data too high { nMyReturn=0 } CASE $02: // data too low { nMyReturn=0 } CASE $03: // command canceled { nMyReturn=0 } CASE $04: // error { nMyReturn=0 } } RETURN nMyReturn; } DEFINE_EVENT DATA_EVENT[dvXBR5] { ONLINE: { SEND_COMMAND DATA.DEVICE,'SET BAUD 9600, N, 8, 1, 485 DISABLE' SEND_COMMAND DATA.DEVICE,'RXON' SEND_COMMAND DATA.DEVICE,'HSOFF' SEND_COMMAND DATA.DEVICE,'XOFF' } STRING: { WHILE(LENGTH_STRING(stSonyXBR5.RxBuf)) { IF(GET_BUFFER_CHAR(stSonyXBR5.RxBuf)=$70) { IF(fnSonyXBR5AckParse(GET_BUFFER_CHAR(stSonyXBR5.RxBuf))) { // command acknowledged ON[stSonyXBR5.CTS] GET_BUFFER_CHAR(stSonyXBR5.RxBuf) // remove the checksum } ELSE { // something went wrong } } ELSE { // not the beginning of the response string } } } } CHANNEL_EVENT[dvXBR5,255] // power cmd and fb { ON:{fnSonyXBR5MsgBuild(1,1,0)} OFF:{fnSonyXBR5MsgBuild(1,0,0)} } DEFINE_PROGRAM IF(LENGTH_STRING(stSonyXBR5.TxBuf) && stSonyXBR5.CTS) // stuff in the buffer and clear to send { OFF[stSonyXBR5.CTS] // cancel related waits CANCEL_WAIT 'Cancel SonyXBR5 CTS' nHeaderPos = FIND_STRING(stSonyXBR5.TxBuf,$8C,2)-1 SEND_STRING dvXBR5,REMOVE_STRING(stSonyXBR5.TxBuf,LEFT_STRING(stSonyXBR5.TxBuf,nHeaderPos),1) } ELSE IF(!LENGTH_STRING(stSonyXBR5.TxBuf) && stSonyXBR5.CTS) // nothing in buffer and clear to send { // poll? } ELSE IF(!stSonyXBR5.CTS) // not clear to send { WAIT 25 'Cancel SonyXBR5 CTS' { ON[stSonyXBR5.CTS] } }Sony_Command[2]= "$8C,$00,$00,$02,$00,$8E" //POF
Sony_Command[3]= "$8C,$00,$01,$02,$01,$90" //Standby ON
Sony_Command[4]= "$8C,$00,$01,$02,$00,$8F" //Standby OFF
Sony_Command[5]= "$8C,$00,$02,$03,$05,$01,$97" //RB1
Sony_Command[7]= "$8C,$00,$02,$03,$02,$01,$94" //VID1
Sony_Command[8]= "$8C,$00,$02,$03,$02,$02,$95" //VID2
Sony_Command[9]= "$8C,$00,$02,$03,$02,$03,$96" //VID3
You need to send standby on before turning off the KDL or you will not be able to turn it back on.
$FF + $FF = $01,$FE $FE is the least significant byte.
define_function integer calcchecksum(char cMsg[]) { stack_var integer nLoop stack_var integer nCheckSum off[nCheckSum] for (nLoop=1;nLoop<=length_string(cMsg);nLoop++) { nCheckSum=((nCheckSum+cMsg[nLoop])& $FF) } return nCheckSum }J
I post this reply so that others do not waste as much time on this as I have.