2

I am trying to connect weighting machine with PHP.

I have tested with hyperterminal it is working fine.

But when I use PHP code with fopen or dio_open it is executed but when fgets or dio_read is called, it hangs and does not display anything.

Fopen Example

exec('mode com2: BAUD=2400 PARITY=N data=8 stop=1 xon=on');

$fp = fopen("COM2:", "r");
if (!$fp) {
  echo "Uh-oh. Port not opened.";
} else {
  echo fgets($fp);
  fclose($fp);
}

DIO Example

exec('mode COM2: baud=2400 data=8 stop=1 parity=n xon=off to=on');
$fd = dio_open('COM2:', O_RDONLY | O_NONBLOCK, 0644);
echo dio_read($fd, 256); 

I'm unable with my tries of both ways to gather any useful output.

Do I require inpout32.dll file to connect?

And what is role of php_iol.dll, this file I also required?

hakre
  • 193,403
  • 52
  • 435
  • 836
LREARTH
  • 41
  • 1
  • 1
  • 4
  • Without any more concrete description of the error (if any), the exact expected output and the exact received output, a control group of all return values *per each* function call you have in your examples and hex-dumps of strings, this is hard to say. – hakre May 11 '14 at 06:45
  • And for doubts about `php_iol.dll` and it's dependency DLLs, please see the vendor documentation. It's not clear what your doubts are and more importantly why you have doubts, in what in concrete, what did happen that you got those "doubts" etc. Also things like *"I tried all options"* is not saying anything specific. So if you want an unspecific answer, go on that way, however if not, make your question more concrete. Especially as you're operating in a very specific domain here. – hakre May 11 '14 at 06:47
  • I also do not see that you use any code related to [`php_iol.dll`](http://codes-sources.commentcamarche.net/source/36224-extension-input-output-library-acess-direct-port-parallel-et-serie) in your question. With that and/or with DIO you might have luck if properly used, with `fopen` you're out of luck reading COM ports on windows. I've also added an answer saying that. – hakre May 11 '14 at 07:18
  • **You should not use `PHP` in combination with fuuu Windows!** It's a miracle, that PHP still works for Windows ... – mate64 May 11 '14 at 07:31
  • Thank you for reply.. Actually few days back when I tried to connect weighing machine with system and use the same code to read COM port, I was successfully able to read the port. But unfortunately I format my system after that and then now I tried the same code but not able to read COM port. I am using PHP 5.3.2 and I think because of inpout32.dll file I am not able to read the port. But I am not sure where I am doing mistake. – LREARTH May 11 '14 at 18:16

1 Answers1

2

PHP can not read from serial ports under Windows. This is not the case on a Linux system, on which there is no problem to reading from COM ports with the common PHP filesystem functions.

Those filesystem functions are also the preferred ways to do in regard of the DIO extension:

The use of the DIO functions should be considered only when direct control of a device is needed. In all other cases, the standard filesystem functions are more than adequate.

As you report your DIO example as "non-working", you need to keep track of errors. See:

Next to that you need to find a working POSIX example first, as DIO is not hyperterminal but POSIX style.

Alternatively some software exists to proxy a COM port through network (for example GPL'ed serproxy). This might solve you integration problem with your operating system, however I'm pretty sure you're out of luck.

Compare with:

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • 1
    Thank you for your reply... Actually few days back when I tried to connect weighing machine with system and use the same code to read COM port, I was successfully able to read the port. But unfortunately I format my system after that and then now I tried the same code but not able to read COM port. I am using PHP 5.3.2 and I think because of inpout32.dll file I am not able to read the port. But I tired many versions of inpout32.dll. I have downloaded different versions from net... But I am not able to read... Could you please help me... we really require this inpout32.dll file. – LREARTH May 11 '14 at 18:14
  • 1
    Reading does not work on windows regardless what you try. The library that makes use of inpout.dll might work, however it's quite old. You would need a binary compatible version. I don't think you get this easily to run nowadays on windows. – hakre May 11 '14 at 18:20