none
Communicating with USB Devices with CE 6.0 RRS feed

  • Question

  • <p>&nbsp;Its one thing to plug in a USB mouse, keyboard, or scanner onto the LANpointPowerX USB port and received data from those devices because there is already a built in driver in the OS(somewhere) that can receive this data, but its a whole new ball game(in my mind) if you plugging in a USB device that you plan to send information to perform a function like printing a label.</p><p>&nbsp; Unless the OS can already deal with this, there would need to be some kind of USB driver that could identify the USB device, then allow one to send data to it. On a regular PC, when you plug in a USB device, the PC either can already recognize it because Windows already has a preloaded driver for it, or you pop in a CD with a driver to load for that device.</p><p>&nbsp; If using a USB based device which the terminal is going to be sending data out to it, I'm guessing that there needs to be a CE 6.0 compatible driver written by the manufacture that would then somehow be loaded into the CE 6.0 device. Seems doubtful that it would just work when plugged in. Do they even make a USB barcode label printers that will work when plugged into a CE 6.0 device?</p><p>&nbsp; I'd recommend that they get a barcode label printer that has a serial port, or maybe Bluetooth, in addition to a USB port. They are going to have to write code to send commands to the barcode label printer in any case. Sending data to any device be it USB, serial, Bluetooth, or Ethernet, its all a matter of being able to open a connection into that port and then be able to send and perhaps receive data back from the device. I am not confident that the LANpointPowerX has a preloaded driver that can send data to a USB based barcode label printer. To my understanding USB works kind-of like TCP/IP but they may need to write their own driver( or us write a driver) to access the barcode printer via USB.</p>
    Monday, September 10, 2012 11:32 PM

All replies

  • USB barcode scanners typically look like HID (keyboard) devices. If the oprating system has USB keyboard support, they just work (like a keyboard).

    Similar support exists for USB printer class devices. However, as you mentioned, it's not just recognizing the device but speaking its language that is the issue with printers. There is HP LaserJet 2 (I think) support in Windows CE. If your printer happens to speak the same language as that device, you'd just have to make the connection between your device ID and the printer driver (registry).

    It's also possible that a simple device like a barcode printer does not appear to the operating system as a printer, but as a serial port. If that's the case, you might send it a string that will be printed as a barcode, followed by a form-feed to complete the label (or something), communicating with it just like any other serial port device.

    USB works nothing like TCP/IP. TCP/IP does not need a special protocol driver for the language of the taget device.

    Paul T.

    Tuesday, September 11, 2012 3:24 PM
  • Thanks Paul:

    Currently I just concerned with trying to send commands to a USB based Zebra Printer. When I plug  the Zerba printer into the USB port the terminal popped up a dialog box and asked  for the name of a driver. Which obviosly tells me there is no USB driver installed.

    I then went into the VS2005 Platform builder Catalog Item and selected the USB Printer Class Driver. Once re-complied(Sysgen'd) and I plugged in the USB Zerba printer and the terminal did NOT pop up the dialog box asking for a driver so I'nm guessing that something got loaded in.

    I then looked in the Registry and saw that a USB Printer Class entry existed with a "LPT" prefix.

    So as a guess I wrote a prgoram tha opened up LPT1: and send out ZPL(Zebra commands) to make a label, and it worked!

    Thanks Paul.

    Here is the code:

    int Open_lpce_ser_wrt(int port)
    {
     TCHAR szmessage[255];
     TCHAR comstr[ 32 ];

     int serialportnum = port;
    // Open the port.
     _stprintf( comstr, _T( "LPT%d:" ), serialportnum );
     OpenSerialPorts[port-1] = CreateFile( comstr,
      GENERIC_WRITE, FILE_SHARE_READ,
            NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL |
            FILE_FLAG_SEQUENTIAL_SCAN, NULL);

     if ( OpenSerialPorts[port-1] == INVALID_HANDLE_VALUE )
     {
      DWORD errorCode = GetLastError();
      wsprintf(szmessage, _T( "ERROR...CreateFile Open of LPT%d:...Error=%d\n" ), serialportnum, errorCode );
      MessageBox(NULL,szmessage,TEXT("LPT PORT OPEN ERROR"), MB_OK);
      return(1);
     }
     return(0);
    }

    int Write_lpce_ser_wrt(int port, TCHAR * lpCmdLine)
    {
     char buffer[ 4096 ];
     DWORD count, xcount;
     int serialportnum = port;

     if ( OpenSerialPorts[port-1] != INVALID_HANDLE_VALUE )
     {
      count = wcslen(lpCmdLine);
      WideCharToMultiByte( CP_ACP, 0, lpCmdLine, -1, &buffer[ 0 ], sizeof( buffer ),
       NULL, NULL );
      WriteFile( OpenSerialPorts[port-1], buffer, count, &xcount, NULL );
      return(1);
     }
     return(0);
    }

    int Close_lpce_ser_wrt(int port)
    {
     int serialportnum = port;
     // Close connection.
     if ( OpenSerialPorts[port-1] != INVALID_HANDLE_VALUE )
     {
      CloseHandle( OpenSerialPorts[port-1]);
      OpenSerialPorts[port-1] = INVALID_HANDLE_VALUE;
     }
     return(0);
    }

    Monday, September 17, 2012 10:52 PM
  • Serial port, parallel port, what's the difference? ;-)

    Glad you got it working!

    Paul T.

    Wednesday, September 19, 2012 6:24 PM