473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 5601
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.