3/20/2021 0 Comments Php Serial Port Windows
Im trying to talk to a fiscal printer trough a custom protocol based on ACKNACK technique (send data - receive answer - respond to answer -.).
Php Serial Port Windows Serial Port ScannerWith a serial port scanner (and from the ticket that are correctly printed) I can see that the sent data are well received from fiscal printer.But any replay to sent data (which are present if data are sent to serial port from other kind of softwareprogramming languages) are present.![]() Are you sure your device really returns anything did you try other serial port applications. Php Serial Port Windows Code Cant ReadAnyway. Yes, Im sure that with my code cant read anything back on the serial port. Ive already tried with other applications and the serial port has always worked good as I expected. As Ive already wrote in my firs post I can correclty send the same commands to the serial port using other programming languages (and also with a specific built-up application under WIN XP) and I get back the right reply from the port (ASCII chr(6) in this case) using always the same hardwar during my tests. Ive a dual-boot PC (WIN XP and Ubuntu linux 9.04) so the hardware (PC, serial port, fiscal printer) are exactly the same for both operating system. Im developing a cross-platform application (WINLinux) so I MUST find a way to make the serial port to be read correctly on both o.s. I dont have much experience with diopecl functions.but I wouldnt like to use them, Id prefer to have the standard PHP functions (fgetsfread) working correctly (Why can I write correctly with fputs but cant read with fgetsfread ). Ive also tried to insert a sleep between the fputs and fread operations just to verify any eventually time-related issue.but it still doesnt work. Anyway, I found a difference during fread instruction between WIN and Ubuntu that I havent seen before (doesnt matter if binary mode is activated or not). On WIN XP fread (and fgets too) hangs (never ending loop), while on UBUNTU buffer is always empty (cant read reply from serial port) but the script doesnt loop on fread and goes (for the rest of my code) correctly to the end. It seems like streamsetblocking(fp,0) doesnt work at all on WIN. I can send commands using fputs but the script hangs while trying to read from the resource using fgets, fread or streamgetcontents. I think the problem, at least in my case, is that the response doesnt have an end or something and the fact that the reading limit doesnt work in this case. The strange thing in my case is that back in 2007 i wrote an sms gateway using a GPRS modem and it used to work with fgets. I managed to make it work using the phpdio extension on windows php 5.2.9. Sleeping the script between fputs and fgets seems to do the job of resolving this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |