Solved Printing to Datamax printer

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
kclench
United States of America
Posts: 102
Joined: 26 Jun 2017, 23:22
Location: Ventura, CA, USA

Printing to Datamax printer

Post by kclench » 26 May 2005, 20:14

 Posted by:  Karen Clench 

Does someone have a sample of code to print to a Datamax printer (COM1:
port) from CTD? Specifically for passing / printing barcodes on Labels.I
have found Joe Meyer (ITG)'s article to print directly to a device. I
have installed Seagull / Datamax drivers for my model of printer, I have
installed a purchased 3of9 font. Any information on how others do this
processing will be greatly appreciated. Thank you very much.

Pedro Vazquez

Re: Printing to Datamax printer

Post by Pedro Vazquez » 26 May 2005, 21:21

 Posted by:  Pedro Vazquez 

Karen,

I do that using a txt file with a template... I substitute the values
between {} with the values I want to print and then send it through the
serial port... here is some source:

Here I change the values:

Code: Select all

!!CB!! 70
If VisFileOpen(hFile, strDoc, OF_Read) != VTERR_Ok
 Return SalMessageBox("Error opening " || strDoc, 'Error', 0)
Call VisFileRead(hFile, strTemplate, VisFileGetSize(strDoc))
Call VisFileClose(hFile)

Code: Select all

!!CB!! 70
Set strTemplate = VisStrSubstitute (strTemplate, "{QUANTITY}",   '1')
Set strTemplate = VisStrSubstitute (strTemplate, "{coditm}",   'Product code')
...... and so on...

Here I send the data to the printer:

Code: Select all

!!CB!! 70
Set nComHandle = CreateFileA( strPort, GENERIC_WRITE, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0 )
If nComHandle = INVALID_HANDLE_VALUE
 ! get window error
 Set nErr = GetLastError()
 Call SalMessageBox( "Error opening " || strPort, "ERROR", MB_Ok )
 Return FALSE
Set nSent = 0
Set strTemplateAux = strTemplate
While SalStrLength(strTemplate) > 0
 Call WriteFile( nComHandle, strTemplateAux, SalStrLength(strTemplateAux),
nSent, 0 )
 If nSent <= SalStrLength(strTemplateAux)
  Set strTemplateAux = SalStrRightX ( strTemplateAux,
SalStrLength(strTemplateAux) - nSent )
Call FlushFileBuffers( nComHandle )
Call CloseHandle( nComHandle )
Set nComHandle = -1
Here are the definitions for the api functions from kernell32.dll:

Code: Select all

!!CB!! 145
Function: CreateFileA
 Description: The CreateFile function creates or opens the following objects
and returns a handle that can be used to access the object:

     files
     pipes
     mailslots
     communications resources
     disk devices (Windows NT only)
     consoles
     directories (open only)

   HANDLE CreateFile(
    LPCTSTR lpFileName,    // pointer to name of the file
    DWORD dwDesiredAccess,    // access (read-write) mode
    DWORD dwShareMode,    // share mode
    LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security
attributes
    DWORD dwCreationDistribution,   // how to create
    DWORD dwFlagsAndAttributes,   // file attributes
    HANDLE hTemplateFile    // handle to file with attributes to copy
    );

   Parameters
    see Visual C++
 Export Ordinal: 0
 Returns
  Number: LONG
 Parameters
  String: LPCSTR
  Number: DWORD
  Number: DWORD
  Number: DWORD
  Number: DWORD
  Number: DWORD
  Number: HANDLE
Function: WriteFile
 Description: The WriteFile function writes data to a file and is designed
for both synchronous and asynchronous operation. The function starts writing
data to the file at the position indicated by the file pointer. After the
write operation has been completed, the
   file pointer is adjusted by the number of bytes actually written, except
when the file is opened with FILE_FLAG_OVERLAPPED. If the file handle was
created for overlapped input and output (I/O), the application must adjust
the position of the file
   pointer after the write operation is finished.

   BOOL WriteFile(
    HANDLE hFile,    // handle to file to write to
    LPCVOID lpBuffer,    // pointer to data to write to file
    DWORD nNumberOfBytesToWrite,  // number of bytes to write
    LPDWORD lpNumberOfBytesWritten,  // pointer to number of bytes written
    LPOVERLAPPED lpOverlapped  // pointer to structure needed for overlapped
I/O
    );
   The OVERLAPPED structure contains information used in asynchronous input
