Data I have not read the PHP source code, but it has file operation function, I think it should be OK? Not really, then do a CGI to achieve also can, and independence is good, easy to maintain. In the past I have done in the BCB environment, the idea is as follows: (in fact, the equivalent of ordinary file reading and writing operations, hehe)
First, open the file
Open a serial port first by file (either of the COM1~~COM4)
HANDLE M_hcomm = CreateFile ("COM2", Generic_read | Generic_write, NULL, open_existing, file_flag_overlapped, 0);
Then you can use WriteFile () and ReadFile () to read and write to the serial port, and finally remember CloseHandle (M_HCOMM), the current open serial port off Oh.
Since the CreateFile () function takes a file_flag_overlapped constant, note that the last parameter of the WriteFile () and ReadFile () function is a overlapped structure that needs to be initialized before reading and writing:
Comstat comstat;//The structure contains the state of the communication device.
BOOL bresult = true;
DWORD dwerror = 0;
DWORD bytesread = 0;
unsigned char m_readbuff;
Start looping Read
for (;;)
{
Bresult = Clearcommerror (M_hcomm, &dwerror, &comstat);//update COMSTAT structure and clear all errors
if (comstat.cbinque = 0)
{
break;//Exit For Loop if you finish reading
}
Bresult = ReadFile (M_hcomm, &readbuff, 1, &bytesread, M_ov);//read one at a time, if you like, you can read n bits at a time
......
Put your processing module here, anyway Readbuff is content (1 bits), can be merged ...
......
}
Four, turn off
CloseHandle (M_hcomm);
The above ideas can be returned through the function of error handling, as for the meaning of the error constants can be read books, complete treatment is a problem, know the method can be, as long as you are a simple application, then simply read and write is enough. This file read and write method also applies to print mouth LPT1, LPT2~~~LPTN. I haven't tried it under Unix, but since the Unix-class operating system has more emphasis on device files than Windows, I believe it's simpler and more versatile to read and write COM ports in UNIX and Linux. Still this: Know the method on the line. When it's time to sell. ^_^
However, if you use the UNIX, Linux as a CGI, you may want to set the permissions of the compiled CGI file, try Oh.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.