How to incorporate c++ file in matlab

10 views (last 30 days)
martijn
martijn on 15 Dec 2011
<How can i insert a C++ file with a .h file in matlab? I have no experience in writing codes. I want to acces a .dll file from a programm to get data from. There's an example, where c++ builder is used to show the data. I need a main.cpp and the .h file to get data into the workspace. But how can I do this?

Answers (2)

martijn
martijn on 15 Dec 2011
Hi Friedrich,
First, thankyou for your answer. It's not a source code. The software use a .dll file which you can acces to get data. To do this, a .h file and a .cpp file is written to give an example of how you can acces data from the .dll file.
This is the .cpp file:
#include "sflib32.h"
DAC740* Dac740 = NULL; /****************************************************************************** DAC740 constructor will initialize this class for use. This routine will call the Windows function LoadLibrary to load the dll into memory, then all of the needed function address will be obtained via GetProcAddress. If an address is unobtainable, a message will be displayed, FreeLibrary will be called, and the module instance handle will be set to NULL. ****************************************************************************/ DAC740::DAC740(void) { register int i; LPVOID lpMsgBuf; char szWorkBuff[300]; typedef struct { void** pFunc; char* szFuncName; }PROC_TYPE;
// table of all functions to include
PROC_TYPE FuncTable[] =
{
// The following two should be at the top of this list, in case one of
// the others causes the initialization loop to exit. That way at least
// these two could be safely called.
{&(void*)InitDac740, "SFInitDac740"},
{&(void*)UnInitDac740, "SFUnInitDac740"},
{&(void*)GetDac740Version, "SFGetDac740Version"},
{&(void*)GetCommStatus, "SFGetCommStatus"},
{&(void*)SetCommStatus, "SFSetCommStatus"},
{&(void*)SetCommNodeName, "SFSetCommNodeName"},
{&(void*)SetSystemType, "SFSetSystemType"},
{&(void*)GetSystemType, "SFGetSystemType"},
{&(void*)SendFile, "SFSendFile"},
{&(void*)ReceiveFileToDisk, "SFReceiveFileToDisk"},
{&(void*)SaveMemoryToDDFFile, "SFSaveMemoryToDDFFile"},
{&(void*)EnumSystems, "SFEnumSystems"},
{&(void*)EnumKeyValues, "SFEnumKeyValues"},
{&(void*)SetSystem, "SFSetSystem"},
{&(void*)GetRegistryParam, "SFGetRegistryParam"},
{&(void*)SetRegistryParam, "SFSetRegistryParam"},
{&(void*)LoadConfig, "SFLoadConfig"},
{&(void*)GetConfigTag, "SFGetConfigTag"},
{&(void*)GetConfigFilename, "SFGetConfigFilename"},
{&(void*)PauseCurrentData, "SFPauseCurrentData"},
{&(void*)ResumeCurrentData, "SFResumeCurrentData"},
{&(void*)GetNumRemoteRecordedDataLines, "SFGetNumRemoteRecordedDataLines"},
{&(void*)LoadCurrentDataHeader, "SFLoadCurrentDataHeader"},
{&(void*)GetHeaderPointer, "SFGetHeaderPointer"},
{&(void*)GetCurrentDataFrame, "SFGetCurrentDataFrame"},
{&(void*)ReadComments, "SFReadComments"},
{&(void*)WriteComments, "SFWriteComments"},
{&(void*)BuildSFDFile, "SFBuildSFDFile"},
{&(void*)RefreshRecordedData, "SFRefreshRecordedData"},
{&(void*)GetCommentLine, "SFGetCommentLine"},
{&(void*)IsSystemInstalled, "SFIsSystemInstalled"},
{&(void*)IsChannelValid, "SFIsChannelValid"},
{&(void*)GetChannelName, "SFGetChannelName"},
{&(void*)GetChannelUnits, "SFGetChannelUnits"},
{&(void*)GetChannelFormat, "SFGetChannelFormat"},
{&(void*)GetChannelType, "SFGetChannelType"},
{&(void*)GetNumSFLIBLoadedDataLines, "SFGetNumSFLIBLoadedDataLines"},
{&(void*)WriteRelay, "SFWriteRelay"},
{&(void*)ReadInput, "SFReadInput"},
{&(void*)SendByteCommand, "SFSendByteCommand"},
{&(void*)GetCommandMaster, "SFGetCommandMaster"},
{&(void*)SetCommandMaster, "SFSetCommandMaster"},
{&(void*)SetSystemTime, "SFSetSystemTime"},
{&(void*)ChangeSetpoint, "SFChangeSetpoint"},
{&(void*)SetConstant, "SFSetConstant"},
{&(void*)ChangeControlModes, "SFChangeControlModes"},
{&(void*)IncrementSetpoint, "SFIncrementSetpoint"},
{&(void*)StartTestAtLine, "SFStartTestAtLine"},
{&(void*)AutozeroChannel, "SFAutozeroChannel"},
{&(void*)CalibrateChannel, "SFCalibrateChannel"},
{&(void*)SetMemoryChannel, "SFSetMemoryChannel"},
{&(void*)SetInterpolationEntry, "SFSetInterpolationEntry"},
{&(void*)RecordDataLine, "SFRecordDataLine"},
{&(void*)RecordCommentLine, "SFRecordCommentLine"},
{&(void*)DoSoftKeyFunction, "SFDoSoftKeyFunction"},
{&(void*)EraseRecordedData, "SFEraseRecordedData"},
{&(void*)EraseLastLine, "SFEraseLastLine"},
{&(void*)EndAutotest, "SFEndAutotest"},
{&(void*)ToggleControl, "SFToggleControl"},
{&(void*)LimitsOn, "SFLimitsOn"},
{&(void*)LimitsOff, "SFLimitsOff"},
{&(void*)LimitsReset, "SFLimitsReset"},
{&(void*)LockHandheld, "SFLockHandheld"},
{&(void*)UnlockHandheld, "SFUnlockHandheld"},
{&(void*)ResetSystem, "SFResetSystem"},
{&(void*)ValidateFile, "SFValidateFile"},
{&(void*)GetStatusFlag, "SFGetStatusFlag"},
{&(void*)SetStatusFlag, "SFSetStatusFlag"},
{&(void*)ClearStatusFlag, "SFClearStatusFlag"},
{&(void*)GetWinHandle, "SFGetWinHandle"},
{&(void*)GetProcessID, "SFGetProcessID"},
{&(void*)LaunchRegisteredApplication, "SFLaunchRegisteredApplication"},
{&(void*)SetWinHandle, "SFSetWinHandle"},
{&(void*)GetCommStatus, "SFGetCommStatus"},
{&(void*)StartAutotest, "SFStartAutotest"},
{&(void*)PauseAutotest, "SFPauseAutotest"},
{&(void*)ResumeAutotest, "SFResumeAutotest"},
{&(void*)PostmortemCapture, "SFPostmortemCapture"},
{&(void*)LogSystemMessage, "SFLogSystemMessage"},
{&(void*)LockSystemLog, "SFLockSystemLog"},
{&(void*)LoadStoredData, "SFLoadStoredData"},
{&(void*)LoadStoredDataFrame, "SFLoadStoredDataFrame"},
{&(void*)GetChannelValue, "SFGetChannelValue"},
{&(void*)SetCurrentDataScreen, "SFSetCurrentDataScreen"},
{&(void*)PlaybackInit, "SFPlaybackInit"},
{&(void*)PlaybackButton, "SFPlaybackButton"},
{&(void*)PlaybackExit, "SFPlaybackExit"},
{&(void*)PlaybackMode, "SFPlaybackMode"},
{&(void*)CalcHeaderSize, "SFCalcHeaderSize"},
{&(void*)ReadChannelOrder, "SFReadChannelOrder"},
{&(void*)WriteChannelOrder, "SFWriteChannelOrder"},
{&(void*)SetUserAccess, "SFSetUserAccess"},
{&(void*)HasUserAccess, "SFHasUserAccess"},
{&(void*)GetLoadedFileName, "SFGetLoadedFileName"},
{&(void*)GetNumLoadedCommentLines, "SFGetNumLoadedCommentLines"},
{&(void*)GetPBDraw, "SFGetPBDraw"},
{&(void*)ReadInternalData, "SFReadInternalData"},
{&(void*)WriteInternalData, "SFWriteInternalData"},
{&(void*)WriteSharedData, "SFWriteSharedData"},
{&(void*)GetChannelMax, "SFGetChannelMax"},
{&(void*)GetChannelMin, "SFGetChannelMin"},
{&(void*)GetControllerName, "SFGetControllerName"},
{&(void*)GetControlSystemType, "SFGetControlSystemType"},
{&(void*)GetControllerMode, "SFGetControllerMode"},
{&(void*)GetControllerCount, "SFGetControllerCount"},
};
// assume that the library will not be loaded
hDac740Dll = NULL;
// try to load the library
wsprintf(szWorkBuff, "%s.DLL", DLL_NAME);
hDac740Dll = LoadLibrary(szWorkBuff);
// if the library was loaded ok, try to get the function addresses
if(NULL == hDac740Dll)
{
wsprintf(szWorkBuff, "Error loading %s.DLL", DLL_NAME);
::OutputDebugString(szWorkBuff);
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL);
// Display the string. ::OutputDebugString((char*)lpMsgBuf);
// Free the buffer. LocalFree( lpMsgBuf ); } else { for(i=0; i<sizeof(FuncTable)/sizeof(FuncTable[0]); i++) { // request the adddress from Windows *FuncTable[i].pFunc = ::GetProcAddress(hDac740Dll, FuncTable[i].szFuncName);
// if we couldn't get it, tell the user
if(NULL == *FuncTable[i].pFunc)
{
wsprintf(szWorkBuff, "Error obtaining %s.DLL runtime address\r\n"
"for function %s", DLL_NAME, FuncTable[i].szFuncName);
::MessageBox(0, szWorkBuff, "Dll load error", MB_OK);
// unload the dll
FreeLibrary(hDac740Dll);
// flag the error
hDac740Dll = NULL;
// get out
break;
}
}
}
};
/****************************************************************************** GetDllInstance can be used by the caller to see if the dll was loaded up ok.
Returns: NULL -> dll load error !NULL -> dll loaded ok (returns instance of dll module) ****************************************************************************/ HINSTANCE DAC740::GetDllInstance(void) { return hDac740Dll; };
/****************************************************************************** ~DAC740 is the class destructor. It simply calls FreeLibrary to decrement the dll's use count. ****************************************************************************/ DAC740::~DAC740(void) { if(NULL != hDac740Dll) FreeLibrary(hDac740Dll); };
and the sflib32.h file that's included:
#ifndef DACLIB_H #define DACLIB_H
/****************************************************************************** DAC740.DLL run-time dynamic link interface module
This module can be used to interface with the DAC740.DLL using run-time linking. Usage: 1. Construct an object of the DAC740 class. 2. Call GetDllInstance to see if the dll was loaded up ok (!NULL means that it was loaded up ok, NULL => error). 3. Call InitDac740 to initialize the library 4. Use any functions as desired 5. Call UnInitDac740 before destroying the object 6. Delete the object. ****************************************************************************/
#define DLL_NAME "SFLIB32" #include stdio.h // for definition of FILE* #include "sflib.h" #include "regdef.h" // Contains the registry field definitions #include "SFC_NumericDefines.hpp"
// define exe id's #define COMLINK_WIN 1 #define WINDYN_WIN 2 #define STORED_WIN 3 #define DATALIB_WIN 4
//primary application window class names (registered to windows) #define WINDYN_WIN_CLASS_NAME "WindynWindow" #define STORED_WIN_CLASS_NAME "StoredWindow" #define COMLINK_WIN_CLASS_NAME "ComlinkWindow" #define DATALIB_WIN_APP_NAME "SuperFlow Test Database Manager"
//dll return values #define RETRY_COUNT 15 #define WCOMLINK_BUSY 2
// define comlink flag status #define COMLINK_NOT_TO_BE -2 // Indicates that Comlink is not to be loaded. #define COMLINK_NOT_LOADED -1 #define COMLINK_BUSY 1 // Any value >= COMLINK_UP indicates comlink "ready" #define COMLINK_UP 100 // Any value >= COMLINK_UP indicates comlink ready #define COMLINK_NOT_CONNECTED 100 // Comlink waiting for connection to a node #define COMLINK_CONNECTED 101 // Comlink connected.
// define valid channel id's #define USER_CHAN_START 1 #define USER_CHAN_END 139 #define MEASURED_CHAN_START 1 #define FREQ_CHAN_START 7 #define FREQ_CHAN_END 12 #define MEASURED_CHAN_END 76 #define CONST_CHAN_START 77 #define CONST_CHAN_END 99 #define CALC_CHAN_START 100 #define CALC_CHAN_END 129 #define INTERP_CHAN_START 130 #define INTERP_CHAN_END 139 // channels 140-199 reserved #define RSV_CHAN_START 140 #define RSV_CHAN_END 199 #define SYS_CHAN_START 200 #define SYS_CHAN_END 231
//#define NUMCHANNELS 139 //number of channels #define NUMCHANNELS (USER_CHAN_END - USER_CHAN_START + 1) #define MAX_DAC_CHANS (SYS_CHAN_END-SYS_CHAN_START+USER_CHAN_END-USER_CHAN_START+2) #define NUM_MEASURED_CHANS (MEASURED_CHAN_END - MEASURED_CHAN_START + 1) #define NUM_CONSTANT_CHANS (CONST_CHAN_END - CONST_CHAN_START + 1) #define NUM_INTERP_CHANS (INTERP_CHAN_END - INTERP_CHAN_START + 1)
//Digital I/O //The following definitions correspond to the //digital I/O implented in NGE hardware. This includes the system digital //I/O present on all NGE system CPU boards, and the NGE "Relay Net." //There are 24 additional system digital inputs and 24 additional system //digital outputs that are implemented in software only. #define DIG_CHAN_START 2000 #define SYS_DIG_IN_START DIG_CHAN_START #define SYS_DIG_IN_HW_END 2007 #define SYS_DIG_IN_SW_START 2008 #define SYS_DIG_IN_SW_END 2031 #define SYS_DIG_OUT_START 2032 #define SYS_DIG_OUT_HW_END 2039 #define SYS_DIG_OUT_SW_START 2040 #define SYS_DIG_OUT_SW_END 2063 #define RLY_DIG_IN_START 2064 #define RLY_DIG_IN_END 2127 #define RLY_RELAY_OUT_START 2128 #define RLY_RELAY_OUT_END 2159 #define DIG_CHAN_END RLY_RELAY_OUT_END #define NUM_DIGITAL_CHANS (SYS_DIG_IN_HW_END-SYS_DIG_IN_START+1) //system digital inputs (hardware only) #define NUM_RELAY_CHANS (RLY_DIG_IN_END-RLY_DIG_IN_START+1) //relay net digital inputs //--- #define NUM_SYS_DIG_IN NUM_DIGITAL_CHANS //for legacy code (hardware only) #define NUM_SYS_DIG_OUT (SYS_DIG_OUT_HW_END-SYS_DIG_OUT_START+1) //system digital outputs (hardware only) #define NUM_RLY_DIG_IN NUM_RELAY_CHANS //for legacy code #define NUM_RLY_RELAY_OUT (RLY_RELAY_OUT_END-RLY_RELAY_OUT_START+1) //relay net relay outputs #define NUM_DIGITAL_ALL (DIG_CHAN_END-DIG_CHAN_START+1)
//def channel name length #define DAC_CHAN_NAME_LEN 7 // including the null terminator byte
// define data types #define CURRENT_DATA 0 #define STORED_DATA 1 #define PLAYBACK_DATA 2 //#define WORKING_DATA 3
// define channel types #define VOLT_COEFF_CHAN 0 #define PRESSURE_CHAN 1 #define FREQ_CHAN 2 #define COUNT_CHAN 3 #define TC_CHAN 4 #define CONST_CHAN 5 #define CALC_CHAN 6 #define SYSTEM_CHAN 100 #define DIGITAL_CHAN 200
// Define the Playback buttons #define PB_NONE 0 // No button #define PB_PLAY 1 #define PB_STOP 2 #define PB_PAUSE 3 #define PB_FAST_FORWARD 4 #define PB_REVERSE 5 #define PB_REWIND 6
// Define the playback status #define PB_PLAYING 0 #define PB_PAUSED 1 #define PB_STOPPED 2
// Define the playback directions #define PB_FORWARD 0 #define PB_BACKWARD 1
// Define the playback modes #define PB_OFF 0 #define PB_SINGLE 1 #define PB_REPEAT 2
// Define the digital types #define DIG_RELAY 0 #define DIG_INPUT 1
// Control defines #define CONTROLLER_1 0 #define CONTROLLER_2 1 #define CONTROLLER_COUNT 2 #define CTRL_MODE_COUNT 5 #define CFA_CONFIG_OFFSET 10
// Control type defines #define CTRL_TYPE_NONE 0 #define CTRL_TYPE_1802 1 #define CTRL_TYPE_CHASSIS 2 #define CTRL_TYPE_TOWING 3 #define CTRL_TYPE_PID 4 #define CTRL_TYPE_SETPT 5 #define CTRL_TYPE_742 6 #define CTRL_TYPE_LOADBANK 7
#include "nge.h"
class DAC740 { private: // in DAC740.CPP HINSTANCE hDac740Dll; LONG (InitDac740)(HWND hWndApp, ULONG ulAppId, DWORD ProcID); LONG (*GetCommStatus)(void); void (*SetCommStatus)(LONG); void (*SetCommNodeName)(char *); LONG (*UnInitDac740)(HWND); void (*SetSystemType)(HWND ComlinkWnd, LONG); LONG (*GetSystemType)(void); char (GetDac740Version)(void); HWND (*GetWinHandle)(ULONG); DWORD (*GetProcessID)(ULONG); HWND (*LaunchRegisteredApplication)(ULONG, bool); void (*SetWinHandle)(HWND, ULONG); LONG (*SendFile)(UCHAR, char); LONG (ReceiveFileToDisk)(UCHAR, char); LONG (SaveMemoryToDDFFile)(char); bool (EnumSystems)(char*, DWORD*, DWORD*); bool (EnumKeyValues)(char *, char*, DWORD*, DWORD*, char**, DWORD*); bool (SetSystem)(char); bool (GetRegistryParam)(LONG, char, ULONG, char*); LONG (SetRegistryParam)(LONG, char, char*); LONG (LoadConfig)(char, LONG, LONG); ULONG (GetConfigTag)(UCHAR, LONG, LONG); char (GetConfigFilename)(LONG, LONG); LONG (*PauseCurrentData)(void); LONG (*ResumeCurrentData)(void); LONG (*SetCurrentDataScreen)(LONG, LONG); LONG (*GetNumRemoteRecordedDataLines)(LONG); LONG (*GetNumSFLIBLoadedDataLines)(void); LONG (*LoadCurrentDataHeader)(LONG); NGE_DATA_HEADER_FRAME (GetHeaderPointer)(LONG, LONG); UCHAR (GetCurrentDataFrame)(void); LONG (*WriteChannelOrder)(char, CHANNEL_ORDER*); LONG (ReadChannelOrder)(char, CHANNEL_ORDER*); LONG (ReadComments)(char, char*); LONG (WriteComments)(char, char*); LONG (BuildSFDFile)(char, char*, char , ULONG, char *); LONG (*ValidateFile)(ULONG, ULONG, char, char*, ULONG); LONG (LoadStoredData)(char, LONG); LONG (CalcHeaderSize)(LONG); LONG (*RefreshRecordedData)(void); LONG (*LoadStoredDataFrame)(LONG, LONG); char (GetCommentLine)(void); LONG (*GetNumLoadedCommentLines)(void); LONG (*WriteRelay)(LONG, LONG, LONG); LONG (*ReadInput)(LONG, LONG, LONG); LONG (*SendByteCommand)(UCHAR); bool (*GetCommandMaster)(void); void (*SetCommandMaster)(bool); LONG (*SetSystemTime)(LONG); LONG (*ChangeSetpoint)(float, float, LONG); LONG (*ChangeControlModes)(UCHAR, UCHAR, LONG); LONG (*IncrementSetpoint)(LONG, float, LONG); LONG (*StartTestAtLine)(ULONG, LONG); LONG (*AutozeroChannel)(USHORT, LONG); LONG (*SetConstant)(USHORT, float); LONG (*CalibrateChannel)(USHORT, float, LONG); LONG (*SetMemoryChannel)(USHORT, float, bool, LONG); LONG (*SetInterpolationEntry)(USHORT, UCHAR, float, float, LONG); LONG (*RecordDataLine)(LONG); LONG (*RecordCommentLine)(char, LONG); LONG (DoSoftKeyFunction)(char, LONG); LONG (*EraseRecordedData)(LONG); LONG (*EraseLastLine)(LONG); LONG (*EndAutotest)(LONG); LONG (*StartAutotest)(LONG); LONG (*PauseAutotest)(LONG); LONG (*ResumeAutotest)(LONG); LONG (*PostmortemCapture)(LONG); bool (*LogSystemMessage)(const char *, USHORT, const char *, const char *); bool (*LockSystemLog)(bool); LONG (*ToggleControl)(LONG); LONG (*LimitsOn)(LONG); LONG (*LimitsOff)(LONG); LONG (*LimitsReset)(LONG); LONG (*LockHandheld)(LONG); LONG (*UnlockHandheld)(LONG); LONG (*ResetSystem)(void); char (*GetStatusFlag)(ULONG); char (*ClearStatusFlag)(ULONG); char (*SetStatusFlag)(ULONG); void (*SetUserAccess)(ULONG ulUserAccess); bool (*HasUserAccess)(ULONG ulFeature); LONG (*GetLoadedFileName)(UCHAR, char, LONG*); LONG (ReadInternalData)(LONG, void, ULONG); LONG (WriteInternalData)(void, ULONG); void (WriteSharedData)(LONG, void, ULONG); char* (*GetControllerName)(USHORT, LONG, LONG); char (*GetControlSystemType)(LONG, LONG); short (*GetControllerMode)(USHORT, USHORT, LONG, LONG); char (*GetControllerCount)(LONG, LONG); bool (*IsSystemInstalled)(const char *pName);
// from COMPUTE.CPP
LONG (*IsChannelValid)(USHORT usChannel, LONG data_flag);
char* (*GetChannelName)(USHORT usChannel, LONG data_flag);
char* (*GetChannelUnits)(USHORT usChannel, LONG data_flag);
UCHAR (*GetChannelFormat)(USHORT usChannel, LONG data_flag);
float (*GetChannelValue)(LONG, USHORT usChannel);
char (*GetChannelType)(USHORT usChannel, LONG data_flag);
float (*GetChannelMax)(USHORT usChannel, LONG);
float (*GetChannelMin)(USHORT usChannel, LONG);
// from PLAYBACK.CPP
LONG (*PlaybackInit)(char*);
LONG (*PlaybackButton)(SHORT);
LONG (*PlaybackExit)(void);
void (*PlaybackMode)(SHORT);
bool (*GetPBDraw)(void);
public: DAC740(void); HINSTANCE GetDllInstance(void); ~DAC740(void);
inline char* SFGetDac740Version(void) { return GetDac740Version(); };
inline LONG SFGetCommStatus(void) { return GetCommStatus(); };
inline void SFSetCommStatus(int status) { SetCommStatus(status); };
inline void SFSetCommNodeName(char *pNodeName) { SetCommNodeName(pNodeName); };
inline LONG SFSendFile(UCHAR file_type, char* filespec) { return SendFile(file_type, filespec); };
inline LONG SFReceiveFileToDisk(UCHAR file_type, char* filespec) { return ReceiveFileToDisk(file_type, filespec); };
inline LONG SFSaveMemoryToDDFFile(char* filespec) { return SaveMemoryToDDFFile(filespec); };
inline bool SFEnumSystems(char** szSystem, DWORD* numSys, DWORD* maxLen) { return EnumSystems(szSystem, numSys, maxLen); };
inline bool SFEnumKeyValues(char szKey, char* szValues, DWORD* numVal, DWORD* maxValLen, char** szValData, DWORD* maxDataLen) { return EnumKeyValues(szKey, szValues, numVal, maxValLen, szValData, maxDataLen); };
inline bool SFSetSystem(char* szSysName) { return SetSystem(szSysName); };
inline bool SFGetRegistryParam(LONG lSysRegID, char* pszRegData, ULONG ulCount, char* pszSystem = 0) { return GetRegistryParam(lSysRegID, pszRegData, ulCount, pszSystem); };
inline LONG SFSetRegistryParam(LONG lSysRegID, char* pszRegData, char* pszSystem = 0) { return SetRegistryParam(lSysRegID, pszRegData, pszSystem); };
inline LONG SFLoadConfig(char* filespec, int data_flag = 0, LONG lSystem = 0) { return LoadConfig(filespec, data_flag, lSystem); };
inline ULONG SFGetConfigTag(UCHAR ucFileType = 0, LONG lDataFlag = 0, LONG lSystem = 0) { return GetConfigTag(ucFileType, lDataFlag, lSystem); };
inline char* SFGetConfigFilename(int data_flag = 0, LONG lSystem = 0) { return GetConfigFilename(data_flag, lSystem); };
inline LONG SFPauseCurrentData(void) { return PauseCurrentData(); };
inline LONG SFResumeCurrentData(void) { return ResumeCurrentData(); };
inline LONG SFGetNumRemoteRecordedDataLines(LONG lSystem = 0) { return GetNumRemoteRecordedDataLines(lSystem); };
inline LONG SFLoadCurrentDataHeader(LONG lSystem = 0) { return LoadCurrentDataHeader(lSystem); };
inline NGE_DATA_HEADER_FRAME* SFGetHeaderPointer(LONG lHeaderFlag, LONG lSystem = 0) { return GetHeaderPointer(lHeaderFlag, lSystem); };
inline UCHAR* SFGetCurrentDataFrame(void) { return GetCurrentDataFrame(); };
inline LONG SFReadComments(char* filespec, char* comments_ptr) { return ReadComments(filespec, comments_ptr); };
inline LONG SFWriteComments(char* filespec, char* comments_ptr) { return WriteComments(filespec, comments_ptr); };
inline LONG SFBuildSFDFile(char* dest_filespec, char* source_filespec, char* cfa_filespec, ULONG ulAddToDatabaseFlag, char *pCommentFile = 0) { return BuildSFDFile(dest_filespec, source_filespec, cfa_filespec, ulAddToDatabaseFlag, pCommentFile); };
inline LONG SFRefreshRecordedData(void) { return RefreshRecordedData(); };
inline char* SFGetCommentLine(void) { return GetCommentLine(); };
inline bool SFIsSystemInstalled(const char *pName) { return IsSystemInstalled(pName); };
inline LONG SFIsChannelValid(USHORT usChannel, int data_flag = 0) { return IsChannelValid(usChannel, data_flag); };
inline char* SFGetChannelName(USHORT usChannel, int data_flag = 0) { return GetChannelName(usChannel, data_flag); };
inline char* SFGetChannelUnits(USHORT usChannel, int data_flag = 0) { return GetChannelUnits(usChannel, data_flag); };
inline UCHAR SFGetChannelFormat(USHORT usChannel, int data_flag = 0) { return GetChannelFormat(usChannel, data_flag); };
inline char SFGetChannelType(USHORT usChannel, int data_flag = 0) { return GetChannelType(usChannel, data_flag); };
inline LONG SFGetNumSFLIBLoadedDataLines(void) { return GetNumSFLIBLoadedDataLines(); };
inline LONG SFWriteRelay(LONG lRelayNum, LONG lSetting, LONG lSystem = 0) { return WriteRelay(lRelayNum, lSetting, lSystem); };
inline LONG SFReadInput(LONG lInputNum, LONG lType, LONG lSystem = 0) { return ReadInput(lInputNum, lType, lSystem); };
inline LONG SFSendByteCommand(UCHAR command) { return SendByteCommand(command); };
inline bool SFGetCommandMaster(void) { return GetCommandMaster(); };
inline void SFSetCommandMaster(bool bFlag) { SetCommandMaster(bFlag); };
inline LONG SFSetSystemTime(LONG lSystem = 0) { return SetSystemTime(lSystem); };
inline LONG SFChangeSetpoint(float setpoint1, float setpoint2, LONG lSystem = 0) { return ChangeSetpoint(setpoint1, setpoint2, lSystem); };
inline LONG SFSetConstant(USHORT usChannel, float const_value) { return SetConstant(usChannel, const_value); };
inline LONG SFChangeControlModes(UCHAR mode1, UCHAR mode2, LONG lSystem = 0) { return ChangeControlModes(mode1, mode2, lSystem); };
inline LONG SFIncrementSetpoint(int set_num, float increment, LONG lSystem = 0) { return IncrementSetpoint(set_num, increment, lSystem); };
inline LONG SFStartTestAtLine(ULONG ulLineNum, LONG lSystem = 0) { return StartTestAtLine(ulLineNum, lSystem); };
inline LONG SFAutozeroChannel(USHORT usChannel, LONG lSystem = 0) { return AutozeroChannel(usChannel, lSystem); };
inline LONG SFCalibrateChannel(USHORT usChannel, float cal_value, LONG lSystem = 0) { return CalibrateChannel(usChannel, cal_value, lSystem); };
inline LONG SFSetMemoryChannel(USHORT usChannel, float mem_value, bool bTPF = false, LONG lSystem = 0) { return SetMemoryChannel(usChannel, mem_value, bTPF, lSystem); };
inline LONG SFSetInterpolationEntry(USHORT usChannel, UCHAR entry, float x, float f_of_x, LONG lSystem = 0) { return SetInterpolationEntry(usChannel, entry, x, f_of_x, lSystem); };
inline LONG SFRecordDataLine(LONG lSystem = 0) { return RecordDataLine(lSystem); };
inline LONG SFRecordCommentLine(char* comment_ptr, LONG lSystem = 0) { return RecordCommentLine(comment_ptr, lSystem); };
inline LONG SFDoSoftKeyFunction(char key, LONG lSystem = 0) { return DoSoftKeyFunction(key, lSystem); };
inline LONG SFEraseRecordedData(LONG lSystem = 0) { return EraseRecordedData(lSystem); };
inline LONG SFEraseLastLine(LONG lSystem = 0) { return EraseLastLine(lSystem); };
inline LONG SFEndAutotest(LONG lSystem = 0) { return EndAutotest(lSystem); };
inline LONG SFToggleControl(LONG lSystem = 0) { return ToggleControl(lSystem); };
inline LONG SFLimitsOn(LONG lSystem = 0) { return LimitsOn(lSystem); };
inline LONG SFLimitsOff(LONG lSystem = 0) { return LimitsOff(lSystem); };
inline LONG SFLimitsReset(LONG lSystem = 0) { return LimitsReset(lSystem); };
inline LONG SFLockHandheld(LONG lSystem = 0) { return LockHandheld(lSystem); };
inline LONG SFUnlockHandheld(LONG lSystem = 0) { return UnlockHandheld(lSystem); };
inline LONG SFResetSystem(void) { return ResetSystem(); };
inline LONG SFValidateFile(UINT SystemID, UINT FileType, char* filespec, char far* fileCFA, DWORD FileParams) { return ValidateFile(SystemID, FileType, filespec, fileCFA, FileParams); };
inline char SFGetStatusFlag(UINT id) { return GetStatusFlag(id); };
inline char SFSetStatusFlag(UINT id) { return SetStatusFlag(id); };
inline char SFClearStatusFlag(UINT id) { return ClearStatusFlag(id); };
inline void SFSetSystemType(HWND ComlinkWnd = NULL, LONG lType = 0) { SetSystemType(ComlinkWnd, lType); };
inline LONG SFGetSystemType(void) { return GetSystemType(); };
inline LONG SFInitDac740(HWND hWndApp = NULL, ULONG ulAppId = 0L, DWORD ProcID = 0)
{
return InitDac740(hWndApp, ulAppId, ProcID);
};
inline LONG SFUnInitDac740(HWND hWnd = NULL)
{
return UnInitDac740(hWnd);
};
inline HWND SFGetWinHandle(ULONG ulAppId) { return GetWinHandle(ulAppId); };
inline DWORD SFGetProcessID(ULONG ulAppId) { return GetProcessID(ulAppId); };
inline void SFSetWinHandle(HWND hWndApp, ULONG ulAppId) { SetWinHandle(hWndApp, ulAppId); };
inline HWND SFLaunchRegisteredApplication(ULONG ulAppId, bool bRestore = true)
{
return LaunchRegisteredApplication(ulAppId, bRestore);
};
inline LONG SFStartAutotest(LONG lSystem = 0)
{
return StartAutotest(lSystem);
};
inline LONG SFPauseAutotest(LONG lSystem = 0)
{
return PauseAutotest(lSystem);
};
inline LONG SFResumeAutotest(LONG lSystem = 0)
{
return ResumeAutotest(lSystem);
};
inline LONG SFPostmortemCapture(LONG lSystem = 0)
{
return PostmortemCapture(lSystem);
};
inline bool SFLogSystemMessage(const char *pMessage, USHORT usType, const char *pSource, const char *pTimeDate = 0)
{
return LogSystemMessage(pMessage, usType, pSource, pTimeDate);
};
inline bool SFLockSystemLog(bool bLock)
{
return LockSystemLog(bLock);
};
inline LONG SFLoadStoredData(char* filespec, int iPlaybackFlag = 0)
{
return LoadStoredData(filespec, iPlaybackFlag);
};
inline LONG SFLoadStoredDataFrame(int frame_number, LONG lSystem = 0) { return LoadStoredDataFrame(frame_number, lSystem); };
inline float SFGetChannelValue(int data_flag, USHORT usChannel) { return GetChannelValue(data_flag, usChannel); };
inline LONG SFSetCurrentDataScreen(LONG lScreenNum, LONG lSystem = 0)
{
return SetCurrentDataScreen(lScreenNum, lSystem);
};
inline LONG SFPlaybackInit(char* filespec) { return PlaybackInit(filespec); };
inline LONG SFPlaybackButton(SHORT sButton) { return PlaybackButton(sButton); };
inline LONG SFPlaybackExit(void) { return PlaybackExit(); };
inline void SFPlaybackMode(SHORT sMode) { PlaybackMode(sMode); };
inline LONG SFCalcHeaderSize(int sf74x_version)
{
return CalcHeaderSize(sf74x_version);
}
inline LONG SFWriteChannelOrder(char* filespec, CHANNEL_ORDER* pChOrder)
{
return WriteChannelOrder(filespec, pChOrder);
}
inline LONG SFReadChannelOrder(char* filespec, CHANNEL_ORDER* pChOrder)
{
return ReadChannelOrder(filespec, pChOrder);
}
inline void SFSetUserAccess(ULONG ulUserAccess) { SetUserAccess(ulUserAccess); };
inline bool SFHasUserAccess(ULONG ulFeature)
{
return HasUserAccess(ulFeature);
}
inline LONG SFGetLoadedFileName(UCHAR ucFileType, char* pszFilename, LONG* piCount)
{
return GetLoadedFileName(ucFileType, pszFilename, piCount);
}
inline LONG SFGetNumLoadedCommentLines(void)
{
return GetNumLoadedCommentLines();
};
inline bool SFGetPBDraw(void) { return GetPBDraw(); };
inline LONG SFReadInternalData(LONG lRequest, void* pvData, ULONG ulDataSize)
{
return ReadInternalData(lRequest, pvData, ulDataSize);
};
inline LONG SFWriteInternalData(void* pvData, ULONG ulDataSize)
{
return WriteInternalData(pvData, ulDataSize);
};
inline void SFWriteSharedData(LONG lRequest, void* pvData, ULONG ulDataSize)
{
WriteSharedData(lRequest, pvData, ulDataSize);
};
inline float SFGetChannelMax(USHORT usChannel, int data_flag = 0)
{
return GetChannelMax(usChannel, data_flag);
};
inline float SFGetChannelMin(USHORT usChannel, int data_flag = 0) { return GetChannelMin(usChannel, data_flag); };
inline char* SFGetControllerName(USHORT ctrl_num, int data_flag = 0, LONG lSystem = 0)
{
return GetControllerName(ctrl_num, data_flag, lSystem);
};
inline char SFGetControlSystemType(LONG data_flag = 0, LONG lSystem = 0)
{
return GetControlSystemType(data_flag, lSystem);
};
inline short SFGetControllerMode(USHORT ctrl_mode, USHORT ctrl_num, LONG data_flag = 0, LONG lSystem = 0)
{
return GetControllerMode(ctrl_mode, ctrl_num, data_flag, lSystem);
};
inline char SFGetControllerCount(LONG data_flag = 0, LONG lSystem = 0)
{
return GetControllerCount(data_flag, lSystem);
};
};
extern DAC740* Dac740; #endif //(DACLIB_H)
I think i need to say in the .cpp file to get the data and to write it to the workspace so that i can use it in matlab. Any idea how to do this?
  1 Comment
