I've recently created a custom menu (browser page) in ROBOGUIDE for validating our DCS zones. It uses an ajax call to determine the active CPC zones. Then it changes the visibility to visible of the buttons that correspond with the zones that are active. In ROBOGUIDE this works perfectly. However, when I loaded it into one of our robots the buttons will not show up, and based on the karel variables the function that gets the button data did not ever execute. This makes me think somehow the ajax is failing to call anything. Using a backdate I made an exact copy of that real robot in ROBOGUIDE, and the karel program worked perfectly, displaying the buttons. Can anyone tell me if there is a difference between the karel execution in ROBOGUIDE and in the real robot? Does anyone else have experience using ajax calls in a physical robot? Did you have to do anything special to set it up?
Controller: R-30iB, V9.4
Javascript:
<script language=javascript src="/frh/cgtp/ajax.js"></script>
<script language=javascript>
var xmlhttp = null;
//request button data from the controller
function buttonSetup(){
ajax_send_url_sync("/KAREL/DCSVAL?operation=getButtons&_seq=" + new Date().getTime(),ButtonEvent);
}
//execute based on button data return
function ButtonEvent(){
if (xmlhttp.readyState == 4) { // if readyState == complete
// Execute JavaScript returned from GETBUTTONS
ajax_execute();
}
}
//execute based on button data return
function ColorEvent(){
if (xmlhttp.readyState == 4) { // if readyState == complete
// Execute JavaScript returned from colorButtons
ajax_execute();
}
}
Karel:
--handle the ajax call for getting the button data
ROUTINE getButtons
begin
IF UNINIT(respfile) THEN
respfile = 'TD:RESPONSE.HTM'
ENDIF
OPEN FILE file1 ('RW', respfile)
FOR zoneNumber = 1 TO maxzones DO
--Create a string to access the zones enable property
CNV_INT_STR(zoneNumber, 1, 0, zoneNumberString);
zoneNumberString = SUB_STR(zoneNumberString, 2, 2);
stringAddress = '$DCSS_CPC[' + zoneNumberString + '].$ENABLE'
-- Check if zone is enabled
GET_VAR(entry, '*SYSTEM*', stringAddress, onOrOff, STATUS);
if( onOrOff = 1) then
enables[zoneNumber] = '1';
else
enables[zoneNumber] = '0';
endif
-- Write JavaScript which will be executed as a response, if the zone is enabled the button will be made visible
WRITE file1('document.getElementById("DCSZone' + zoneNumberString + '").value =')
WRITE file1(enables[zoneNumber])
WRITE file1(';', CR)
ENDFOR
CLOSE FILE file1
end getButtons