N3rdB0mber
N3rdB0mber

Reputation: 169

USB communications - Windows CE host terminal to usb device (printer)

I am developing some code to run from a Windows CE5 terminal that will send data to a usb device (a printer in this case). I am having issues obtaining the value of the port used to open communications. I have tried to use the device path written in the registry by the driver (USBport + GUID) and many other variations to no prevail. I understand that communicating to the device should just "open a file" to communicate w/ the device at a given memory address. I understand there are modern usb libraries, but those will be of no use on such an old OS (i assume). My overall goal is to write the code is VC++ and use JNI to wrap the code for use in a Java application (SE6). Can anybody give an example on what a sample "device path" might be? Or if there is anything else I am missing feel free to shed light. I have noticed most of the modern USB libraries have a search function, but if I have the device path I don't believe the search function would be necessary....

Currently I am trying to get the code to work on any OS, and have been using Windows 7 just to get things working. Below are some code snippets:

const LPCTSTR portvalue = L"441ee000-4342-11d5-a184-00c04f60524d"; // defines the portname, ie, location of device to read/write

int usbHandle = OpenUsb(portvalue); //opens the file/device for communication

/********Here is the OpenUsb function *************/ __declspec(dllexport) int _cdecl OpenUsb(const LPCTSTR portName) {

HANDLE activeUsbFileHandle = CreateFile(portName,                   //portname built in registry? need to get a WinCE5 vm going..? i belive so
                                 GENERIC_READ|GENERIC_WRITE,
                                 FILE_SHARE_READ|FILE_SHARE_WRITE, // comm devices must be opened w/exclusive-access
                                 NULL,                             // no security attributes
                                 OPEN_EXISTING,                    // comm devices must use OPEN_EXISTING
                                 FILE_ATTRIBUTE_NORMAL,            
                                 NULL);


cout << "Portname Mem Location: " << &portName;
cout << "\nThe portname passed in as: " << portName << endl;

commTimeouts.ReadIntervalTimeout = 0;
commTimeouts.ReadTotalTimeoutConstant = 500;
commTimeouts.ReadTotalTimeoutMultiplier = 0;
commTimeouts.WriteTotalTimeoutConstant = 5000;
commTimeouts.WriteTotalTimeoutMultiplier = 0;
SetCommTimeouts(activeUsbFileHandle, &commTimeouts);

return (int)activeUsbFileHandle;

}

Upvotes: 1

Views: 816

Answers (1)

strange-corner
strange-corner

Reputation: 476

portName = "\\LPT1:"; /* i use this for printing */             

Upvotes: 1

Related Questions