and output (I/O).
 Export Ordinal: 0
 Returns
  Boolean: BOOL
 Parameters
  Number: HANDLE
  String: LPCSTR
  Number: DWORD
  Receive Number: LPDWORD
  Number: DWORD
Function: CloseHandle
 Description: The CloseHandle function closes an open object handle.

   BOOL CloseHandle(
    HANDLE hObject  // handle to object to close
    );
 Export Ordinal: 0
 Returns
  Boolean: BOOL
 Parameters
  Number: HANDLE
Function: FlushFileBuffers
 Description:
 Export Ordinal: 0
 Returns
  Boolean: BOOL
 Parameters
  Number: HANDLE
Attached you can see a template file...

Hope it helps...

Regards

Pedro E. Vazquez
Buenos Aires Software S.A. -- www.bas.com.ar
Argentina
You do not have the required permissions to view the files attached to this post.

Pedro Vazquez

Re: Printing to Datamax printer

Post by Pedro Vazquez » 26 May 2005, 21:37

 Posted by:  Pedro Vazquez 

This line ----> While SalStrLength(strTemplate) > 0

Should be this -----> While SalStrLength(strTemplateAux) > 0

Pedro Vazquez

Re: Printing to Datamax printer

Post by Pedro Vazquez » 26 May 2005, 21:38

 Posted by:  Pedro Vazquez 

I send the commands directly to the port, without the need of any driver....

Graham Fleming

Re: Printing to Datamax printer

Post by Graham Fleming » 27 May 2005, 08:14

 Posted by:  Graham Fleming 

I have done this by just creating a report with Report Builder and using a
windows printer driver. If I remember correctly I think I had to find one
that worked, there was 2 or 3 on the net but only 1 worked for me.

I used EAN 13 font but I don't really see why 3of9 wouldn't work the same.

graham

Martin Duty

Re: Printing to Datamax printer

Post by Martin Duty » 27 May 2005, 14:29

 Posted by:  Martin Duty 

We just the Seagull Scientific drivers from the Datamax download area.
Created a QRP, used Free3of9 barcode fonts and everything works fine.

Martin

kclench
United States of America
Posts: 102
Joined: 26 Jun 2017, 23:22
Location: Ventura, CA, USA

Re: Printing to Datamax printer

Post by kclench » 31 May 2005, 19:43

 Posted by:  Karen Clench 

Would it work the same without calling a QRP report, staying inside the
application? Or do you need to use the report writer? Can you show me an
excerpt from your souce code of the report file on how the Seagull
drivers are involved or called?

Martin Duty

Re: Printing to Datamax printer

Post by Martin Duty » 31 May 2005, 21:06

 Posted by:  Martin Duty 

Hi Karen,

We use the 4801 Datamax printer. We use the Seagull drivers found on the
Datamax web site. We use a QRP and just treat it like a standard printer and
use code simular to the following:

Code: Select all

Set strLocationPrintReport = 'Martin.QRP'
Set strBindVars = 'strVar1, strVar2'
Set strReportVars = 'Var1, Var2'
While SalTblFindNextRow( tblCodes, nNextRow, ROW_New, 0)
    Set nReportErrorReturn = SalReportPrint( hWndForm,
strLocationPrintReport, strBindVars, strReportVars, 1, RPT_PrintAll, 0, 0,nError)
Now if you do not want to use QRP's or such you will have to hard code
everything to the printer. I've also done this with Intermec barcode
printers. Here is code simular to how we do that:

Code: Select all

