472,989 Members | 2,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Using Serial Port in Linux. Weird problem with receiving data.

A baffling end to my week! I open my serial port on my Debian PC (Debian version 5.0.1) I have a decent Null Modem lead going to another PC (I'll call it PC#2), with its port open with the same parameters. I send a series of bytes from the Debian PC which comes through, no problem.

I reply from PC#2, but the read buffer of the Debian PC's port shows nothing. What's more, the message gets sent directly back to the PC#2, with certain bytes getting changed. (I'm guessing its just invalid ascii codes that get changed, e.g. 0x02 always gets changed to 0x5e 0x42, which is ^B. Displayable bytes don't get changed.)

I've tried changing the Flow control method but that hasn't helped.

I'm using php_serial.class.php, from http://www.phpclasses.org/browse/package/3679.html. It is a highly rated class and I'm guessing its not to blame.
My code is a very slight modification of the example that comes with the class (modifying just so it keeps reading any messages for a number of seconds):

Expand|Select|Wrap|Line Numbers
  1. include "php_serial.class.php";
  2. $serial = new phpSerial;
  3.  
  4. $serial->deviceSet("COM1");
  5.  
  6. // We can change the baud rate
  7. $serial->confBaudRate(9600);
  8. $serial->confCharacterLength(8);
  9. $serial->confStopBits(1);
  10. $serial->confParity("none");
  11.  
  12. //$serial->confFlowControl ("none");
  13. // Then we need to open it
  14. $serial->deviceOpen();
  15.  
  16. $serial->sendMessage(chr(0xff).chr(0x02).chr(0x4B)); // Sends with no problem
  17.  
  18. do{
  19.     // Or to read from
  20.     $read = $serial->readPort();
  21.     echo $read;
  22.     $pause1 += 0.01;
  23. } while (empty($read) && $pause1 < 99999);
  24. // Read never becomes non-empty whatever I send back from other PC within this time
  25.  
  26. $serial->deviceClose();
  27.  
If anyone has a strong hunch about why I'm getting this problem, or any thing helpful to say, thank you very much.
Oct 9 '09 #1
1 5564
I ought to have included this from the actual class that I downloaded. I now think that this is where the problem is:

Expand|Select|Wrap|Line Numbers
  1.         function deviceOpen ($mode = "r+b")
  2.     {
  3.         $this->_dHandle = fopen($this->_device, $mode);
  4.  
  5.         if ($this->_dHandle !== false)
  6.         {
  7.             stream_set_blocking($this->_dHandle, 0);
  8.             $this->_dState = SERIAL_DEVICE_OPENED;
  9.             return true;
  10.         }
  11.  
  12.         $this->_dHandle = null;
  13.         trigger_error("Unable to open the device", E_USER_WARNING);
  14.         return false;
  15.     }
  16.  
I'm pretty sure now that the problem is use of the function stream_set_blocking(). According to user comments on the manual, this function is ignored by php5.2. So it seems the serial port cannot be unblocked - hence data coming in not getting read and getting sent straight back down the line.

Is my only solution to use php4? Anyone know a workaround for the stream_set_blocking() bug?
Oct 15 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jan | last post by:
Hello, is there someone who know's how to read and write data to a serial port using visualbasic 8 thanx in advance
0
by: pandi | last post by:
Hi, I am using a check scanner.It has functions which gives output like image ,checknumber. i am using serial port to get this output in my coding. My problem is i am not able to read the display...
1
by: Jan | last post by:
Hello, I want to send some simple strings to com1 using vb2005. I want to read it in Hyperterminal. I succeeded to send some data en read it in Hyperterminal, only the data I received is not...
2
by: Quentin | last post by:
I would like to create a serial port listener that starts recording data to a text file as soon as the port starts receiving the data. How do I trigger the program to start running when data is...
8
by: dadalos | last post by:
Hello; I'm having a problem with receiving data from serial port. There's an eventhandler(datareceived) and I'm monitoring the answer from the serial port to a text box in the eventhandler. There's...
9
by: Hal Vaughan | last post by:
I've done a fair amount of Googling for information on reading the serial port in C++ (and in Linux). Unfortunately, out of every 4 hits, 1 seems to be an unanswered question, 1 is someone saying,...
0
by: ghjk | last post by:
I want to read sms from GSM modem using C# in serial communication. I wrote the code. But i want to do it automatically. I put my code here and please tell me how can i do it automatically. ...
4
by: Xavier | last post by:
Hi, I try to access to a Bluetooth GPS data-logger with Python. I use pySerial. Sending and receiving little messages (~100 char) works fine. However, when I ask the GPS to dump the trails,...
4
by: mayaanu | last post by:
I have developed a GUI based application in C# for communicating with a 16 bit littleendian microcontroller device .the device has a serial port interface. 1.my appplication opens a COM port on...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.