[Mono-devel-list] Using thirdparty lib with mono and linux

Ulrich Meinicke ulrich.meinicke at tepcon.de
Thu Dec 23 10:53:46 EST 2004


Hi!

I developed a software with mono under Windows XP. It connects to
RFID-reader via Ethernet. Therefore I use a third-party library from the
reader manufacturer. 
Compiling and running with mono just works fine. Also with the .Net
Runtime. But it should also run under linux, but it doesn't.

This is a sample of the code:

using System;
using System.Net;

using ILRnet;
 class PortReader {
  
	static CiPort3Net  m_refReader = null;
		
	public static void Main() {

	    if ( m_refReader != null ){
	      m_refReader.Disconnect();
	    }
	   	m_refReader = new CiPort3Net();
	
	   	
	   	if (m_refReader.ConnectEthernet("192.168.1.44", 7070)){
	
	   	  m_refReader.SetActiveAntenna(1);

	   	  Console.WriteLine("Found Reader");
	   	}else{
	   	  	Console.WriteLine("Connection to reader failed.
Exit.");	 	  
	   	}  
  }
}

I compile it with: mcs -r:ILRNet.dll file.cs

When I start the program with "mono file.exe" the files ILRNet.dll and
ILR_SDK_DLL.dll must be in the same directory. It's a dll from the
reader manufacturer. My understanding is, that the ILRNet.dll is the
.Net Assembly and this dll calls functions from the ILR_SDK_DLL.dll
library. So the .Net assembly is just a wrapper. 

The reader manufacturer provides a library for linux. I tried to map the
ILR_SDK_DLL.dll  in the config file:
<configuration>
        <dllmap dll="cygwin1.dll" target="libc.so.6" />
        <dllmap dll="libc" target="libc.so.6" />
        <dllmap dll="libintl" target="libc.so.6" />
        <dllmap dll="libxslt.dll" target="libxslt.so" />
        <dllmap dll="libmySQL.dll" target="libmysqlclient.so" />
        <dllmap dll="odbc32.dll" target="libodbc.so" />
        <dllmap dll="oci" target="clntsh" />
        <dllmap dll="db2cli" target="libdb2_36.so"/>
        <dllmap dll="ILR_SDK_DLL.DLL"
target="libILR_sdk-i386-gcc3-0.4.3.so"
/>
</configuration>


As said before compiling this code with mono under linux is just fine. (
I use mono 1.0.4). But during runtime I get the following error:

Unhandled Exception: System.EntryPointNotFoundException: CreateiPort3Obj
in <0x00053> (wrapper managed-to-native)
ILRnet.CiPort3Net:CreateiPort3Obj()
in <0x0001c> ILRnet.CiPort3Net:.ctor ()
in <0x00047> PortReader:Main ()

Is there anything else I could do that the C (or C++) function and
classes of the reader manufacturer are used. I think the function and
class names are different in the .Net dll and the C++ dll.
But where's the mapping?

I appended the relevant include file from the linux c++ library which
the manufactuerer povides. Any further hints/information would be
helpful.

Thanks a lot!

Ulrich


iPortIII.h:

// iPortIII.h: interface for the CiPortIII class.
//
//////////////////////////////////////////////////////////////////////

#if
!defined(AFX_IPORTIII_H__7D35B2D2_B8CB_42E3_AE2F_B3A80EDC1715__INCLUDED_
)
#define AFX_IPORTIII_H__7D35B2D2_B8CB_42E3_AE2F_B3A80EDC1715__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "base_ip3.h"
#include "iTemperatureLog.h"

// socket include for windows
#ifdef WIN32
  #include <winsock.h>
  // link with
  #ifdef _WIN32_WCE
    #pragma comment( lib, "winsock" )
  #else
    // tell the compiler to include socket library
    #pragma comment( lib, "Ws2_32" )
  #endif
#endif


#ifdef ILR_SDK_DLL_EXPORTS
#define ILR_SDK_API __declspec(dllexport) #else #ifdef
ILR_SDK_DLL_IMPORTS #define ILR_SDK_API __declspec(dllimport) #else
#define ILR_SDK_API #endif #endif

/// A class to encapsulate the IPort III functionality via a remote
connection class ILR_SDK_API CiPortIII : public CBase_iPortIII { friend
class CiQTag;
public:
	bool Connect(char *szIPAddress, const short sPortNumber);
	virtual bool Disconnect(void);
	CiPortIII();
	virtual ~CiPortIII();
	virtual bool GetInformation(char *szInformation, WORD
wBufferLength);


	//! \todo Implement me
	virtual bool SetRelays(bool bRelay1, bool bRelay2, bool bRelay3,
bool bRelay4);


private:

	virtual bool ReadTemperatureLog(CiQTag *piQTag, CiTemperatureLog
&iTLog, int nRetries);
	virtual bool StopTemperatureLog(CiQTag *piQTag, int nRetries);
	virtual bool StartTemperatureLog(CiQTag *piQTag, WORD
wIntervalSeconds,int nRetries);
	virtual bool WriteRAM(CBaseTag *pTag, WORD wStartAddress, BYTE
*pbyData, WORD wBytesToWrite, int &iBytesWritten, int retries =
USE_DEFAULT_RETRIES);
	virtual bool ReadRAM(CBaseTag *pTag, WORD wStartAddress, BYTE
*pbyData, WORD wBytesToRead, int &iBytesRead, int retries =
USE_DEFAULT_RETRIES);

/*!\internal
*/
	virtual bool SessionSetup(CBaseTag* pTag, BYTE byMode, int
retries = -1);
	virtual bool SleepTag(CBaseTag* pTag, BYTE bySeconds, int
retries = -1);
	virtual bool ReadEEPROM(CBaseTag *pTag, WORD wStartAddress, BYTE
*pbyData, WORD wBytesToRead, int &iBytesRead, int retries = -1);
	virtual bool WriteEEPROM(CBaseTag *pTag, WORD wStartAddress,
BYTE *pbyData, WORD wBytesToWrite, int &iBytesWritten, int retries =
-1);


private:
	virtual int IPORTWriteConfKey(const char* szKey, int value);
	int  IPORTWriteConfKey(const char* szKey, const char* szValue);
	bool ILRScan(CTagArray &tagArray);
	virtual bool ScanForiDTags(CTagArray &tagArray, WORD
wTagsExpected, BYTE byMaxRollcall, BYTE byMode, int nScanType);
	virtual bool ScanForiQTags(CTagArray &tagArray, WORD
wTagsExpected, BYTE byMaxRollcall, BYTE byMode, int nScanType);
	bool ParseBLINKResponse(CBaseTag* pTag);
	bool ParseWriteEEPROMResponse(CBaseTag *pTag, BYTE *pbyData, int
&iBytesWritten);
	bool ParseReadEEPROMResponse(CBaseTag* pTag, BYTE *pbyData, int
&iBytesRead);
	bool ParseScanResponse(CTagArray &tagArray);
	bool ReceiveResponse(char* szRequestCode, unsigned int
nTimeout);
	bool ParseReadLogResponse(CiQTag *piQTag, CiTemperatureLog
&iTLog);

	void ParseFieldStrengthFromBuffer(CBaseTag* pTag, char*
pBuffer);
	void ParseBatteryStatusFromBuffer(CBaseTag *pTag, char
*pBuffer);
	void ParseVersionFromBuffer(CBaseTag *pTag, char *pBuffer);
	void ParseTemperatureFromBuffer(CBaseTag *pTag, char *pBuffer);

	bool SendCommand(BYTE *pbyBuf, int nBufLen);
	bool IsFullMessageReceived(const int nCurrentLength);
	bool CalculateCRC(BYTE *pbyBuffer, const unsigned int
nBufferLength, char *szResult);

	void SetTime_t(time_t &lTime, int wSecond, int wMinute, int
wHour, int wDay, int wMonth, int wYear);

	SOCKET m_socket;
	SOCKADDR_IN m_sa;
	char m_cBuffer[1024*8];

};

#endif //
!defined(AFX_IPORTIII_H__7D35B2D2_B8CB_42E3_AE2F_B3A80EDC1715__INCLUDED_
)





More information about the Mono-devel-list mailing list