Asked  7 Months ago    Answers:  5   Viewed   50 times

I am looking for a way to communicate with RS232 serial COM port on windows. I have found 2 solutions on the net, one which is not totally free (introduces deliberate delays on the function) and another with limited capability on Windows. The latter can only write to a COM port on Windows, not read.

I can't look at the code of the first solution since it is compiled into a .dll (makes sense, otherwise people can just edit the delay and not purchase it...) and the second one seems only to use fopen() to open the port and later fwrite() to it for writing, just like one would do to a stream. But apparently freading it returns nothing.

I know it's possible as the first solution did it, although it does require Apache to use php-cgi module instead of php5module.

Any ideas?

 Answers

30

Every solution above is either inefficient or too much work.

You can just use the PHP-DIO library (dio_fcntl, dio_open, dio_read, dio_write, dio_seek, ...). It's also in the PHP manual's entry for DIO:

This PECL package isn't available by default. To get it for Windows if you have PHP 5.2.x greater than 5.2.6, you can download it as part of a ZIP:

  • Thread-safe (for Apache)

  • Non-thread-safe (for IIS)

Both of these links were found in http://www.deveblog.com/index.php/download-pecl-extensions-for-windows/

Here is the build from Linux, just get it and do the phpize/configure/make/make install thing.

I don't know whether it should be used in an Apache session, but go for it.

Wednesday, March 31, 2021
 
lena
answered 7 Months ago
46

Found it! Apologizing for misapprehension, but all this situation is really confusing for guy who such a little about servers management. Anyway, below is my solution.

http://code.google.com/p/pecl-win/downloads/detail?name=php_redis-2.1.3-5.3-ts.dll&can=2&q=

Link above provides .dll file, which in my case must be copied to: C:xamppphpext and add a line in to php.ini file extension=php_redis.dll and lastly restart apache2 service.

And that's it, nothing has to be installed, as long as redis server already up and running this will provide connection between php and redis!

2020-05-06 update

Seems like previous url only contains outdated .dll files. @Niz provided in the comments an updated url where you can download the correct version of redis DLL for your windows. Make sure to download the one that matches your redis and php versions.

https://pecl.php.net/package/redis

Wednesday, March 31, 2021
 
Yarin
answered 7 Months ago
51

Yes, IIS supports integrated Windows authentication. Access the 'Authentication' option for your website...

IIS1

...and change the 'Windows Authentication' item to 'enabled' (and perhaps 'Anonymous Authentication' to 'disabled' if you want to force users to authenticate)...

IIS2

More details are available on Technet.

In PHP the username should be populated in the $_SERVER superglobal. I think as AUTH_USER, but I can't confirm that right now. Use var_dump($_SERVER); to find the correct key.

Wednesday, March 31, 2021
 
Fredy
answered 7 Months ago
80

the php_serial.class.php is kind of broken, i had to adapt it to get a reading out of it, so instead of using the following from the reader method: $content = ""; $i = 0;

                    if ($count !== 0)
                    {
                            do {
                                    if ($i > $count) $content .= fread($this->_dHandle, ($count - $i));
                                    else $content .= fread($this->_dHandle, 128);
                            } while (($i += 128) === strlen($content));
                    }
                    else
                    {
                            do {
                                    $content .= fread($this->_dHandle, 128);
                            } while (($i += 128) === strlen($content));
                    }

i used just this

     //trigger_error("reading 0 ".$i, E_USER_WARNING);
     $content .= fread($this->_dHandle, $count);


     return str_split($content);

then reconstruct the byte string in php

Saturday, May 29, 2021
 
relyt
answered 5 Months ago
62

If the linked example fails it means that RXTX hasn't detected any serial ports on your machine. You may have a serial port on your machine but one of the reasons it isn't recognized by your OS might be because it is actually a serial-to-USB adapter, and is being recognized as an USB port.

If you are on Linux, serial ports usually look like this:

ls /dev/ttyS*

outputs:

/dev/ttyS0
/dev/ttyS1
/dev/ttyS2

the adapted port might look like this:

/dev/ttyUSB0

If you can see some output on your serial attached device (e.g. POS printer or LCD display) you can test it like this:

echo 'hello' > /dev/ttyUSB0

and the device should show the 'hello' string if it is attached to that port and everything is working properly.

However, I would definitely recommend Java simple serial connector library over RxTx. We have tried both in an commercial POS application (>1M tickets at this time).

RxTx is being used for sequential printing successfully. In the print scenario the RxTx library was called upon sequentially and used only to send the data to the port. Only some serial flags were red the detect to buissiness of the device.

But because of its limitations we simply could not use it for reading input from a serially connected IButton. In the iButton scenario the data is expected to be received asynchronously from the port. There were constant bugs and hangs when we tried to implement it with RxTx, but with JSSC it was implemented almost immediatley.

Sunday, August 15, 2021
 
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :