Page 1 of 1
Bluetooth Printing
Posted: Tue Oct 28, 2008 4:43 pm
by Wolfgang Ciriack
Hello,
when i print to a bluetooth printer (EXTECH S2500THS) with
Code: Select all
local hOut := CreateFile( gd_PrinterPort, GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL )
cText+=.....
for n = 1 to Len( cText )
WriteByte( hOut, Asc( SubStr( cText, n, 1 ) ) )
next
return nil
some of the characters get lost (always other characters, sometimes only one, sometimes 2, 3 or 4). The printer is connected via Bluetooth seriell at COM8.
Must i configure something for bluetooth seriell communication at COM8 ?
Would it help, if i put a sleep in the WriteByte loop ? If yes, with which command ?
Posted: Tue Oct 28, 2008 5:30 pm
by Antonio Linares
Wolfgang,
Please try calling SysRefresh() from inside the loop
Posted: Tue Oct 28, 2008 5:52 pm
by Wolfgang Ciriack
Hello Antonio,
do yo mean it in this way ?
Code: Select all
for n = 1 to Len( cText )
WriteByte( hOut, Asc( SubStr( cText, n, 1 ) ) )
SysRefresh()
next
return nil
Posted: Tue Oct 28, 2008 5:52 pm
by Antonio Linares
yes
Posted: Thu Oct 30, 2008 8:46 am
by Wolfgang Ciriack
Hello Antonio,
first tests did not change anything, but now i have reseted the whole system and the printing seems to be ok now.
Thank you for your help.
Posted: Thu Oct 30, 2008 4:19 pm
by Richard Chidiak
Wolfgang
release the handle or you may go into trouble
The sysrefresh is needed after sending a msginfo or msgyesno, not needed in the loop.
i have been using BT printing with success since quite a while now . Only problem i have is printing french accented characters... still not solved
HTH
Code: Select all
for n = 1 to Len( cText )
WriteByte( hOut, Asc( SubStr( cText, n, 1 ) ) )
SysRefresh()
next
CloseHandle( hOut ) // this is missing
return nil
Posted: Thu Oct 30, 2008 4:47 pm
by Wolfgang Ciriack
Hello Richard,
thank you for your advice, i will add this to my prog.
Posted: Thu Oct 30, 2008 5:27 pm
by Maurizio
Wolfgang ,
I use this DLL
http://www.fieldsoftware.com/PrintDC.htm
You cann print to a wide variety of printers using Infrared, Bluetooth and 802.11b wireless network , choose the font and the color.
Maurizio
Posted: Thu Oct 30, 2008 6:00 pm
by Wolfgang Ciriack
Maurizio,
i have ordered this SDK together with the Extech printer, but i am waiting for the delivery. Until now, i have no idea how to integrate this in my app.
For now, it is ok with the text output, but perhaps a little bit later i will come back with questions to that SDK
There are now some other programming hints which i have to solve, connecting via seriell communication to a GPS-Logger, sending Data via Wireless Lan (if connected) and so on....
Posted: Fri Oct 31, 2008 7:21 am
by Maurizio
Wolfgang ,
This is a sample .
Regards MAurizio
Code: Select all
#include "FWCE.ch"
#define PD_SELECTPORTRAIT 0x00040000
#define PD_SELECTLANDSCAPE 0x00080000
//----------------------------------------------------------------------------//
function Main()
local oWnd, cValue := "One"
Local oFont
Local cTitle := "Stampa"
DEFINE WINDOW oWnd TITLE cTitle
DEFINE FONT oFont NAME "Tahoma" SIZE 80, 80
@ 1, 2 BUTTON "Test" SIZE 80, 30 ACTION PrintCE()
ACTIVATE WINDOW oWnd
return nil
//----------------------------------------------------------------------------//
function PrintCE()
OPEN_CE()
PrintLine("Print this line")
CLOSE_CE()
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <aygshell.h>
#include <commdlg.h>
#include "PrintDC.h"
static far HDC hPrDC;
//==============================================================================================
//TCHAR * AnsiToWide( char * );
extern "C" {
TCHAR * AnsiToWide( char * );
};
HB_FUNC( PRINTLINE )
{
int nLen = hb_parclen( 1 );
LPSTR pW = hb_parc( 1 ) ;
PDC_ExtTextOut(hPrDC,100,100, 0, NULL, AnsiToWide(pW ), nLen * 2 , NULL);
}
//==============================================================================================
HB_FUNC( OPEN_CE )
{
//Initialize PrintDC
HWND hWnd;
hWnd = FindWindow (NULL,L"Stampa");
// MessageBox( 0, wName, L"TRUE", 0 );
PDC_Init(_T("Key")); //
PRINTDLG pdlg;
memset(&pdlg, 0, sizeof(PRINTDLG));
pdlg.cbStruct = sizeof(PRINTDLG);
pdlg.hwndOwner= hWnd;
pdlg.dwFlags = PD_SELECTPORTRAIT | PD_INTHOUSANDTHSOFINCHES;
if (!PDC_PrintDlg(&pdlg)) { //Show "Select Printer" dialog
PDC_KillDoc(NULL); //user may have pressed cancel - free PrintDC resources and clear error condition
return;
}
//Get the printer DC
hPrDC=pdlg.hdc; //Can also use PDC_GetPrinterDC()
if (hPrDC==NULL) return;
//Get printer resolution
int DPI;
DPI=PDC_GetDeviceCaps(hPrDC,LOGPIXELSX);
//Get our margins - stored as thousandths of an inch.since used PD_INTHOUSANDTHSOFINCHES
// Convert margins to printer units (DPI) and subract physical offsets
int leftmargin,topmargin;
leftmargin=(pdlg.rcMargin.left*DPI)/1000 - PDC_GetDeviceCaps(hPrDC,PHYSICALOFFSETX);
topmargin=(pdlg.rcMargin.top*DPI)/1000 - PDC_GetDeviceCaps(hPrDC,PHYSICALOFFSETY);
//Lets get started printing
DOCINFO di;
PDC_StartDoc(hPrDC,&di);
PDC_StartPage(hPrDC);
//Print our text using default font
}
//==============================================================================================
HB_FUNC( CLOSE_CE )
{
PDC_EndPage(hPrDC);
PDC_EndDoc(hPrDC);
if (hPrDC) PDC_DeleteDC((HDC) hPrDC);
PDC_UnInit();
}
#pragma ENDDUMP
Posted: Fri Oct 31, 2008 7:25 am
by Wolfgang Ciriack
Thank you very much Maurizio, i save this on my disk !