/    Sign up×
Community /Pin to ProfileBookmark

XMLHttpRequest to send data trough serial port

Ok, now I really need some help… this forum never fails to me ?

[CODE]comando=”P”+Kp+”I”+Ki+”D”+Kd+”R”+Ref+”F”;
com_server=”serial2.php?var1=”+comando;
var request = window.ActiveXObject ? new ActiveXObject(“Microsoft.XMLHTTP”) : new XMLHttpRequest();
request.open(“GET”,com_server,true);
request.send(null);[/CODE]

that is my javascript to get the php page which is the following:

[code=php]`mode com3: BAUD=19200 PARITY=N data=8 stop=1 xon=off`;
$fp = fopen (“COM3:”,”a”);
if($string = $_GET[‘var1’]){
$long=strlen($string);
fwrite($fp,$string,$long);
}
fclose ($fp);[/code]

The data is sent through the serial port only some times, others it doesn’t work, and I have tested the serial port and it opens and closes without any problem…

It usually works randomly… the only pattern I was able to catch is:

if the variable comando doesn’t change, data is NEVER sent through the serial port…

and for the record, if I do the following thing instead of using httprequest it NEVER fails, but I am forced to open a popup window, which is not very nice for the user

[CODE]options=”toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=1,height=1,top=1,left=1″;
window.open(‘serial2.php?var1=’+comando,””,options);[/CODE]

any ideas of where the problem could be?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@yamobeauthorAug 08.2006 — I still have this problem ?

so a new question to solve it myself, when I do:

request.open("GET",page.php,true);

how is it possible to debug page.php?
Copy linkTweet thisAlerts:
@yamobeauthorAug 15.2006 — I will finish my monologue by telling my solution.. I finally solved this, it was a header issue.. in my php file this solved my problem:

header("Cache-Control: no-store, no-cache, must-revalidate");

header("Pragma: no-cache");
×

Success!

Help @yamobe spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...