Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-04-2010
ASAPLTDA ASAPLTDA is offline
Miembro
 
Registrado: jun 2003
Ubicación: COLOMBIA-CALI
Posts: 639
Poder: 23
ASAPLTDA Va por buen camino
convertir instruccion C a Delphi Lectoras SOYAL

hola amigos del foro esty trantando de ejecutar una libreria hecha en C .dll pero usando lenguaje Dlphi quisiera su ayuda para poder ejucutar ajunto la ayuda total del software pero en est momento por me gustaria saber como hacer estas asignacion:
Código:
//			TxBfx[0] = 0xFF;		// Destination Node Address
//			TxBfx[1] = 0x12;		// Node information
//			TxBfx[2] = 0x02;		// Read Command
//			TxBfx[3] = 'R';	       // Parameters
//			nLen = 4;
la explicacion total de como usar la dll la adjunto ya que mi edea es simularla en delphi y apenas logre procesarla la opiare a este forum

Código:
////////////////////////////////////////////////////////////////////////////////////////
// Header file : SoyalComm.h
//
//         Copyright (c), Soyal Technology Co., LTD. TAIWAN
//		
//	SoyalComm.DLL :		Version 1.01	2004,JUL,08
//		SOYAL PROTOCOL multi port driver for WIN32
//
// All rights are reserved. Reproduction in whole or in part is prohibited
//      without the written consent of the copyright owner.
// Soyals reserves the right to make changes without notice at any time.
// Soyals makes no warranty, expressed, implied or statutory, including but
//		not limited to any implied warranty of merchantability or fitness for
//		any particular purpose.
// Soyals must not be liable for any loss or damage arising from its use.
//

////////////////////////////////////////////////////////////////////
// BOOL		IsPortAvailable( int CommPort )
// In :		Serial port number (0 ... n) for COM:1 ... COM:n+1
// Returns: If the port is available or not
//

////////////////////////////////////////////////////////////////////
// void*	CreateSPort( void )
//
// Returns: If create successfully return the pointer of Item object that 
//			represents the communication object that is created. otherwise return NULL
// Effect:	Use the method to create a objec for communication to a serial device 
//

////////////////////////////////////////////////////////////////////
// BOOL		DeleteSPort( void *pComm )
// Returns:	Nonzero if successful; otherwise zero
// Effect:	Delete the object created by CreateSPort()
//

////////////////////////////////////////////////////////////////////
// BOOL		OpenSComm( void *pComm, int Port )
// In :		Communication Object address, that create by CreateSPort
//			Serial port number		( Ex: 0 for port COM1, 1 for port COM2 )
// Returns: Nonzero if the opening was successful
// Effect:	Connect the communication object to serial port in 9600,N,8,1
//

////////////////////////////////////////////////////////////////////
// BOOL		CloseSComm( void *pComm )
// In :		Communication Object address, that create by CreateSPort
// Returns: Nonzero if the opening was successful
// Effect:	DisConnect the communication object with serial port
//

////////////////////////////////////////////////////////////////////
// BOOL		ReadWriteSComm( void *pComm, BYTE* TxBfx, BYTE* RxBfx, WORD* pLen )
// In :		Communication Object address, that create by CreateSPort
//			TxBfx:	Address of data block to transmit
//			RxBfx:	reserved memory block to receive data
//			SendLength: number of bytes to transmit
// Returns: Nonzero if all bytes transmited and put the received bytes in *pLen
// Effect:	Transmits *pLen bytes of data from TxBfx to the serial port, 
//			and receive the return data in RxBfx
//

////////////////////////////////////////////////////////////////////
// DWORD	GetSCommStatus( void *pComm )
// In :		Communication Object address, that create by CreateSPort
// Returns: Return unsigned long data of last ReadWriteSComm status
//

////////////////////////////////////////////////////////////////////
// BOOL		ConfigSComm( void *pComm, int baud )
// In :		Communication Object address, that create by CreateSPort
//			Serial port speed
// Returns: Nonzero if all bytes transmited and put the received bytes in *pLen
// Effect:	After OpenSComm the serial port parameters will be 9600,N,8,1
//			Use this function can change baud.

////////////////////////////////////////////////////////////////////
// BOOL		ConfigSCommParity( void *pComm, int baud, int Parity )
// In :		Communication Object address, that create by CreateSPort
//			Serial port speed
//			Parity: 0: Non Parity  1:Even Parity,  2:Odd Parity
// Returns: Nonzero if all bytes transmited and put the received bytes in *pLen
// Effect:	After OpenSComm the serial port parameters will be 9600,N,8,1
//			Use this function can change baud.

////////////////////////////////////////////////////////////////////////////
//	Usage:
//
//
//	#include	"SoyalComm.h"
//
// void  main()
// {
//	void*	pComm;
//	int		i;
//	WORD	nLen;
//	BYTE	TxBfx[256], RxBfx[256];
//	DWORD	deError;
//
//		//////////////////////////////////////////////////////
//		// Fine the available serial ports from COM1 ... COM6
//		for( i=0; i < 6; i++ ) {
//			if( IsPortAvailable( i ) ) {
//				// Do something like add to selection box
//			}
//		}
//
//		if( (pComm = CreateSPort()) == NULL ) {
//			printf( "Cann't create SoyalComm object !\n" );
//			return;
//		}
//
//		////////////////////////////////////////////////////////
//		// Connect the SoyalComm object to serial port (COM1)
//		if( OpenSComm( pComm, 0 ) {
//									// Command of Soyal AR737H1356:
//			TxBfx[0] = 0xFF;		// Destination Node Address
//			TxBfx[1] = 0x12;		// Node information
//			TxBfx[2] = 0x02;		// Read Command
//			TxBfx[3] = 'R';			// Parameters
//			nLen = 4;
									// Get AR721H Node(001) Event -> TxBfx[0] = 0x01, TxBfx[1] = 0x18, nLen = 2