Call SalFileOpen( hPrinterPort, sCOM, OF_Create | OF_ReadWrite)
!!CB!! 129
Set strItemID2 = SalNumberToStrX( nItemID, 0 )
Set strClientName = SalStrLeftX(strClientName, 20)
Set ETX = SalNumberToChar(03)
Set SI = SalNumberToChar(15)
Set CAN = SalNumberToChar(24)
Set ESC = SalNumberToChar(27)
Set CR= SalNumberToChar(13)
Set STX = SalNumberToChar(02)
Set ETB = SalNumberToChar(23)
! ----------------------------------------------- This is the static data,
font, and barcode setup.
Set sPrinterCommand[1] = STX || ESC || 'c' || ETX || STX || ESC || 'P' ||ETX
Set sPrinterCommand[2] = STX || 'E4;F4;' || ETX
Set sPrinterCommand[3] = STX || 'H0;o15,2;f0;c2;h2;w1;d3,Client:;' || ETX
Set sPrinterCommand[4] = STX || 'H1;o15,67;f0;c2;h2;w1;d3,Dept:;' || ETX
Set sPrinterCommand[5] = STX || 'H2;o15,102;f0;c2;h2;w1;d3,Record #:;' ||ETX
Set sPrinterCommand[6] = STX || 'H3;o15,137;f0;c2;h2;w1;d3,UV&S Item ID:;'|| ETX
Set sPrinterCommand[7] = STX || 'H4;o15,205;f0;c0;h2;w1;d3,Underground
Vaults and Storage, Inc.;' || ETX
While nCounter < 18
 Set sPrinterString = sPrinterString || sPrinterCommand[nCounter]
 Set nCounter = nCounter + 1
Call SalFileWrite(hPrinterPort, sPrinterString, SalStrLength(sPrinterString))
HTH

Martin

kclench
United States of America
Posts: 102
Joined: 26 Jun 2017, 23:22
Location: Ventura, CA, USA

Re: Printing to Datamax printer

Post by kclench » 09 Jun 2005, 21:01

 Posted by:  Karen Clench 

Martin -
I guess I am missing something that other developers know. I don't
understand the basics of communicating via the Seagull drivers, perhaps?

Don't I need to reference the Seagull drivers via the CTD external
files, library file: seagulldefinitionname .dll ?
And then in the code call a function from their dll in order to send the
text string to the Datamax printer via Seagull drivers? And if so, how
do I see what functions and parameters are in the dlls? I am basing this
assumption on external libraries like kernal32.dll and user32.dll have
functions with parameters that we call all the time from CTD code.

I have tried to implement writing directly to the COM1: port without the
Seagull drivers, based on the example set forth in Joe Meyer's "Printing
directly to a Device" but is does not print a label until I have exited
my application. So I would really prefer to write my code to implement
the Seagull drivers.

The Datamax printer is connected via the Serial port and cannot be put
through the USB or other ports. (These are printers circa 1996). I am
reviewing all documentation supplied with the downloaded drivers and on
Seagull Scientific's website for insight on communicating with my Label
printer.

Thank you very much for your help.
Sincerely,
Karen

Martin Duty

Re: Printing to Datamax printer

Post by Martin Duty » 09 Jun 2005, 23:07

 Posted by:  Martin Duty 

Hi Karen,

If you have printer drivers for the Datamax printer, then just print to it
using a QRP. Nothing special. It works just like any other printer you have
drivers for.

