RFID BLUETOOTH PHP

Asked

Viewed 412 times

2

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

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

I tried using 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 execute via terminal the command "MODE COM7:9600,n,8,1", and gives a msg "The device COM7 is not available at this time."

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

Has anyone ever worked with anything like?

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);
?>
  • fopenis to open a file, in your case, for reading. Where is the file?

  • I saw some people giving example of opening connection with serial port using "FOPEN", providing only the "COM" as in the example above, ended up testing the code. I have no experience with serial port, bluetooth, so anything is valid to get the desired result rs

  • 1

    I don’t know if php would be the right language for what you want, but you’ve tried running xampp in administrator mode ?

  • What would be the proper language? I ran as ADM, but it remains the same thing.

  • 1

    I believe python is best to mess with it.... but I’ve never touched it.

  • https://github.com/karulis/pybluez

  • I found a demo software that provides the source code VS, but I do not have the slightest dispatch with it. It can communicate with the reader and does not generate any errors. I found other softwares too, and in common, all use the "Rfidreaderlibrary.dll".

  • When you turn on your Bluetooth device, it will be available to be "viewed" by your computer. At this time you should pair this device (don’t forget to enable Bluetooth before your computer). Only then can you open a connection to the device, in whatever language. Done pairing, then you should check which port COM the device is enabled. There yes you indicate in your code the right port. Tip: Before encoding, try opening the connection with a type program PuTTy or similar.

  • @wBB, all the procedures you quoted I was already doing, the only test I didn’t do was with the Putty, but I understand that if it didn’t work with the CMD which is "weightless", it probably won’t work on the Putty either.

  • @I used Putty to open COM and it worked.

  • I even managed to send the commands to start reading the tags, abort, and it worked well for Putty.

  • This means that the problem is neither on your device, nor on the COM port of your PC, nor on the communication itself. From where you conclude that you’re in the programming part. I don’t have a test for you, but another suggestion would be to use a different language to know if it works or, if you want to insist on PHP, try other methods. If you’re going to use C language, there are a lot of examples about serial communication ready on the NET and you could quickly test.

  • There are demos in C, C#, that work the communication, perform the reading, etc, my problem is q would be to use in an existing PHP system, so I’m seeing the possibilities.

  • 1

    Even if it is a PHP system it would be possible to use python, since python is native linux and PHP could call it via shell

  • If your device generates logs in some TXT in windows, it would be nice to consider reading the Log instead of connecting on the device with PHP. If you can generate this log, you could even do something asynchronous with a server and have the data in real time in the cloud.

Show 10 more comments

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 that the reader beeps means that the reading was done in the reader itself, but it does not mean that the read value was sent to a destination through some interface. If the reader is wireless, it may not even be paired to the computer, but charge the reading if it is energized.

If you have already detected that the reader is paired to the computer, just access the corresponding port and obey the communication protocol. From what I understand, you have already won this step and discovered that the reader is mapped on the door COM7.

Your question does not make it clear what kind of application you are building, whether it is a PHP script running in a command line or whether this code will run on a web page. If the code runs on a web page, remember that it will search for the reader on the COM port of the server running the PHP script, 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. In Windows she is not able to read what comes from the door, just write on the door. Also, this class is experimental and full of bugs, so I wouldn’t trust it to run a real application in production.

I suggest you use another language to connect to the serial port and receive the reading result. Place the code that reads on a service that will run on the machine where the reader is paired. This service can be done using some native language of 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 query. The size of the buffer and the data structure (FIFO, LIFO etc.) will depend on your business requirement, that is, how often the application needs to receive the value read. Your application then searches the value via HTTP GET in localhost. If it is a web application, just do it via request AJAX when the cursor is positioned in the field, remembering to configure in your service the Header HTTP Access-Control-Allow-Origin with the page source server, so that the CORS (Cross-Origin Request Sharing) work.

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

It’s not a trivial solution, but I’ve already developed something similar that runs perfectly on hundreds of customers a few years ago. The downside of this solution is to have to develop and maintain an extra service, in addition to need to monitor this service, to identify if stuck.

  • My system is hosted on the Web, on a dedicated LINUX server. The idea would be for the web system (PHP) to call the paired reader "locally", read and return the content to the web. Obvious q is not so easy, permissions, security, etc. Neodynamic has something like what I need, but aimed at printing, the Webclientprint Processor software with PHP support, where you install on the client computer, the web script makes the call and sends the print.

  • I was able to take some examples on the web and I was able to develop a console where I identify and list the paired bluetooth devices, start the connection with the reader, start receiving tags, finish and save directly in the database. It would be possible to call this . exe at a given time?

  • Sorry, it’s a "Windows App", . NET 4.5. It is q n I have practice or knowledge regarding console, applications, etc. Example of case: the company’s HR access the web system, register a new employee and attach the RFID badge. To link, the ideal would be to call the connection with the reader at that time, read the tag, and return to the browser to proceed with the registration. With what you said of HTTP/AJAX, would the scenario be possible? Would you have some terms to research and read to have better understanding or some example? I’m kind of lost rs.

0

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

Other things:

1) I don’t know where you are now, but it seems to me that PHP only accepts up to the port COM5. More than that can make a mistake;

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

    1. I tested all the fopen possibilities.
  • see if this helps: https://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html

  • remembering that the device with which you will establish communication has to be connected to the same PC/server where PHP is installed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.