/    Sign up×
Community /Pin to ProfileBookmark

insert data from com port into textbox php

I read where this is an easy task but to a newbe, it isn’t that easy. I have a scale attached to computer with RS232. I need a php script to read the weight into a text box.

I found the following:

include “php_serial.class.php”;
$serial = new phpSerial;
$serial->deviceSet(“COM1”);
$serial->confBaudRate(2400);
$serial->confParity(“none”);
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl(“none”);
$serial->deviceOpen();
$read = $serial->readPort();
$serial->deviceClose();
$serial->confBaudRate(2400);
// etc…

But how do I echo the data?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 12.2013 — From your code, it looks like [FONT=Courier New]$read[/FONT] should contain the data from the port.

Try a var_export() of it to see what data it contains and how it's structured, e.g.:
[code=php]
echo "<pre>".var_export($read, true)."</pre>";
[/code]
Copy linkTweet thisAlerts:
@wpdfranauthorJun 12.2013 — Tried that...again, didn't work. I know my computer can read the com port 1.
Copy linkTweet thisAlerts:
@wpdfranauthorJun 12.2013 — So I tried this:

[code=php]

error_reporting(E_ALL);

$fp = fopen('COM1', 'r+');

if(!fp){
echo "Port not accessible";
} else {
echo "Port COM1 opened.";
}

$output = "mode COM1: BAUD=1200 PARITY=Even data=7 stop=1 Xon=off ";

$buffer = fgets($fp);

echo "Read: $buffer";

[/code]


Port is open but no $buffer and no errors.
Copy linkTweet thisAlerts:
@NogDogJun 12.2013 — Do you need to fput() your output first? (I'm by no means a COM port expert -- haven't touched that stuff in a bunch of years. ? )
Copy linkTweet thisAlerts:
@wpdfranauthorJun 12.2013 — Not sure what you mean?
Copy linkTweet thisAlerts:
@NogDogJun 12.2013 — You assign a string to the variable $output, but you don't actually do anything with it. I thought maybe you meant to output that string to the COM port, in which case I [i]believe[/i] that could be done via fputs() or fwrite() (fputs is just an alias of fwrite).

Or I could be completely wrong. ?
×

Success!

Help @wpdfran 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.29,
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,
)...