jlcapel wrote:Arturo,
¿Como te fue la información?
¿Era lo que buscabas?
luis.santeliz wrote:yo logre que imprimiera directamente desde FWPPC utilizando una libreria que me proporciona el fabricante, estoy usando una BROTHER MW100 MOBILE PRINTER imprime perfecto, graficos y todo.
Antonio Linares wrote:Arturo,
Haz una búsqueda en estos foros por IRDA (botón "search" arriba) y encontrarás muchos comentarios que se han hecho de ese tema, gracias
Arturo Lopesoria wrote:
Antonio:
He leído ya cada uno de los distintos protocolos disponibles para IRDA. Hasta donde he podido entender el código siguiente debe funcionar. Sólo necesitaría de tu ayuda para ponerlo de manera adecuada usando las sentencias de BEGIN..PRAGMA dump.
Saludos. He Aquí:
#pragma BEGINDUMP
#include <windows.h>
#include <WinSock2.h>
HB_FUNC( WSASTARTUP )
{
WORD WSAVerReq = MAKEWORD( 1, 1 );
WSADATA WSAData;
if( WSAStartup( WSAVerReq, &WSAData ) != 0 )
{
// wrong winsock dlls?
}
}
SOCKET ServSock;
HB_FUNC( SOCKET )
{
if( ( ServSock = socket( AF_IRDA, SOCK_STREAM, 0 ) ) == INVALID_SOCKET )
{
// WSAGetLastError()
}
}
typedef struct _SOCKADDR_IRDA
{
u_short irdaAddressFamily;
u_char irdaDeviceID[ 4 ];
char irdaServiceName[ 25 ];
} SOCKADDR_IRDA, * PSOCKADDR_IRDA, FAR * LPSOCKADDR_IRDA;
int sizeOfSockAddr;
HB_FUNC( BIND )
{
SOCKADDR_IRDA ServSockAddr = { AF_IRDA, 0, 0, 0, 0, "SampleIrDAService" };
if( bind( ServSock, ( const struct sockaddr * ) &ServSockAddr,
sizeof( SOCKADDR_IRDA ) ) == SOCKET_ERROR )
{
// WSAGetLastError()
}
}
HB_FUNC( LISTEN )
{
if( listen( ServSock, 2 ) == SOCKET_ERROR )
{
// WSAGetLastError()
}
}
HB_FUNC( ACCEPT )
{
SOCKET NewSock;
while( 1 )
{
sizeOfSockAddr = sizeof( SOCKADDR_IRDA );
if( ( NewSock = accept( ServSock, ( struct sockaddr * ) &PeerSockAddr,
&sizeOfSockAddr ) ) == INVALID_SOCKET )
{
// WSAGetLastError()
// exit
}
// NewSock is a connected socket
// create a new thread and pass it NewSock, return to accept() on main
// or use NewSock here until done, then close it
}
}
#define BUFF_LEN 4096
int BytesRead, BytesSent;
char Buffer[ BUFF_LEN ];
HB_FUNC( RECV )
{
if( ( BytesRead = recv( ServSock, Buffer, sizeof( Buffer ), 0 ) ) == SOCKET_ERROR )
{
// WSAGetLastError()
}
if( BytesRead == 0 )
{
// peer has closed the connection and I have all the data
// close the socket now
}
}
HB_FUNC( SEND )
{
if( ( BytesSent = send( ServSock, Buffer, sizeof( Buffer ), 0 ) ) == SOCKET_ERROR )
{
// WSAGetLastError()
}
// check that BytesSent == sizeof(Buffer)
}
HB_FUNC( CLOSESOCKET )
{
if( closesocket( ServSock ) == SOCKET_ERROR )
{
// WSAGetLastError()
}
}
#pragma ENDDUMP
#pragma BEGINDUMP
#include <windows.h>
#include <WinSock2.h>
#define IAS_SET_ATTRIB_MAX_LEN 32
// buffer for IAS set
BYTE IASSetBuff[sizeof(IAS_SET) - 3 + IAS_SET_ATTRIB_MAX_LEN];
int IASSetLen = sizeof(IASSetBuff);
PIAS_SET pIASSet = (PIAS_SET) &IASSetBuff;
// for the setsockopt call to enable 9 wire IrCOMM
int Enable9WireMode = 1;
// server sockaddr with IrCOMM name
SOCKADDR_IRDA ServSockAddr = { AF_IRDA, 0, 0, 0, 0, "IrDA:IrCOMM" };
SOCKADDR_IRDA PeerSockAddr;
int sizeofSockAddr;
SOCKET ServSock;
SOCKET NewSock;
if ((ServSock = socket(AF_IRDA, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
// WSAGetLastError
}
// add IrCOMM IAS attributes for 3 wire cooked and 9 wire raw, see IrCOMM spec
memcpy(&pIASSet->irdaClassName[0], "IrDA:IrCOMM", 12);
memcpy(&pIASSet->irdaAttribName[0], "Parameters", 11);
pIASSet->irdaAttribType = IAS_ATTRIB_OCTETSEQ;
pIASSet->irdaAttribute.irdaAttribOctetSeq.Len = 6;
memcpy(&pIASSet->irdaAttribute.irdaAttribOctetSeq.OctetSeq[0],
"\000\001\006\001\001\001", 6);
if (setsockopt(ServSock, SOL_IRLMP, IRLMP_IAS_SET, (const char *) pIASSet, IASSetLen)
== SOCKET_ERROR)
{
// WSAGetLastError
}
// enable 9wire mode before bind()
if (setsockopt(ServSock, SOL_IRLMP, IRLMP_9WIRE_MODE, (const char *) &Enable9WireMode,
sizeof(int)) == SOCKET_ERROR)
{
// WSAGetLastError
}
if (bind(ServSock, (const struct sockaddr *) &ServSockAddr, sizeof(SOCKADDR_IRDA))
== SOCKET_ERROR)
{
// WSAGetLastError
}
// nothing special for IrCOMM from now on...
if (listen(ServSock, SERV_BACKLOG) == SOCKET_ERROR)
{
// WSAGetLastError
}
// IrCOMM Client
// The following code shows the steps necessary to build a client that connects via 9 Wire IrCOMM:
#define DEVICE_LIST_LEN 5
// discovery buffer
BYTE DevListBuff[sizeof(DEVICELIST) - sizeof(IRDA_DEVICE_INFO) +
(sizeof(IRDA_DEVICE_INFO) * DEVICE_LIST_LEN)];
int DevListLen = sizeof(DevListBuff);
PDEVICELIST pDevList = (PDEVICELIST) &DevListBuff;
int DevNum;
#define IAS_QUERY_ATTRIB_MAX_LEN 32
// buffer for IAS query
BYTE IASQueryBuff[sizeof(IAS_QUERY) - 3 + IAS_QUERY_ATTRIB_MAX_LEN];
Int IASQueryLen = sizeof(IASQueryBuff);
PIAS_QUERY pIASQuery = (PIAS_QUERY) &IASQueryBuff;
// for searching through peers IAS response
BOOL Found = FALSE;
UCHAR *pPI, *pPL, *pPV;
// for the setsockopt call to enbale 9 wire IrCOMM
int Enable9WireMode = 1;
SOCKADDR_IRDA DstAddrIR = { AF_IRDA, 0, 0, 0, 0, "IrDA:IrCOMM" };
if ((pConn->Sock = socket(AF_IRDA, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
// WSAGetLastError
}
// search for the peer device
pDevList->numDevice = 0;
if (getsockopt(pConn->Sock, SOL_IRLMP, IRLMP_ENUMDEVICES, (CHAR *) pDevList, &DevListLen)
== SOCKET_ERROR)
{
// WSAGetLastError
}
// if (pDevList->numDevice == 0)
{
// no devices found, tell the user
}
// assume first device, we should have a common dialog here
memcpy(&DstAddrIR.irdaDeviceID[0], &pDevList->Device[0].irdaDeviceID[0], 4);
// query the peer to check for 9wire IrCOMM support
memcpy(&pIASQuery->irdaDeviceID[0], &pDevList->Device[0].irdaDeviceID[0], 4);
// IrCOMM IAS attributes
memcpy(&pIASQuery->irdaClassName[0], "IrDA:IrCOMM", 12);
memcpy(&pIASQuery->irdaAttribName[0], "Parameters", 11);
if (getsockopt(pConn->Sock, SOL_IRLMP, IRLMP_IAS_QUERY, (char *) pIASQuery,
&IASQueryLen) == SOCKET_ERROR)
{
// WSAGetLastError
}
if (pIASQuery->irdaAttribType != IAS_ATTRIB_OCTETSEQ)
{
// peer's IAS database entry for IrCOMM is bad
// error
}
if (pIASQuery->irdaAttribute.irdaAttribOctetSeq.Len < 3)
{
// peer's IAS database entry for IrCOMM is bad
// error
}
// search for the PI value 0x00 and check 9 wire, see IrCOMM spec.
pPI = pIASQuery->irdaAttribute.irdaAttribOctetSeq.OctetSeq;
pPL = pPI + 1;
pPV = pPI + 2;
while (1)
{
if (*pPI == 0 && (*pPV & 0x04))
{
Found = TRUE;
break;
}
if (pPL + *pPL >= pIASQuery->irdaAttribute.irdaAttribOctetSeq.OctetSeq +
pIASQuery->irdaAttribute.irdaAttribOctetSeq.Len)
{
break;
}
pPI = pPL + *pPL;
pPL = pPI + 1;
pPV = pPI + 2;
}
if (! Found)
{
// peer doesn't support 9 wire mode
// error
}
// enable 9wire mode before connect()
if (setsockopt(ServSock, SOL_IRLMP, IRLMP_9WIRE_MODE, (const char *) &Enable9WireMode,
sizeof(int)) == SOCKET_ERROR)
{
// WSAGetLastError
}
// nothing special for IrCOMM from now on...
if (connect(pConn->Sock, (const struct sockaddr *) &DstAddrIR, sizeof(SOCKADDR_IRDA))
== SOCKET_ERROR)
{
// WSAGetLastError
}
#pragma ENDDUMP
#include "FWCE.ch"
function Main()
IrdaPrint( "Hello World!" )
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#define _WIN32_WCE
#include <WinSock2.h>
#include <af_irda.h>
#define NUMRETRY 10 // No está definido en el ejemplo. Usamos 10 a ver que tal
HB_FUNC( IRDAPRINT ) // cText
{
SOCKET sock; // Socket bound to the server
DEVICELIST devList; // Device list
int iCount = 0, // Number of retries
index = 0, // Integer index
iDevListLen = sizeof(devList); // Size of the device list
TCHAR szError[ 100 ]; // Error message string
WSADATA wsaData;
WORD wVersion = MAKEWORD( 1, 1 ); // Winsock Version 1.1
BYTE IASQueryBuff[ sizeof( IAS_QUERY ) - 3 + IAS_MAX_ATTRIBNAME ];
int IASQueryLen = sizeof( IASQueryBuff );
PIAS_QUERY pIASQuery = ( PIAS_QUERY ) &IASQueryBuff;
char szServiceName[ 12 ];
SOCKADDR_IRDA iraddr;
struct linger l;
if( WSAStartup( wVersion, &wsaData ) != 0 )
{
wsprintf( szError, TEXT( "WSAStartup failed. Error: %d" ),
WSAGetLastError() );
MessageBox( 0, szError, TEXT( "error" ), 0 );
return;
}
// Create a socket that is bound to the server.
if( ( sock = socket( AF_IRDA, SOCK_STREAM, 0 ) ) == INVALID_SOCKET )
{
wsprintf( szError, TEXT( "Allocating socket failed. Error: %d" ),
WSAGetLastError() );
MessageBox( 0, szError, TEXT( "error" ), 0 );
WSACleanup();
return;
}
// Initialize the number of devices to zero.
devList.numDevice = 0;
while( ( devList.numDevice == 0 ) && ( iCount <= NUMRETRY ) )
{
// Retrieve the socket option
if( getsockopt( sock, SOL_IRLMP, IRLMP_ENUMDEVICES, ( char * ) &devList,
&iDevListLen) == SOCKET_ERROR )
{
wsprintf( szError, TEXT( "Server could not be located, getsockopt failed. Error: %d"), WSAGetLastError() );
MessageBox( 0, szError, TEXT( "Error" ), 0 );
closesocket( sock );
WSACleanup();
return;
}
if( devList.numDevice == 0 )
{
iCount++;
Sleep( 1000 );
}
}
if( iCount > NUMRETRY )
{
MessageBox( 0, TEXT( "Server could not be located!" ), TEXT( "Error" ), 0 );
closesocket( sock );
WSACleanup();
return;
}
memcpy( &pIASQuery->irdaDeviceID, devList.Device[ 0 ].irdaDeviceID, 4 );
memcpy( &pIASQuery->irdaClassName, "IrLPT", 6 );
memcpy( &pIASQuery->irdaAttribName, "IrDA:IrLMP:LsapSel", 19 );
if( getsockopt( sock, SOL_IRLMP, IRLMP_IAS_QUERY, ( char * ) pIASQuery,
&IASQueryLen) == SOCKET_ERROR )
{
wsprintf( szError, TEXT( "getsockopt failed. Error: %d" ), WSAGetLastError() );
MessageBox( 0, szError, TEXT( "Error" ), 0 );
closesocket( sock );
WSACleanup();
return;
}
sprintf( szServiceName, "LSAP-SEL%d", pIASQuery->irdaAttribute.irdaAttribInt );
memset( &iraddr, 0, sizeof( iraddr ) );
iraddr.irdaAddressFamily = AF_IRDA;
memcpy( iraddr.irdaDeviceID, devList.Device[ 0 ].irdaDeviceID, 4 );
memcpy( iraddr.irdaServiceName, szServiceName, strlen( szServiceName ) + 1 );
// Establish a connection to the socket.
if( connect( sock, ( struct sockaddr * ) &iraddr, sizeof( iraddr ) ) == SOCKET_ERROR )
{
wsprintf( szError, TEXT( "Connecting to the server failed. Error: %d" ), WSAGetLastError() );
MessageBox( 0, szError, TEXT( "Error" ), MB_OK );
closesocket( sock );
WSACleanup();
return;
}
// Turn on SO_LINGER
l.l_onoff = 1;
l.l_linger = 0;
if( setsockopt( sock, SOL_SOCKET, SO_LINGER, ( char * ) &l,
sizeof( struct linger ) ) == SOCKET_ERROR )
{
wsprintf( szError, TEXT( "setsockopt failed. Error: %d" ), WSAGetLastError() );
MessageBox( 0, szError, TEXT( "Error" ), MB_OK );
closesocket( sock );
WSACleanup();
return;
}
// Send a string from the client socket to the server socket.
if( send( sock, hb_parc( 1 ), hb_parclen( 1 ) + 1, 0 ) == SOCKET_ERROR )
{
wsprintf( szError, TEXT( "Sending data to the server failed. Error: %d" ),
WSAGetLastError() );
MessageBox( 0, szError, TEXT( "Error" ), MB_OK );
closesocket( sock );
WSACleanup();
return;
}
// Close the socket.
if( closesocket( sock ) == SOCKET_ERROR )
{
wsprintf( szError, TEXT( "closesocket failed. Error: %d" ),
WSAGetLastError() );
MessageBox( 0, szError, TEXT( "Error" ), 0 );
WSACleanup();
return;
}
WSACleanup();
}
#pragma ENDDUMP
Return to FiveWin para Pocket PC
Users browsing this forum: No registered users and 14 guests