php - Reading Serial Port in Perl -


i'm bit tired of reading serial port, using perl first of perl not primary development tool, i'm php background. please guide me in right way. intention read data weight machine web page, did lot of research on topic.

the browser app cannot read serial port data directly choose user end machine can installed server (apache) , task php , web application can read result using ajax call localhost url idea working great on linux machines on windows pc stuck.

i understand php can't read data serial port in windows linux choose perl stuff. did search got few codes , last 8 hours i'm fighting :(

#!e:\xampp\perl\bin\perl.exe # above line perl execution path in xampp # below line tells browser, script send html content. # if miss line show "malformed header script" error.    print "content-type: text/plain\n\n";   # use strict; use warnings;   use win32;   require 5.003;   use win32::serialport qw( :stat 0.19 );   print "here";   $portobj = new win32::serialport ("com3") || die "can't open com3: $^e\n";   print "here";   $portobj->user_msg(on);   $portobj->databits(8);   $portobj->baudrate(9600);   $portobj->parity("none");   $portobj->stopbits(1);   $portobj->handshake("rts");   $portobj->buffers(4096, 4096);    $portobj->error_msg(1);  # prints major messages "framing error"   $portobj->user_msg(1);      $portobj->write_settings || undef $portobj;     print "here";   # $portobj->save($configuration_file_name);   $portobj->read_interval(100);    # max time between read char (milliseconds)   $portobj->read_char_time(5);     # avg time between read char   $portobj->read_const_time(100);     print "here";    $string_in = $portobj->read("200");     print $string_in   # $portobj->baudrate(300);   # $portobj->restart($configuration_file_name);  # 9600 baud    $portobj->close || die "failed close";   undef $portobj;   

the code not working on forum , many other places says working here , here, this , this.

im unable find means "use win32::serialport qw( :stat 0.19 );" importing library version number. ?

i'm installed xampp perl , activeperl win32::serialport 0.22 , api when run code return error like

error message: end of script output before headers: serial.pl  

500 error

any idea ??

solved

for reading section use code below.

# warn "here";   ($ser) = @_;   ($numchars, $c);   $line = '';   {     {       ($numchars, $c) = $portobj->read(1);       #print "$numchars read=$c\n";     } while ($numchars < 1);     # print $c;     $line .= $c;   } while ($c ne "\n");    print $line; 

the code works fine cli put php file read perl script , return data.

use win32::serialport qw( :stat 0.19 ); 

this same as

use win32::serialport ':stat', '0.19'; 

the :stat imports number of useful status constants, , explained under exports in documentation module

the 0.19 part of perl, , insisting version of win32::serialport must 0.19 or later. current version 0.22. if change 0.19 0.23 see effect has


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -