Hi everyone,
I am using a LM3S5951 controllers for one of my projects in which I need to implement a host side driver for Dot Matrix printer .
I am done with enumeration of the printer, but now I would like to know how can I send data to printers using bulk transfers. I am using the Stellaries USB Library for the same where I found some host side codes for keyboard and pendrive. I would like to know, how to go about this.
Regards
Dhanush
B) StellarisWare implementation This implementation is based on StellarisWare 10630 First, host class instance and DriveOpen()/DriveClose() are easily made, modifying mass storage source code (copy/paste-global replace).
// printer host class instance // and USBHPRNDriveOpen() / USBHPRNDriveClose() typedef void (*tUSBHPRNCallback)(unsigned long ulInstance, unsigned long ulEvent, void *pvEventData); typedef struct { // // Save the device instance. // tUSBHostDevice *pDevice; // // Used to save the callback. // tUSBHPRNCallback pfnCallback; // // class specific members // // // Bulk IN pipe. // unsigned long ulBulkInPipe; // // Bulk OUT pipe. // unsigned long ulBulkOutPipe; } tUSBHPRNInstance; static tUSBPRNInstance g_USBHPRNDevice = { 0 }; unsigned long USBHPRNDriveOpen(unsigned long ulDrive, tUSBHPRNCallback pfnCallback) { // // Only the first drive is supported and only one callback is supported. // if((ulDrive != 0) || (g_USBHPRNDevice.pfnCallback)) { return(0); } // // Save the callback. // g_USBHPRNDevice.pfnCallback = pfnCallback; // // Return the requested device instance. // return((unsigned long)&g_USBHPRNDevice); } void USBHPRNDriveClose(unsigned long ulInstance) { tUSBHPRNInstance *pPRNDevice; // // Get a pointer to the device instance data from the handle. // pPRNDevice = (tUSBHPRNInstance *)ulInstance; // // Close the drive (if it is already open) // USBHPRNClose((void *)pPRNDevice); // // Clear the callback indicating that the device is now closed. // pPRNDevice->pfnCallback = 0; }
And then, host driver instance
#define PRN_EVENT_OPEN 1 #define PRN_EVENT_CLOSE 2 static void *USBHPRNOpen(tUSBHostDevice *pDevice); static void USBHPRNClose(void *pvInstance); const tUSBHostClassDriver g_USBHostPRNClassDriver = { USB_CLASS_PRINTER, USBHPRNOpen, USBHPRNClose, 0 };
Copy these routines from usbhmsc.c, and replace all "MSC" with "PRN" USBHPRNOpen() <- USBHMSCOpen() USBHPRNClose() <- USBHMSCClose()
Delete this line from copied USBHPRNOpen() g_USBHMSCDevice.ulMaxLUN = 0xffffffff;
> now I would like to know how can I send data to printers using bulk transfers.
USBHPRNOpen() opens the bulk IN/OUT pipes. Using the OUT pipe, the data on pBuffer is sent to the printer, as follows. You may send any size of buffer, even greater than 64 bytes with single USBHCDPipeWrite() call.
ulBytes = USBHCDPipeWrite(g_USBHPRNDevice.ulBulkOutPipe, (unsigned char*)pBuffer, sizeof(pBuffer));
Tsuneo
Hi Tsuneo , I have already tried with USBHCDPipeWrite().I pass a string in this function and it prints only if the string ends with a carriage return () .
But how to print multiple strings in a single line . I tried writing the code in a for loop , now printer prints once in every 4 times command send.
I think there is garbage in pipes or not a proper HCD pipe write usage.
Regards, Dhanush.
> I think there is garbage in pipes or not a proper HCD pipe write usage.
What is the PDL supported by the printer? Before making such groundless assumption, you have to know printing protocol (ie. PDL) In my first post, I said you should find the PDL before coding your firmware.
Hi,
The Printer I am using is epson LX-300 and it supports ESC/P 9 pin PDL format. Can u please tell me now how should I go about this. The bold print and double print commands are working fine, I am facing the same problem discussed above.
The first time I send a string to be printed, it works. But the second time it prints garbage data.
Regards Dhanush