Page 2 of 3
Posted:
Sat Feb 17, 2007 9:00 am
by Antonio Linares
Richard,
Could you please try this:
- Code: Select all Expand view
HB_FUNC( WRITE233 ) // hComm --> lOk
{
DWORD cBytes;
unsigned char ch = 233;
hb_retl( ( BOOL ) WriteFile( ( void * ) hb_parnl( 1 ), &ch, 1, &cBytes, NULL ) );
}
Just to check if 233 ascii gets properly printed, thanks
Posted:
Sat Feb 17, 2007 9:20 am
by Richard Chidiak
Antonio
No it is not good
This is the sample i am using (just to check the syntax)
I had to remove the INT RC (compile error)
#include "C:\FWPPC\INCLUDE\FWCE.ch"
#define GENERIC_READ 0x80000000
#define GENERIC_WRITE 0x40000000
#define GENERIC_REWRITE 0xC0000000
#define OPEN_EXISTING 3
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_FLAG_OVERLAPPED 0x40000000
#define WriteByte _WriteByte
function Main()
LOCAL I := 0, ;
CTEXTE := SPACE(30), ;
HOUT
hOut := CreateFile( "COM5:",GENERIC_REWRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL )
CTEXTE := "Désignation à suivre €"
SENDTEXT(hout,Ctexte)
CloseHandle( hOut )
RETURN Nil
function SendText( hOut, cText )
local n
for n = 1 to Len( cText )
WriteByte( hOut, Asc( SubStr( cText, n, 1 ) ) )
next
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <aygshell.h>
HB_FUNC( _WRITEBYTE ) // hComm, nChar --> lOk
{
DWORD cBytes;
unsigned char ch = 233;
// unsigned char ch = ( unsigned char ) hb_parnl( 2 );
hb_retl( ( BOOL ) WriteFile( ( void * ) hb_parnl( 1 ), &ch, 1, &cBytes, NULL ) );
}
#pragma ENDDUMP
Posted:
Sat Feb 17, 2007 11:15 am
by Enrico Maria Giordano
Antonio Linares wrote:- Code: Select all Expand view
HB_FUNC( WRITE233 ) // hComm --> lOk
{
DWORD cBytes;
unsigned char ch = 233;
hb_retl( ( BOOL ) WriteFile( ( void * ) hb_parnl( 1 ), &ch, 1, &cBytes, NULL ) );
}
Why the cast to void *? It should be to HANDLE. But this is surely not the problem.
EMG
Posted:
Sat Feb 17, 2007 2:51 pm
by Antonio Linares
Enrico,
From Windows headers: typedef void *HANDLE;
Its quite strange why WriteFile() is not able to manage unsigned chars...
Posted:
Sun Feb 18, 2007 3:40 pm
by Richard Chidiak
Antonio
This is from Pocket pc Msdn
Does it make any sense in this case ?
You should note that the lpBuffer parameter of WriteFile is a LPCVOID (typedef for const void *).
That means the lpBuffer parameter is type-agnostic. You could make it point to an array of chars, or you can make it point to an array of WCHARs, an array of ints, array of doubles, array of Matrices, array of FileSystems, array of... you get the idea. The key to telling WriteFile what the data type is, is through the nNumberofBytesToWrite parameter.
If you want to write 2 WCHARs to the stream, the 3rd parameter to WriteFile should be 2*sizeof(WCHAR) (but make sure that the 2 WCHARs are next to each other in memory).
Note, that sending UNICODE across the serial port is only useful if the program on the other side of the port understands UNICODE.
// WriteFile(f, data, lstrlen(data) * sizeof(TCHAR), &bytesWritten, NULL); // RIGHT
Posted:
Sun Feb 18, 2007 6:07 pm
by Antonio Linares
Richard,
It does not make a difference. We are placing an unsigned char into the buffer and WriteFile() should transmit an unsigned char.
Could you try to send the data to a different bluetooth device ? Maybe the difference comes from the receiver
Posted:
Sun Feb 18, 2007 6:08 pm
by Antonio Linares
Richard,
Does that printer work with unicode chars ?
Posted:
Sun Feb 18, 2007 7:39 pm
by Richard Chidiak
Antonio
The printer is OK There is no setting on it.
When i send the txt file to the printer via windows mobile (send via bluetooth), the printout is OK.
The problem is i the writefile function
Richad
Posted:
Sun Feb 18, 2007 7:40 pm
by Richard Chidiak
I don't have the documentation of the printer available here, but i will take a look at it tomorrow morning.
My guess is "Yes" it takes Unicode, see my previous post.
Posted:
Mon Feb 19, 2007 2:00 pm
by Richard Chidiak
Antonio
The printer works with Unicode
It is a brand new HP Deskjet 460
I tried it also on another BT printer (Epson), same problem.
Looks like we have a problem with accented characters.
I have a work around but can not find the appropriate C code for it. Maybe you can help ?
I want to print a txt file from fwppc by calling the file explorer, send via bluetooth function. This will temporarly fix my problem.
Thanks for the help,
Richard
Posted:
Mon Feb 19, 2007 6:46 pm
by Antonio Linares
Richard,
Please try this:
- Code: Select all Expand view
HB_FUNC( WRITE233 ) // hComm --> lOk
{
DWORD cBytes;
WCHAR ch = 233;
hb_retl( ( BOOL ) WriteFile( ( void * ) hb_parnl( 1 ), &ch, sizeof( ch )
, &cBytes, NULL ) );
}
Posted:
Tue Feb 20, 2007 7:42 am
by Richard Chidiak
Same result
Bad character printed.
Richard
Posted:
Tue Feb 20, 2007 7:46 am
by Enrico Maria Giordano
Are you able to read what exactly comes out of the palmtop?
EMG
Posted:
Tue Feb 20, 2007 7:52 am
by Richard Chidiak
Enrico
What do you mean by this ? i do not understand
Richard
Posted:
Tue Feb 20, 2007 7:55 am
by Enrico Maria Giordano
Till now you only know that the printer won't print what you expected. It would be useful to know what number(s) really comes out of the palmtop instead.
EMG