//			if( ReadWriteSComm( pComm, TxBfx, RxBfx, &nLen ) ) {
//				///////////////////////////////////////////////////
//				// The Header code will be included in return data
//				// RxBfx: 7E 0C 01 ...
//				// Do something
//				//		...
//			} else {
//				dwError = GetSCommStatus( pComm );
//				if( dwError & COMM_RXTIMEOUT ) {
//					printf( "Timeout !\n" );
//				}
//				if( dwError & COMM_RXERRSUM ) {
//					printf( "Check Sum Error !\n" );
//				}
//				if( dwError & COMM_TXERRLENGTH ) {
//					printf( "Cann't send to serial port !\n" );
//				}
//			}
//			CloseSComm( pComm );
//		} else {
//			printf( "Cann't connect to serial port " );
//		}
//		DeleteSPort( pComm );
//		return;
//
// }
//

/////////////////////////////////////////////////////////////////////////////////////////
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the SOYALCOMM_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file  
// SOYALCOMM_API functions as being imported from a DLL, wheras this DLL sees symbols
// see defined with this macro as being exported.

#ifdef __cplusplus
extern "C" {
#endif	/* __cplusplus */

#ifdef SOYALCOMM_EXPORTS
#define SOYALCOMM_API __declspec(dllexport)
#else
#define SOYALCOMM_API __declspec(dllimport)
#endif

////////////////////////////////////////////////////////////////////
// Error Conditions and return values.
#define	COMM_TXOK			0x00000001
#define	COMM_RXOK			0x00000002
#define	COMM_TXERR			0x00000004
#define	COMM_RXERR			0x00000008
#define	COMM_RXTIMEOUT		0x00000010
#define	COMM_RXHEADER		0x00000020
#define	COMM_RXLENGTH		0x00000040
#define	COMM_RXERRSUM		0x00000080
#define	COMM_RXERRXOR		0x00000100
#define	COMM_TXERRLENGTH	0x00000200
#define COMM_FRAMEERROR		0x00000400
/////////////////////////////////////////////////////////////////////
// Function Prototypes
SOYALCOMM_API BOOL	IsPortAvailable( int CommPort );
SOYALCOMM_API void*	CreateSPort( void );
SOYALCOMM_API BOOL	DeleteSPort( void *pComm );
SOYALCOMM_API BOOL	ReadWriteSComm( void *pComm, BYTE* TxBfx, BYTE* RxBfx, WORD* pLen );
SOYALCOMM_API BOOL	OpenSComm( void *pComm, int Port );
SOYALCOMM_API BOOL	CloseSComm( void *pComm );
SOYALCOMM_API DWORD	GetSCommStatus( void *pComm );
SOYALCOMM_API BOOL	ConfigSComm( void *pComm, int baud );
SOYALCOMM_API BOOL	SetCommType( void *pComm, BOOL Soyal );

#ifdef	__cplusplus
}
#endif	/*	__cplusplus */
Responder Con Cita
  #2  
Antiguo 13-04-2010
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.210
Poder: 22
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
La primera parte que expones puede traducirse así:

Código Delphi [-]
var
  TxBfx: array[0..3] of CHAR;

begin
  TxBfx[0]:= #$FF;
  TxBfx[1]:= #$12;
  TxBfx[2]:= #$02;
  TxBfx[3]:= 'R';

Lo siguiente es el archivo cabecera para usar la dll. En C para exportar una función desde una dll:
Código:
__declspec(dllexport) BOOL IsPortAvailable(int CommPort );
eso en delphi sería:
Código Delphi [-]
function IsPortAvailable(CommPort: integer): boolean; cdecl; export;

Ahora bien, como tu solo quieres usar la dll deberías declarar así la función:
Código Delphi [-]
function IsPortAvailable(CommPort: integer): boolean; cdecl;

implementation

function IsPortAvailable; external dllname;

Espero que con esto puedas realizar tu traducción.

Saludos.
Responder Con Cita
  #3  
Antiguo 14-04-2010
ASAPLTDA ASAPLTDA is offline
Miembro
 
Registrado: jun 2003
Ubicación: COLOMBIA-CALI
Posts: 639
Poder: 23
ASAPLTDA Va por buen camino
Conversion a C a Delphi

MUCHAS GRACIAS VIEJO

Seguire el desarrollo, si tengo alguna pregunta adicional la agregare a este tema y se que me podras ayudar
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Leer datos lectora de tarjetas Soyal AR721H ASAPLTDA Varios 0 11-04-2010 18:22:36
instruccion MINUS Query de delphi jomanmoz SQL 2 26-03-2008 07:31:33
enviar instruccion de =SUM desde delphi 5 a excel mayte mtz Varios 2 06-12-2006 16:52:28
Instrucción dinamica para desactivar menu en Delphi Gustavo Restrep Varios 3 01-06-2006 20:42:11
AnyNET-Delphi Beta2: Una herramienta para convertir de .NET a Delphi.NET mamcx Noticias 3 01-10-2005 01:27:09


La franja horaria es GMT +2. Ahora son las 00:37:13.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi