PHP Classes

Can't read output from the serial

Recommend this page to a friend!

      PHP Serial  >  All threads  >  Can't read output from the serial  >  (Un) Subscribe thread alerts  
Subject:Can't read output from the serial
Summary:Serial Class
Messages:4
Author:Mohd Sirhan Shahrani Bin Mt. Salleh
Date:2007-09-19 07:10:56
Update:2009-01-03 10:22:53
 

  1. Can't read output from the serial   Reply   Report abuse  
Picture of Mohd Sirhan Shahrani Bin Mt. Salleh Mohd Sirhan Shahrani Bin Mt. Salleh - 2007-09-19 07:10:56
Hi Remy,

I managed to sent data to credit card terminal using your serial class.
However I still couldn't retrieve data that was sent by the credit card terminal to the system.
The class will replied nothing. Hopefully u can give me some guide to solve this problem.

This is my code :

include "php_serial.php";
include "customer_display.php";

$serial = new php_serial;
$serial->deviceSet("/dev/ttyS0");
$serial->deviceOpen();

$stx = chr(0x02);
$_data = "022C000000000100000019";
$chk_digit = $terminal_data->get_check_digit($_data);
$etx = chr(0x03);

$hx1 = hexdec('0x'.substr($chk_digit,0,2));
$hx2 = hexdec('0x'.substr($chk_digit,2,2));
$hx3 = hexdec('0x'.substr($chk_digit,4,2));
$hx4 = hexdec('0x'.substr($chk_digit,6,2));
$hx5 = hexdec('0x'.substr($chk_digit,8,2));
$hx6 = hexdec('0x'.substr($chk_digit,10,2));
$hx7 = hexdec('0x'.substr($chk_digit,12,2));
$hx8 = hexdec('0x'.substr($chk_digit,14,2));

$serial->sendMessage($stx . $_data . chr($hx1) . chr($hx2) . chr($hx3) . chr($hx4) . chr($hx5) . chr($hx6) . chr($hx7) . chr($hx8) . $etx);

// Or to read from
$end_time = time() + 60; //60 seconds

while(time() <= $end_time){

$read = $serial->readPort();
//echo $read;
//print_r($read);

if($read != ''){
break;
}

}

$serial->deviceClose();

  2. Re: Can't read output from the serial   Reply   Report abuse  
Picture of Matt Switlik Matt Switlik - 2008-04-01 01:00:49 - In reply to message 1 from Mohd Sirhan Shahrani Bin Mt. Salleh
I'm having a similar problem with my IO board.
I can send but not receive data.
the board accepts commands like "l01" or "l00" which turns LED Zero On or Off respectively. to read the first analog input the command is "a0" and the board spits back a hex value of the input. I have a resistor with a value of "03FF" on the input now. I know this because I can use minicom in linux to send the "a0" command and minicom receives "03FF".

I had to force the _exec function to always return(0) because of unreliable process termination codes due to a known issue in php http://us2.php.net/manual/en/function.proc-close.php

here's the code:

<?php
include "php_serial.class.php";

$serial = new phpSerial;

// these are the same settings as in the terminal I used to test the io board
$serial->deviceSet("COM1");
$serial->confBaudRate(19200); //Baud rate: 19200
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length
$serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1")
$serial->confFlowControl("none");


$serial->deviceOpen("r+b");

//Clear board IO
$sMessage = "c";
$serial->sendMessage($sMessage);

//blink LED 0 3 times
for($i=0; $i<3; $i++)
{
$sMessage = "l11";
$serial->sendMessage($sMessage,1);
$sMessage = "l10";
$serial->sendMessage($sMessage,1);
}

//try to read analog input zero.
$sMessage = "a0";
$serial->sendMessage($sMessage);
echo "Sent: '$sMessage'<br>trying to read...";

//try reading the port a bunch
for($i=0; $i<=1000; $i++)
{
$read = $serial->readPort();
echo $read;
}

echo " done.";
$serial->deviceClose();
?>

it blinks LED 0 3 times and then outputs

Sent: 'a0'
trying to read... done.

It should output "03FF"

  3. Re: Can't read output from the serial   Reply   Report abuse  
Picture of Matt Switlik Matt Switlik - 2008-04-06 21:24:22 - In reply to message 1 from Mohd Sirhan Shahrani Bin Mt. Salleh
Try adding the "raw" option to the confFlowControl() function in the php_serial.class.php file
example: I changed line 380 to read:
"none" => "clocal -crtscts -ixon -ixoff raw",

This worked for my ORPP Serial IO controller board.
The board doesn't output a return character after the hex value of an input.

  4. Re: Can't read output from the serial   Reply   Report abuse  
Picture of MOURIER MOURIER - 2009-01-03 10:22:53 - In reply to message 1 from Mohd Sirhan Shahrani Bin Mt. Salleh
Hi Mohd
First happy new year and best wishes to you and your family (in India?).
I try to use php_serial_class with linux and I am unable to make the soft running. All the example I found seems running but when I check with stty they don't change the speed or anything else. I try with several linux: mandrake, mandriva, centos4.7, centos5.2 thats quite the same. Is there something to do before writing or reading the port? Is it necessary that something is connected to the port for testing? Is it necessary to make 777 chmod to the port or something else? I ask you because Remy email does not answer.
Michel MOURIER
mourierm@wanadoo.fr