Hi,
Hoping for some help with a script conversion. I have searched and, as usual, Search Engines are giving me what they think I want rather than what I actually need!! Most answers direct me to PHP pages, and those I have found relating to Javascript, I find very confusing!
I have an old PHP script that simply resets a controller by writing direct to a memory location within the PAC Controller. I am trying to develop a Javascript equivalent which would be triggered if a watchdog fails to get a response. It is the conversion of the PHP Script that is the problem for me. I can muddle through the rest!
Here is the PHP script - basically writing <5> to Memory Location <F038 0000> using PHP function 'fsockopen'
<?php
#Write Quadlet routine for Opto 22 PAC R1
function writeQuad ($loc, $val) {
$comm = "0000 00 00 0000 FFFF ".$loc." ".$val;
$ipsock = pfsockopen ("172.27.123.50",2001,$errno,$errstr,3);
if (!$ipsock)
echo "$errstr ($errno)<br />\n";
{ stream_set_timeout($ipsock,3);
echo $comm;
$comm1 = str_replace(" ","",$comm);
$comm3 = pack("H*", $comm1 ) ;
fwrite($ipsock,$comm3);
$reply = fread($ipsock,20);
$info = stream_get_meta_data($ipsock);
fclose($ipsock);
if ($info['timed_out'])
echo 'connection timed out!';
else {
$tcode = substr(bin2hex($reply),6,1);
$rcode = substr(bin2hex($reply),12,1);
$Int = substr(bin2hex($reply),24,8);
}
}
}
writeQuad("F038 0000", "00000005"); //Reset Command
?>
Any help/pointers gratefully received
TIA,
Colin