Hola amigos :
Alguien me podría mostrar un ejemplo de envío de datos al puerto serial de una Pocket ?
Saludos y gracias por adelantado.
// BlueTooth use sample
#include "FWCE.ch"
#define GENERIC_READ 0x80000000
#define GENERIC_WRITE 0x40000000
#define GENERIC_REWRITE 0xC0000000
#define OPEN_EXISTING 3
#define FILE_ATTRIBUTE_NORMAL 0x00000080
function Main()
local hCom:=NIL
local aCom:={"COM1:","COM2:","COM3:","COM4:","COM5:","COM6:","COM7:","COM8:"}
PUBLIC cCom:=aCom[8]
PUBLIC oWnd
// local hIn := CreateFile( "COM3:",; // change the number as needed
// GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL )
DEFINE WINDOW oWnd TITLE "Comunicaciones COMx"
#define nSEP 5
#define nMARGEN_DER 10
#define nANCHO 20
#define oBCONECT oWnd:aControls[1]
#define oCPUERTO oWnd:aControls[2]
#define oBIMPRIM oWnd:aControls[3]
#define oBSALIR oWnd:aControls[4]
@ 10, nMARGEN_DER BUTTON "Conectar" SIZE 80, 20 PIXEL OF oWnd
oBCONECT:bAction:={|| hCom:=Conectar(cCOM) }
// oBCONECT:bWhen:={|| hCom==NIL }
@ oBCONECT:nTop, oBCONECT:nRight+nSEP COMBOBOX cCom ITEMS aCom SIZE 70,nANCHO PIXEL OF oWnd
@ oBCONECT:nBottom+nSEP, nMARGEN_DER BUTTON "Imprimir" ACTION Imprime(hCom) SIZE 80, 20 PIXEL OF oWnd
oBIMPRIM:bWhen:={|| hCom<>NIL }
@ oBIMPRIM:nBottom+nSEP , nMARGEN_DER BUTTON "Salir" SIZE 80, 20 PIXEL OF oWnd
oBSALIR:bAction:={|| CloseHandle(hCom), oWnd:End() }
// ACTION MsgInfo(ReadText(hCom)) SIZE 80, 20
ACTIVATE WINDOW oWnd
CloseHandle( hCom )
// CloseHandle( hIn )
return nil
FUNCTION Conectar(cPTO)
local hCom
local err
IF cPTO=NIL
RETURN .F.
ENDIF
SetWindowText(oBCONECT:hWnd,"Conectando "+cPTO) // Cambia el caption del boton para saber que se esta conectando
hCom := CreateFile( cPTO, nor( GENERIC_WRITE, GENERIC_READ ), 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL ) // aqui crea la conexion con el puerto
SetComm(hCom, 9600, .F., 8, 1) // Configura el puerto
err:=GetLastError()
IF err=-1
MsgInfo(err,"Error!")
ELSE
SetWindowText(oBCONECT:hWnd,"Desconectar")
oBCONECT:bAction:={||CloseHandle(hCom), hCom:=NIL, SetWindowText(oBCONECT:hWnd,"Conectar"), oBCONECT:bAction:={|| hCom:=Conectar(cCOM)} }
ENDIF
RETURN hCom
#DEFINE CRLF Chr(13)+Chr(10)
//
// ESC/P CODES
#DEFINE ESC Chr(27)
#DEFINE EXPAND Chr(14)
#DEFINE _EXPAND Chr(20)
#DEFINE NEGR Chr(15)
#DEFINE _NEGR Chr(18)
#DEFINE SANSSER ESC+"k1"
#DEFINE ROMAN ESC+"k0"
#DEFINE DRAFT ESC+"x0"
#DEFINE FORMFEED Chr(12)
#DEFINE ULTIMAPAG Chr(26)
FUNCTION Imprime(hCom)
// SendText(hCom,ESC+"iS") // Inicialización Obligatoria
// MsgInfo(ReadText(hCom,32)) // Recibe información de statu
SendText(hCom,ESC+"@")
// SendText(hCom,ESC+"ia"+Chr(0))
// SendText(hCom,ESC+"k1")
SendText(hCom,EXPAND+"LA EMPRESA MODELO"+_EXPAND)
SendText(hCom,SANSSER+"esto es una prueba SANSERIF")
SendText(hCom,ROMAN+"esto es una prueba ROMAN")
SendText(hCom,DRAFT+"esto es una prueba DRAFT")
SendText(hCom,ULTIMAPAG)
RETURN
function SendText( hOut, cText, lCr )
local n
DEFAULT lCr:=.T.
for n = 1 to Len( cText )
WriteByte( hOut, Asc( SubStr( cText, n, 1 ) ) )
next
IF lCr
WriteByte( hOut, 13 )
WriteByte( hOut, 10 )
ENDIF
return nil
FUNCTION ReadText(hSer,nBytes)
LOCAL nChr, cTxt:=""
DEFAULT nBytes:=32
WHILE nChr != 236 .AND. nChr != 10
nChr = ( READBYTE( hSer ) )
cTxt += ALLTRIM(STR( nChr,3,0 ))+" "
IF (nBytes--)=0
exit
ENDIF
ENDDO
RETURN cTxt
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
LPSTR WideToAnsi( LPWSTR );
HB_FUNC( GETWINDOWTEXT )
{
HWND hWnd = ( HWND ) hb_parnl( 1 );
int iLen = GetWindowTextLength( hWnd );
LPWSTR pText = ( LPWSTR ) hb_xgrab( ( iLen * 2 ) + 2 );
LPSTR pAnsi;
GetWindowText( hWnd, pText, iLen + 1 );
pAnsi = WideToAnsi( pText );
hb_retc( pAnsi );
hb_xfree( pAnsi );
hb_xfree( pText );
}
/*
Configurar el puerto COMx:
SetComm(hCom, nBaudRate, nParidad, nDataBits, lStopBits)
ej: SetComm(hCom, 9600, .F., 9, 1)
*/
HB_FUNC( SETCOMM )
{
DCB dcb;
GetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb );
dcb.BaudRate = hb_parnl( 2 );
dcb.Parity = hb_parl( 3 );
dcb.ByteSize = hb_parnl( 4 );
dcb.StopBits = hb_parnl( 5 );
hb_retl( SetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb ) );
}
HB_FUNC( MGETREPLACE ){}
HB_FUNC( GETWINTXTLENGHT ){}
HB_FUNC( MGETLINE ){}
#pragma ENDDUMP
Return to FiveWin para Pocket PC
Users browsing this forum: No registered users and 10 guests