RFID BLUETOOTH PHP

2

I'm trying to connect an RFID reader to Windows via Bluetooth.

I can identify what COM is, but when I try to call via PHP using fopen, for example, the error "failed to open stream: Permission denied".

I tried to use the PHPSERIAL function, but also the error: "Warning: Specified serial port is not valid in C: \ xampp \ htdocs \ serial \ PhpSerial.php on line 120".

I tried to run the command "MODE COM7: 9600, n, 8.1" via the terminal and the msg "The COM7 device is not available at this time."

In all cases, the reader even beeps, but it generates the error.

Has anyone worked with anything like this?

Follow the tested codes.

<?php
    include 'PhpSerial.php';
    $serial = new PhpSerial;
    $serial->deviceSet("COM7");
    $serial->confBaudRate(2400);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->confFlowControl("none");
    $serial->deviceOpen();
?>

<?php
    $port = fopen("COM7", "r+b");
    echo fgets($port);
    fclose($port);
?>
    
asked by anonymous 09.03.2018 / 20:37

2 answers

3
Dealing with very specific hardware from high level languages is usually a challenge, especially if it is in Web applications. Some considerations about your problem and a suggested solution:

The fact of the beep reader means that the reading was done on the reader itself, but does not mean that the read value was sent to a destination through some interface. If the player is wireless, it may not even be paired with the computer, but read if it is powered up.

If you have already detected that the player is paired with the computer, you should only access the corresponding port and obey the communication protocol. From what I understand, you have already won this step and found that the reader is mapped to COM7.

Your question does not make it clear what kind of application you are building, whether it is a PHP script running on the command line or whether that code will run on a Web page. If the code runs on a Web page, remember it will look for the reader on the COM port of the server where the PHP script runs , not on the Windows client, unless the Web server runs on the Windows client.

Anyway, the PhpSerial class only works in read / write mode on Linux. On Windows it is not able to read what comes from the door, just write on the port. Also, this class is experimental and buggy, so I would not trust it to run an actual application in production.

I suggest you use another language to connect to the serial port and receive the reading result. Put the code that reads into a service that will run on the machine where the reader is paired. This service can be done using some language native to Windows (C #, VB etc.), C, C ++, Java or on top of Node.js, for example.

When the reader beeps, the service receives the result and stores it in a buffer, providing an HTTP interface for querying. The size of the buffer and the data structure (FIFO, LIFO etc.) will depend on your business requirement, ie how often the application needs to receive the read value. Your application then looks up the value via HTTP GET on localhost. If it is a Web application, just do it via request AJAX when the cursor is positioned in the field, remembering to configure the Header http Access-Control-Allow-Origin with the source server of the page, so that CORS (Cross-Origin Request Sharing) works.

Once read by the HTTP interface, the value is removed from buffer .

It's not a trivial solution, but I've already developed something that has worked perfectly with hundreds of customers a few years ago. The negative side of this solution is having to develop and maintain one more service, besides needing to monitor that service, to identify if it has crashed.

    
14.03.2018 / 21:41
0

Check the permissions of the page server (on the machine where you run PHP), because this permission error you are seeing must be coming from there ...

Other things:

1) I do not know what foot it is currently, but it seems to me that PHP only accepts up to the COM5 port. More than that can give error;

2) Change your second parameter from fopen from "r+b" to w+ to test. It will be fopen("COMx", "w+"); where COMx must be equal to or less than COM5 .

    
14.03.2018 / 23:04