Friedrich
Friedrich on 16 Dec 2011
Hi,
try to use the loadlibrary command in MATLAB to load the DLL into MATLAB:
http://www.mathworks.com/help/releases/R2011b/techdoc/ref/loadlibrary.html
If this shouldn't work, write a mex file in which you call the DLL like in the example given above.

Sign in to comment.


martijn
martijn on 19 Dec 2011
I tried to use the loadlibrary command using:
loadlibrary('sflib32.dll','sflib32.h','addheader','regdef.h','addheader','nge.h','addheader','SFC_Numericdefines.hpp') The header files are included in the sflib32.h file as #include.
But i get the following errors:
Warning: Message from C preprocessor: lcc preprocessor error: C:\WINDOWS\sflib.h:8 C:\WINDOWS\sflib32.h:20 Syntax error in #ifdef/#ifndef lcc preprocessor warning: C:\WINDOWS\SFC_NumericDefines.hpp:44 C:\WINDOWS\sflib32.h:22 No newline at end of file
> In loadlibrary at 371 Warning: Warnings messages were produced while parsing. Check the functions you intend to use for correctness. Warning text can be viewed using: [notfound,warnings]=loadlibrary(...) > In loadlibrary at 396 Warning: The data type 'error' used by structure DEF_TYPE1 does not exist. The structure may not be usable. > In loadlibrary at 458 Warning: The data type 'PTR_TYPE#139' used by structure NGE_CFA_TYPE does not exist. The structure may not be usable. > In loadlibrary at 458 Warning: The data type 'error' used by structure CALIBRATION does not exist. The structure may not be usable. > In loadlibrary at 458 Warning: The data type 'error#21' used by structure VAR_INT_TYPE does not exist. The structure may not be usable. > In loadlibrary at 458 Warning: The data type 'CALIBRATION#76' used by structure NGE_DATA_HEADER_FRAME does not exist. The structure may not be usable. > In loadlibrary at 458 Warning: The data type 'error#10' used by structure NGE_DATA_HEADER_FRAME does not exist. The structure may not be usable. > In loadlibrary at 458 Warning: The data type 'EC_CHAN_TYPE#23' used by structure NGE_DATA_HEADER_FRAME does not exist. The structure may not be usable. > In loadlibrary at 458 Warning: The data type 'DEV_DATA_TYPE#5' used by structure NGE_DATA_REC_TYPE does not exist. The structure may not be usable. > In loadlibrary at 458 Warning: The data type 'TNodeItem#20' used by structure TNodeInfo does not exist. The structure may not be usable. > In loadlibrary at 458 Warning: The function 'SFC_ulSuiteID_WinDyn' was not found in the library > In loadlibrary at 458 Warning: The function 'SFC_ulAppID_MDITemplate' was not found in the library > In loadlibrary at 458 Warning: The function 'SFC_ulAppID_EditLimits' was not found in the library > In loadlibrary at 458 Warning: The function 'SFC_ulAppID_EditPaths' was not found in the library > In loadlibrary at 458 Warning: The function 'SFC_ulAppID_EditLog' was not found in the library > In loadlibrary at 458 Warning: The function 'SFC_ulMaskLSBYTE' was not found in the library > In loadlibrary at 458 Warning: The function 'SFC_ulMemChanCount' was not found in the library > In loadlibrary at 458 Warning: The function 'SFC_ulSysChanTsTime' was not found in the library > In loadlibrary at 458 Warning: The function 'Dac740' was not found in the library

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by