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.