If you want to drive the printer your self (or do not have drivers) then you
have to pass code to the serial port like you have read about. The coding
you send to the printer you should be able to find in the printer manual.
You would not use a DLL for this, but open a file called COM1
(SalFileOpen( hPrinterPort......), write to it (
SalFileWrite(hPrinterPort,......), then close the file ( SalFileClose(
hPrinterPort) ..... which may be why your program doesn't print until the
program exits).

If you still can't figure this out, let me know. I have a barcode printing
program that is small. I'd have to do some minor changes to it before
releasing it, but shouldn't be a big thing.

Martin

kclench
United States of America
Posts: 102
Joined: 26 Jun 2017, 23:22
Location: Ventura, CA, USA

Re: Printing to Datamax printer

Post by kclench » 10 Jun 2005, 02:04

 Posted by:  Karen Clench 

The reason I have not tried to write a .qrp is that my existing label
printing code is already in the application, it was written many years
ago. At that time SqlWindow and CTD 1.1 could not pass Escape characters
in the string for Barcodes. We solved the problem by writing a custom
dll(for pass-through capability only) and defining the installed printer
as 'Generic/ Text' instead of COM1. The custom .dll was declared in
external libraries and the function was called from my code - passing
the print string to the Label printer.

The users have been holding onto a Win98 computer for the label printer
because the custom dll and Generic / Text combination no longer works in
Win2000 and WinXP.I was hoping to use the majority of existing code and
print to the Label printer via the Seagull / Datamax drivers. I have
installed the Manufacturer's drivers, and in Control Panel / Printers
and Faxes installed the Label Printer as name 'Allegro' (the model of
the printer manufactured by Datamax) it is using Port COM1 (serial).
selecting properties on the printer verifies that Seagull drivers are
know to that printer.

Is there a line of code in your .qrp that sends the data-string to the
Label Printer knowing that it is Seagull's drivers?

Thanks again for your help and patience in the issue.

Karen

Martin Duty

Re: Printing to Datamax printer

Post by Martin Duty » 10 Jun 2005, 14:39

 Posted by:  Martin Duty 

Hi Karen,

I hope you are not using 1.1 now are you? I do know that since 1.5 you can
pass escape charaters our the serial port. That is how we have always
printed to our Intermec Printers.

Nope.... prints to the default printer (which I have code to swap the
default printer to the Datamax, print the QRP, then swap back to the default
printer to what it was.

Not a problem. Many here have helped me with my problems.

With all of your last reply, I think we can get you to a solution. Your
existing code must be creating a string which you pass to your DLL. Instead
of passing this string to the DLL, now create/open a file (use SAL like I've
shown you or WinAPI like Pedro showed). Write your string to that file. Then
close the file. and your barcode should print. This will all be done without
a printer driver or a QRP.

If you are still having problem with this, can you write a small program
that will just print one or two barcodes to your printer? If so send this to
me and I'll show you the code changes.

Martin

kclench
United States of America
Posts: 102
Joined: 26 Jun 2017, 23:22
Location: Ventura, CA, USA

Re: Printing to Datamax printer

Post by kclench » 10 Jun 2005, 22:23

 Posted by:  Karen Clench 

Finally,I have success with labels printing via going directly to the
serial port using SAL code. I changed the printer properties to use the
Generic drivers instead of Seagull and now it works.

kclench
United States of America
Posts: 102
Joined: 26 Jun 2017, 23:22
Location: Ventura, CA, USA

Re: Printing to Datamax printer

Post by kclench » 31 Jan 2007, 01:46

 Posted by:  Karen Clench 

My client has decide thatI must come up with another solution via using
the Seagull Drivers (Datamax) because printing directly to the serial
(COM) port is causing badly printed labels. After 32 labels they are
incorrect and I assume the buffer is overflowing. Do you have
suggestions on what I should try? I have never written a qrp report. I
am currently in version CTD4.1.

Martin Duty

Re: Printing to Datamax printer

Post by Martin Duty » 31 Jan 2007, 15:07

 Posted by:  Martin Duty 

Hi Karen,

I've attached the QRP we use to print barcodes on our Datamax printers. I
use the Seagull printer driver that came with them. I also use barcodes
called Free3of9 (http://www.squaregear.net/fonts/free3of9.shtml)

My code to print (kind of):

Code: Select all

C_Pushbutton_Print_BarCode: pbPrint
Message Actions
    On SAM_Click
        Set strLocationPrintReport = fhFileDirectory || '\\BoxBarCode.qrp'
        Set strReportVars = 'BoxNmbr, CompanyName'
        Set strBindVars = 'strFinalReportData, strValue'
        Set nNextRow = TBL_MinRow
        Set nReportErrorReturn = SalReportPrint( hWndForm,
strLocationPrintReport, strBindVars,
strReportVars, 1, RPT_PrintAll, 0, 0, nError)
Form Message Actions

Code: Select all

On SAM_ReportFetchNext
    While SalTblFindNextRow( tblCodes, nNextRow, ROW_Selected, 0)
        Call SalTblSetFocusRow( tblCodes, nNextRow)
        If SalIsNull( tblCodes.colCode )
            Call SalTblDeleteRow( tblCodes, nNextRow, TBL_Adjust)
        Else
            Set strFinalReportData= tblCodes.colCode
            Return TRUE
     Return FALSE
Hope this helps.

Martin
PS Good move on upgrading to a newer version.
You do not have the required permissions to view the files attached to this post.

Return to “td.sourcecode”

Who is online

Users browsing this forum: [Ccbot] and 1 guest