473,804 Members | 3,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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.clas s.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 5650
lutherchp
2 New Member
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_bloc king(). 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_bloc king() bug?
Oct 15 '09 #2

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

Similar topics

1
7021
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
9820
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 image ( which i scanned using scanner ). I used serail port as well as MSCOMM control.but i couldn't get the output. Can anybody knows this and help me to sort out my problem -- it is very urgent here i am using windows 2000 professional OS and i...
1
2481
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 the data I send. This is the code i used: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
2
4743
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 sent to that port. Any help with the code would be great! Thank you!!
8
16580
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 no problem till here. But also I want to use the incoming data to process it in some functions. But when I assign the incoming string(from the ReadExisting() function) to a local variable there are always lots of characters missing. How do I solve...
9
14403
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, "That's easy, there's a lot out there, Google it,", 1 is a discussion on it without examples and the other is who knows what. I did find some info on it and have been experimenting. The one example that I liked the best in terms of...
0
4569
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. public partial class SMS : Form { //create an Serial Port object SerialPort sp = new SerialPort(); public SMS() {
4
2754
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, it returns some Mbytes and here is the problem : in the stream of bytes, I randomly losts chunks of ~100bytes.
4
13412
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 which the device is connected with proper settings for the device. 2.It writes a command to the port. 3.datareceived event of the serial port reads the data in to a byte array. 3.i have closed the serialport using close() method The problem that i...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.