/* comxs by Peer-Axel Kroeske 18-Nov-2012 peeraxel@aol.com radiovibrations.com/php/com-port-access.htm This tool helps to access serial ports in PHP where ports from COM10 and above cause problems. For binary safe in and output. Structure: comxs.exe comport, bytestoread, command in hex values Example: comxs.exe COM11 11 fe fe 00 03 fd will write the sequence (fe fe 00 e0 03 fd) to COM11 and then listen until 17 (0x11) bytes are received. There is no timeout. It won't terminate until all bytes are received. Use 0 for write-only. It returns a string with written hex values like "fe fe 00 03 ... fd" */ #include #include #include #include using namespace std; //htoi by John Santic http://johnsantic.com/comp/htoi.html unsigned int htoi (const char *ptr) { unsigned int value = 0; char ch = *ptr; while (ch == ' ' || ch == '\t') ch = *(++ptr); for (;;) { if (ch >= '0' && ch <= '9') value = (value << 4) + (ch - '0'); else if (ch >= 'A' && ch <= 'F') value = (value << 4) + (ch - 'A' + 10); else if (ch >= 'a' && ch <= 'f') value = (value << 4) + (ch - 'a' + 10); else return value; ch = *(++ptr);}} int main(int argc, char *argv[]) { char *sp; char path[]="\\\\.\\"; strcat(path,argv[1]); int x,y,z; if (argc<1) {cout<<"parameter missing";return FALSE;} HANDLE hCom; COMMTIMEOUTS timeouts = {1000}; DWORD size, BytesRead, BytesWritten; hCom = CreateFile(path,GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,0,0); if(hCom == INVALID_HANDLE_VALUE) {hCom = NULL; cout<<"invalid port";return FALSE;} for (x=3;x0) { unsigned char* data[y]; ReadFile(hCom,data,y,&BytesRead,0); for (x=0;x<=y;x++) { z=((int(data[x>>2]))>>((x%4)<<3))&0xff; if (z<16) {cout<<'0';} cout<