Update of /cvsroot/opengtoolkit/serial/c_source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26715/c_source Added Files: lv_error.cpp lv_error.h lvserial.cpp lvserial.def lvserial.h lvserialrc.h plist.cpp plist.h Log Message: initial commit --- NEW FILE: plist.cpp --- /* plist.cpp * * Simple pList Implementation * * Martin Henz Systemtechnik, Stuttgart * */ #include <stdlib.h> #include "plist.h" #pragma pack(1) __inline PLIST InitializeList(PLIST pList); __inline PLINK GetPrevLink(PLINK pLink); __inline PLINK GetNextLink(PLINK pLink); __inline PLINK GetHeadOfList(PLIST pList); __inline PLINK GetTailOfList(PLIST pList); __inline void * GetElementPtr(PLINK pLink); __inline void SetElementPtr(PLINK pLink, void *pElement); __inline unsigned long GetListLength(PLIST pList); __inline PLINK AddToList(PLIST pList, PLINK pDstLink, PLINK pSrcLink); __inline PLINK AddToFrontOfList(PLIST pList, PLINK pLink); __inline PLINK AddToEndOfList(PLIST pList, PLINK pLink); __inline void AddLinkToLink(PLINK pDstLink, PLINK pSrcLink); __inline PLINK DeleteFromList(PLIST pList, PLINK pLink); __inline PLINK DeleteFromFrontOfList(PLIST pList); __inline PLINK DeleteFromEndOfList(PLIST pList); /* InitializeList * * Initializes a list * * parameter * pList list pointer * * return * list pointer */ __inline PLIST InitializeList(PLIST pList) { pList->pHead = (PLINK) 0L; pList->pTail = (PLINK) 0L; pList->ulLength = 0; return pList; } /* GetPrevLink * * Gets the previous link * * parameter * pLink link pointer * * return * the previous link */ __inline PLINK GetPrevLink(PLINK pLink) { return pLink->pPrev; } /* GetNextLink * * Gets the next link * * parameter * pLink link pointer * * return * the next link */ __inline PLINK GetNextLink(PLINK pLink) { return pLink->pNext; } /* GetHeadOfList * * Gets the head of the list * * parameter * pList list pointer * * return * the list head link */ __inline PLINK GetHeadOfList(PLIST pList) { return pList->pHead; } /* GetTailOfList * * Gets the tail of the list * * parameter * pList list pointer * * return * the list tail link */ __inline PLINK GetTailOfList(PLIST pList) { return pList->pTail; } /* GetElementPtr * * Gets the element data pointer * * parameter * pLink link * * return * element data pointer */ __inline void * GetElementPtr(PLINK pLink) { return pLink->pElement; } /* SetElementPtr * * Sets the element data pointer * * parameter * pLink link * pElement element data pointer */ __inline void SetElementPtr(PLINK pLink, void *pElement) { pLink->pElement = pElement; } /* GetListLength * * Gets the length of the list * * parameter * pLink link * * return * element data pointer */ __inline unsigned long GetListLength(PLIST pList) { return pList->ulLength; } /* AddLinkToLink * * Links two links together * * parameter * pDstLink destination link * pSrcLink source link */ __inline void AddLinkToLink(PLINK pDstLink, PLINK pSrcLink) { //Make the source link point at the destination link. pSrcLink->pPrev = pDstLink; pSrcLink->pNext = pDstLink->pNext; // Make the destination link point at the source link. pDstLink->pNext->pPrev = pSrcLink; pDstLink->pNext = pSrcLink; } /* AddToList * * Adds a link to the list. If the source link is NULL, the functions appends * the destination link at the end of the list. If the destination link is * NULL, the source link will be appended at the front of the list. If neither * source and destination link is NULL, it links them together. * * parameter * pList list pointer * DstLink destination link * SrcLink source link * * return * the added link pointer */ __inline PLINK AddToList(PLIST pList, PLINK pDstLink, PLINK pSrcLink) { //Grow the list length by one. pList->ulLength++; //If SrcLink is NULL then add DstLink to the end of the list. if ( pSrcLink == (PLINK) 0L ) { //If the tail pointer is NULL then the list is empty. if ( pList->pTail != (PLINK) 0L ) { AddLinkToLink(pList->pTail, pDstLink); } else { pDstLink->pPrev = pDstLink; pDstLink->pNext = pDstLink; pList->pHead = pDstLink; } return (pList->pTail = pDstLink); } //If DstLink is NULL then add SrcLink to the front of the list. if ( pDstLink == (PLINK) 0L ) { //If the head pointer is NULL then the list is empty. if ( pList->pHead != (PLINK) 0L ) { AddLinkToLink(pList->pHead, pSrcLink); } else { pSrcLink->pPrev = pSrcLink; pSrcLink->pNext = pSrcLink; pList->pTail = pSrcLink; } return (pList->pHead = pSrcLink); } //Neither pDstLink nor SrcLink is NULL so link them together. AddLinkToLink(pDstLink, pSrcLink); return pSrcLink; } /* DeleteFromList * * Deletes a link from the list * * parameter * pList list pointer * pLink link pointer * * return * the deleted link pointer */ __inline PLINK DeleteFromList(PLIST pList, PLINK pLink) { //If the list is empty then return NULL. if ( pList->ulLength != 0 ) { /* If the list length is not zero then we may need to fixup head and * tail pointers in the event we delete the first or last link, * respectively. */ if ( --pList->ulLength != 0 ) { // If we are deleting the front link then fixup the head pointer. if ( pList->pHead == pLink ) { pList->pHead = pList->pHead->pNext; } //If we are deleting the end link then fixup the tail pointer. if ( pList->pTail == pLink ) { pList->pTail = pList->pTail->pPrev; } // Now we can unlink this link from the list. pLink->pNext->pPrev = pLink->pPrev; pLink->pPrev->pNext = pLink->pNext; } else { // There is only one link on the list and we just deleted it. pList->pHead = (PLINK) 0L; pList->pTail = (PLINK) 0L; } return pLink; } return (PLINK) 0L; } /* AddToFrontOfList * * Adds a link at the front of the list * * parameter * pList list pointer * pLink link pointer * * return * the added link pointer */ __inline PLINK AddToFrontOfList(PLIST pList, PLINK pLink) { return AddToList(pList, (PLINK) 0L, pLink); } /* AddToEndOfList * * Adds a link at the end of the list * * parameter * pList list pointer * pLink link pointer * * return * the added link pointer */ __inline PLINK AddToEndOfList(PLIST pList, PLINK pLink) { return AddToList(pList, pLink, (PLINK) 0L); } /* DeleteFromFrontOfList * * Deletes a link from the front of the list * * parameter * pList list pointer * pLink link pointer * * return * the deleted link pointer */ __inline PLINK DeleteFromFrontOfList(PLIST pList) { return DeleteFromList(pList, GetHeadOfList(pList)); } /* DeleteFromEndOfList * * Deletes a link from the end of the list * * parameter * pList list pointer * pLink link pointer * * return * the deleted link pointer */ __inline PLINK DeleteFromEndOfList(PLIST pList) { return DeleteFromList(pList, GetTailOfList(pList)); } #pragma pack() /* ListCreate * * The function allocates the memory needed for a new list and initialises * the list as an empty list. * * parameter * * return * pointer to list */ PLIST ListCreate(void) { PLIST pList; if ( (pList = (PLIST)malloc(sizeof(LIST))) == NULL) return NULL; InitializeList(pList); return pList; } /* ListDispose * * Releases the momory allocated for the list * * parameter * pList list pointer * * return * 0 if no error or 1 if the pList argument is not valid */ int ListDispose(PLIST pList) { if (pList == NULL) return 1; InitializeList(pList); free(pList); return 0; } /* ListAppendElement * * Appends a new element at the end of the list. * * parameter * pList list pointer * pElement element data pointer * * return * element handle */ void * ListAppendElement(PLIST pList, void *pElement) { PLINK pLink; if (pList == NULL) return NULL; if ( (pLink = (PLINK)malloc(sizeof(LINK))) == NULL) return NULL; pLink->pElement = pElement; AddToEndOfList(pList, pLink); //return the element handle return pLink; } /* ListRemoveHandle * * Removes an element from the list * * parameter * pList list pointer * hElement element handle * * return * the removed elements data pointer * */ void * ListRemoveHandle(PLIST pList, void *hElement) { void *pElement; if (pList == NULL || hElement == NULL) return NULL; if (DeleteFromList(pList, (PLINK)hElement) == NULL) return NULL; pElement = ((PLINK)hElement)->pElement; ((PLINK)hElement)->pNext = NULL; ((PLINK)hElement)->pPrev = NULL; ((PLINK)hElement)->pElement = NULL; free(hElement); return pElement; } /* ListRemoveFirstElement * * Removes the first element of the list * * parameter * pList list pointer * * return * the removed element data pointer */ void * ListRemoveFirstElement(PLIST pList) { PLINK pLink; void *pElement; if (pList == NULL) return NULL; pLink = DeleteFromFrontOfList(pList); if (pLink != NULL) { pElement = pLink->pElement; pLink->pNext = NULL; pLink->pPrev = NULL; pLink->pElement = NULL; free(pLink); return pElement; } return NULL; } /* ListRemoveLastElement * * Removes the last element from the list * * parameter * pList list pointer * * return * the removes element data pointer */ void * ListRemoveLastElement(PLIST pList) { PLINK pLink; void *pElement; if (pList == NULL) return NULL; pLink = DeleteFromEndOfList(pList); if (pLink != NULL) { pElement = pLink->pElement; pLink->pNext = NULL; pLink->pPrev = NULL; pLink->pElement = NULL; free(pLink); return pElement; } return NULL; } /* ListGetElement * * Returns the elements data pointer referenced by the element handle * * parameter * pList list pointer * hElement element handle * * return * the elements data pointer */ void * ListGetElement(PLIST pList, void *hElement) { if (pList == NULL || hElement == NULL) return NULL; return ((PLINK)hElement)->pElement; } /* ListGetLength * * Retrieves the length of the list (number of elements in the list) * * parameter * pList list pointer * * return * ulLength of the list */ int ListGetLength(PLIST pList) { if (pList == NULL) return -1; return GetListLength(pList); } /* ListCheckHandle * * Checks an element handle * * parameter * pList list pointer * hElement element handle * * return * 0, if the handle is valid * 1, if the handle is not a valid element handle * in case of an error, the function returns a negative number */ int ListCheckHandle(PLIST pList, void *hElement) { PLINK pLink; unsigned long i; if (pList == NULL) return -1; for ( i = 0, pLink = GetHeadOfList(pList); i < GetListLength(pList); i++, pLink = GetNextLink(pLink)) { if (pLink == hElement) return 0; } return 1; } /* ListCheckElement * * Checks an element data pointer * * parameter * pList list pointer * pElement element data pointer * * return * 0, if the pointer is valid * 1, if the pointer is not a valid element handle * in case of an error, the function returns a negative number */ int ListCheckElement(PLIST pList, void *pElement) { PLINK pLink; unsigned long i; if (pList == NULL) return -1; for ( i = 0, pLink=GetHeadOfList(pList); i < GetListLength(pList); i++, pLink = GetNextLink(pLink)) { if (pLink->pElement == pElement) return 0; } return 1; } /* ListGetFirstElement * * Returns the first element of the list * * parameter * pList list pointer * * return * the elements data pointer * */ void * ListGetFirstElement(PLIST pList) { if (pList == NULL) return NULL; return (GetHeadOfList(pList))->pElement; } /* ListGetFirstHandle * * Retruns the first element of the list * * parameter * pList list pointer * * return * the elements handle */ void * ListGetFirstHandle(PLIST pList) { if (pList == NULL) return NULL; return GetHeadOfList(pList); } /* ListFindElement * * Searches for an element in the list * * parameter * pList list pointer * pElement element pointer * * return * element pointer, or NULL if not found */ void * ListFindElement(PLIST pList, void *pElement, int ( __cdecl *compare ) ( const void *, const void *) ) { PLINK pLink; unsigned long i; if (pList == NULL) return NULL; for ( i = 0, pLink = GetHeadOfList(pList); i < GetListLength(pList); i++, pLink = GetNextLink(pLink)) { if (compare(pElement, pLink->pElement) == 0) return pLink->pElement; } return NULL; } /* Compare Function template for ListFindElement int ElmCmp( char *arg1, MY_STRUCT arg2 ) { // Compare all of both strings: return _stricmp( arg1, arg2->struct_element ); } */ /* ListFindElmHandle * * Searches for an element in the list * * parameter * pList list pointer * pElement element pointer * * return * element handle, or NULL if not found */ void * ListFindElmHandle(PLIST pList, void *pElement, int ( __cdecl *compare ) ( const void *, const void *) ) { PLINK pLink; unsigned long i; if (pList == NULL) return NULL; for ( i = 0, pLink = GetHeadOfList(pList); i < GetListLength(pList); i++, pLink = GetNextLink(pLink)) { if (compare(pElement, pLink->pElement) == 0) return pLink; } return NULL; } /* Compare Function template for ListFindElmHandle int ElmCmp( char *arg1, MY_STRUCT arg2 ) { // Compare all of both strings: return _stricmp( arg1, arg2->struct_element ); } */ /* ListFindHandle * * Searches for an handle in the list * * parameter * pList list pointer * hElement element handle * * return * element handle or NULL if not found */ void * ListFindHandle(PLIST pList, void *hElement, int ( __cdecl *compare ) ( const void *, const void *) ) { PLINK pLink; unsigned long i; if (pList == NULL) return NULL; for ( i = 0, pLink = GetHeadOfList(pList); i < GetListLength(pList); i++, pLink = GetNextLink(pLink)) { if (compare(((PLINK)hElement)->pElement, pLink->pElement) == 0) return hElement; } return NULL; } /* Compare function template for ListFindHandle int HndlCmp( MY_STRUCT arg1, MY_STRUCT arg2 ) { // Compare all of both strings: return _stricmp( arg1->struct_element, arg2->struct_element ); } */ --- NEW FILE: lv_error.h --- /* lv_error.h * * LabVIEW Error Cluster Utilities * * Martin Henz Systemtechnik, Stuttgart * * */ #ifndef __inc_lv_error_h #define __inc_lv_error_h #include "extcode.h" //error cluster and error reporting #ifndef __typedef_ErrC #define __typedef_ErrC #pragma pack(1) typedef struct _STRUCT_LVERRORCLUSTER { LVBoolean lfStatus; long lCode; LStrHandle shSource; } ErrC, *pErrC, **hErrC; #pragma pack() #endif #if defined(__cplusplus) || defined(__cplusplus__) extern "C" { #endif void lv_ErrBld(LVBoolean lfStatus, long lCode, char *pszSource, pErrC pError); void lv_ErrBldMsg(LVBoolean lfStatus, long lCode, char *pszSource, char *pszMsg, pErrC pError); void lv_ErrBldOpt(LVBoolean lfStatus, long lCode, char *pszSource, char *pszMsg, char *pszOptMsg, pErrC pError); void lv_ErrBuilder(LVBoolean lfStatus, long lCode, char *pszSource, char *pszMsg, char *pszOptMsg, char *pszReason, pErrC pError); void lv_EasyErrBld(long lCode, char *pszSource, pErrC pError); void lv_WinErrBld(long lCode, char *pszSource, pErrC pError); void lv_WarnOrErrBld(long lCode, char *pszSource, pErrC pError); void lv_LStrErrBld(LVBoolean *plfStatus, long lCode, LStrHandle shSource, pErrC pError); void lv_LStrEasyErrBld(long lCode, LStrHandle shSource, pErrC pError); #if defined(__cplusplus) || defined(__cplusplus__) } #endif #endif --- NEW FILE: lv_error.cpp --- /* lv_error.cpp * * LabVIEW Error Cluster Utilities * * Martin Henz Systemtechnik, Stuttgart * * */ #define _WIN32_WINNT 0x0500 #include <windows.h> #include <crtdbg.h> #include "lv_error.h" /* lv_ErrBld * * Setzt den Fehler oder Warnungsstatus des Error Clusters * * parameter * lfStatus neuer Fehlerstatus * lCode neuer Fehlercode * pszSource Fehlerquelle * pError ErrorCluster * */ void lv_ErrBld(LVBoolean lfStatus, long lCode, char *pszSource, pErrC pError) { //error pointer test _ASSERT(!DSCheckPtr(pError)); /* Der ErrorCluster wird nur verändert, wenn der aktuelle Status False ist, oder * wenn der aktuelle Errorcode 0 ist (für Warnungen) */ if ( pError->lfStatus == LVFALSE ) { _ASSERT(pszSource); if (lfStatus == LVTRUE || (pError->lCode == 0 && lCode != 0) ) { pError->lfStatus = lfStatus; pError->lCode = lCode; LStrPrintf(pError->shSource,(CStr)"%s", pszSource); } } } /* lv_ErrBldMsg * * Setzt den Fehler oder Warnungsstatus des Error Clusters * * parameter * lfStatus neuer Fehlerstatus * lCode neuer Fehlercode * pszSource Fehlerquelle * pszMsg Nachricht * pError ErrorCluster * */ void lv_ErrBldMsg(LVBoolean lfStatus, long lCode, char *pszSource, char *pszMsg, pErrC pError) { //error pointer test _ASSERT(!DSCheckPtr(pError)); /* Der ErrorCluster wird nur verändert, wenn der aktuelle Status False ist, oder * wenn der aktuelle Errorcode 0 ist (für Warnungen) */ if ( pError->lfStatus == LVFALSE ) { _ASSERT(pszSource); if (lfStatus == LVTRUE || (pError->lCode == 0 && lCode != 0) ) { pError->lfStatus = lfStatus; pError->lCode = lCode; LStrPrintf(pError->shSource,(CStr)"%s: %s", pszSource, pszMsg); } } } /* lv_ErrBldOpt * * Setzt den Fehler oder Warnungsstatus des Error Clusters * * parameter * lfStatus neuer Fehlerstatus * lCode neuer Fehlercode * pszSource Fehlerquelle * pszMsg Nachricht * pszOptMsg Optionale Nachricht * pError ErrorCluster */ void lv_ErrBldOpt(LVBoolean lfStatus, long lCode, char *pszSource, char *pszMsg, char *pszOptMsg, pErrC pError) { //error pointer test _ASSERT(!DSCheckPtr(pError)); /* Der ErrorCluster wird nur verändert, wenn der aktuelle Status False ist, oder * wenn der aktuelle Errorcode 0 ist (für Warnungen) */ if ( pError->lfStatus == LVFALSE ) { _ASSERT(pszSource); if (lfStatus == LVTRUE || (pError->lCode == 0 && lCode != 0) ) { pError->lfStatus = lfStatus; pError->lCode = lCode; if (pszMsg != NULL) { if (pszOptMsg != NULL) LStrPrintf(pError->shSource,(CStr)"%s: %s (%s)", pszSource, pszMsg, pszOptMsg); else LStrPrintf(pError->shSource,(CStr)"%s: %s", pszSource, pszMsg); } else { if (pszOptMsg != NULL) LStrPrintf(pError->shSource,(CStr)"%s (%s)", pszSource, pszOptMsg); else LStrPrintf(pError->shSource,(CStr)"%s", pszSource); } } } } /* lv_ErrBuilder * * Setzt den Fehler oder Warnungsstatus des Error Clusters * * parameter * lfStatus neuer Fehlerstatus * lCode neuer Fehlercode * pszSource Fehlerquelle * pszMsg Nachricht * pszOptMsg Optionale Nachricht * pszReason mögliche Ursache * pError ErrorCluster */ void lv_ErrBuilder(LVBoolean lfStatus, long lCode, char *pszSource, char *pszMsg, char *pszOptMsg, char *pszReason, pErrC pError) { //error pointer test _ASSERT(!DSCheckPtr(pError)); /* Der ErrorCluster wird nur verändert, wenn der aktuelle Status False ist, oder * wenn der aktuelle Errorcode 0 ist (für Warnungen) */ if ( pError->lfStatus == LVFALSE ) { _ASSERT(pszSource); if (lfStatus == LVTRUE || (pError->lCode == 0 && lCode != 0) ) { pError->lfStatus = lfStatus; pError->lCode = lCode; if (pszMsg != NULL) { if (pszOptMsg != NULL) { if (pszReason != NULL) LStrPrintf(pError->shSource,(CStr)"%s: %s (%s)<err>%s", pszSource, pszMsg, pszOptMsg, pszReason); else LStrPrintf(pError->shSource,(CStr)"%s: %s (%s)", pszSource, pszMsg, pszOptMsg); } else { if (pszReason != NULL) LStrPrintf(pError->shSource,(CStr)"%s: %s<err>%s", pszSource, pszMsg, pszReason); else LStrPrintf(pError->shSource,(CStr)"%s: %s", pszSource, pszMsg); } } else { if (pszOptMsg != NULL) { if (pszReason != NULL) LStrPrintf(pError->shSource,(CStr)"%s (%s)<err>%s", pszSource, pszOptMsg, pszReason); else LStrPrintf(pError->shSource,(CStr)"%s (%s)", pszSource, pszOptMsg); } else { if (pszReason != NULL) LStrPrintf(pError->shSource,(CStr)"%s<err>", pszSource, pszReason); else LStrPrintf(pError->shSource,(CStr)"%s", pszSource); } } } } } /* lv_EasyErrBld * * Setzt den Fehlerstatus des Error Clusters * * parameter * lCode neuer Fehlercode * pszSource Fehlerquelle * pError ErrorCluster */ void lv_EasyErrBld(long lCode, char *pszSource, pErrC pError) { //error pointer test _ASSERT(!DSCheckPtr(pError)); /* Der ErrorCluster wird nur verändert, wenn der aktuelle Status False ist, oder * wenn der aktuelle Errorcode 0 ist (für Warnungen) */ if ( pError->lfStatus == LVFALSE ) { _ASSERT(pszSource); if (lCode != 0) { pError->lfStatus = LVTRUE; pError->lCode = lCode; LStrPrintf(pError->shSource, (CStr)"%s", pszSource); } } } /* lv_WinErrBld * * Setzt den Windows Fehlerstatus des Error Clusters * * input * lCode neuer Fehlercode * pszSource Fehlerquelle * pError ErrorCluster * * output * error ErrorCluster */ void lv_WinErrBld(long lCode, char *pszSource, pErrC pError) { char * pszWinErrMsg; //error pointer test _ASSERT(!DSCheckPtr(pError)); /* Der ErrorCluster wird nur verändert, wenn der aktuelle Status False ist, oder * wenn der aktuelle Errorcode 0 ist (für Warnungen) */ if ( pError->lfStatus == LVFALSE ) { _ASSERT(pszSource); if (lCode != 0) { pError->lfStatus = LVTRUE; pError->lCode = lCode; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, lCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &pszWinErrMsg, 0, NULL); LStrPrintf(pError->shSource, (CStr)"%s<err>%s", pszSource, pszWinErrMsg); LocalFree(pszWinErrMsg); } } } /* lv_WarnOrErrBld * * Setzt den Fehlerstatus des Error Clusters. The error status will be set * for Error Codes lower than 60000. * * parameter * lCode neuer Fehlercode * pszSource Fehlerquelle * pError ErrorCluster * */ void lv_WarnOrErrBld(long lCode, char *pszSource, pErrC pError) { //error pointer test _ASSERT(!DSCheckPtr(pError)); /* Der ErrorCluster wird nur verändert, wenn der aktuelle Status False ist, oder * wenn der aktuelle Errorcode 0 ist (für Warnungen) */ if ( pError->lfStatus == LVFALSE ) { _ASSERT(pszSource); if (lCode != 0) { pError->lfStatus = lCode < 60000 ? LVTRUE : LVFALSE; pError->lCode = lCode; LStrPrintf(pError->shSource, (CStr)"%s", pszSource); } } } /* lv_LStrErrBld * * Setzt den Fehler oder Warnungsstatus des Error Clusters * * parameter * lfStatus neuer Fehlerstatus * lCode neuer Fehlercode * shSource Fehlerquelle * pError ErrorCluster */ void lv_LStrErrBld(LVBoolean *plfStatus, long lCode, LStrHandle shSource, pErrC pError) { //error pointer test _ASSERT(!DSCheckPtr(pError)); /* Der ErrorCluster wird nur verändert, wenn der aktuelle Status False ist, oder * wenn der aktuelle Errorcode 0 ist (für Warnungen) */ if ( pError->lfStatus == LVFALSE ) { _ASSERT(!DSCheckHandle(shSource)); if (*plfStatus == LVTRUE || (pError->lCode == 0 && lCode != 0)) { pError->lfStatus = *plfStatus; pError->lCode = lCode; LStrPrintf(pError->shSource, (CStr)"%H", shSource); } } } /* lv_LStrEasyErrBld * * Setzt den Fehlerstatus des Error Clusters * * parameter * lCode neuer Fehlercode * shSource Fehlerquelle * pError ErrorCluster */ void lv_LStrEasyErrBld(long lCode, LStrHandle shSource, pErrC pError) { //error pointer test _ASSERT(!DSCheckPtr(pError)); /* Der ErrorCluster wird nur verändert, wenn der aktuelle Status False ist, oder * wenn der aktuelle Errorcode 0 ist (für Warnungen) */ if ( pError->lfStatus == LVFALSE ) { _ASSERT(!DSCheckHandle(shSource)); if ( lCode != 0 ) { pError->lfStatus = LVTRUE; pError->lCode = lCode; LStrPrintf(pError->shSource, (CStr)"%H", shSource); } } } --- NEW FILE: lvserialrc.h --- //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. // Used by lvserial.rc // // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 101 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif --- NEW FILE: lvserial.cpp --- /* lvserial.cpp * * Serial Port API * * Martin Henz Systemtechnik, Stuttgart * * */ #define _WIN32_WINNT 0x0500 #include <windows.h> #include <stdio.h> #include <objbase.h> #include <crtdbg.h> #include <time.h> #include "lvserial.h" #include "lv_error.h" inline long __CommRead( [...2492 lines suppressed...] * pError pError cluster */ void lvCommGetUserData(HANDLE hComm, unsigned long *pulUserData, pErrC pError) { long lCode; //pError pointer test _ASSERT(!DSCheckPtr(pError)); return; if (pError->lfStatus == LVTRUE) return; _ASSERT(!DSCheckPtr(pulUserData)); lCode = CommGetUserData(hComm, pulUserData); lv_WarnOrErrBld(lCode, __FUNCTION__, pError); } --- NEW FILE: plist.h --- /* plist.cpp * * Simple List Implementation * * Martin Henz Systemtechnik, Stuttgart * */ #ifndef __inc_plist_h #define __inc_plist_h #pragma pack(1) /* * The LINK structure is used to chain structures together into a list. */ typedef struct _LINK *PLINK; typedef struct _LINK { PLINK pPrev; //previous or back pointer PLINK pNext; //next or forward pointer void *pElement; //element pointer } LINK; /* * The LIST data structure. */ typedef struct _LIST { PLINK pTail; //list tail pointer PLINK pHead; //list head pointer unsigned long ulLength; //list length } LIST; typedef _LIST *PLIST; #pragma pack() /* * Functions */ #if defined(__cplusplus) || defined(__cplusplus__) extern "C" { #endif //create and dispose PLIST ListCreate(void); int ListDispose(PLIST pList); //add to list void * ListAppendElement(PLIST pList, void *pElement); //remove from list void * ListRemoveHandle(PLIST pList, void *hElement); void * ListRemoveFirstElement(PLIST pList); void * ListRemoveLastElement(PLIST pList); //get element and element handle void * ListGetElement(PLIST pList, void *hElement); void * ListGetFirstElement(PLIST pList); void * ListGetFirstHandle(PLIST pList); //information and check int ListGetLength(PLIST pList); int ListCheckHandle(PLIST pList, void *hElement); int ListCheckElement(PLIST pList, void *pElement); void * ListFindElement(PLIST pList, void *pElement, int ( __cdecl *compare ) ( const void *, const void *) ); void * ListFindElmHandle(PLIST pList, void *pElement, int ( __cdecl *compare ) ( const void *, const void *) ); void * ListFindHandle(PLIST pList, void *hElement, int ( __cdecl *compare ) ( const void *, const void *) ); #if defined(__cplusplus) || defined(__cplusplus__) } #endif #endif --- NEW FILE: lvserial.h --- /* lvserial.h * * Serial Port API * * Martin Henz Systemtechnik, Stuttgart * * */ #include <windows.h> #include "lv_error.h" #include "plist.h" #include <extcode.h> typedef struct { HANDLE hC; char *pszPort; int fTermCharEnable; char *pcTermChar; long lNumberOfTermChar; unsigned long ulTimeout; unsigned long ulNOpened; HANDLE hSempaphore; unsigned long ulUserData; HANDLE hEvRead; HANDLE hEvWrite; } COMM, *PCOMM; #define COMM_PARITY_NONE 0 #define COMM_PARITY_ODD 1 #define COMM_PARITY_EVEN 2 #define COMM_PARITY_MARK 3 #define COMM_PARITY_SPACE 4 #define COMM_ONESTOPBIT 0 #define COMM_ONE5STOPBITS 1 #define COMM_TWOSTOPBITS 2 #define COMM_FLUSH_TXABORT 0x0001 // Kill the pending/current writes to the comm port. #define COMM_FLUSH_RXABORT 0x0002 // Kill the pending/current reads to the comm port. #define COMM_FLUSH_TXCLEAR 0x0004 // Kill the transmit queue if there. #define COMM_FLUSH_RXCLEAR 0x0008 // Kill the typeahead buffer if there. #define COMM_ERRF_RXOVER 0x0001 // Receive Queue overflow #define COMM_ERRF_OVERRUN 0x0002 // Receive Overrun Error #define COMM_ERRF_RXPARITY 0x0004 // Receive Parity Error #define COMM_ERRF_FRAME 0x0008 // Receive Framing pError #define COMM_ERRF_BREAK 0x0010 // Break Detected #define COMM_ERRF_TXFULL 0x0100 // TX Queue is full #define COMM_ERRF_PTO 0x0200 // LPTx Timeout #define COMM_ERRF_IOE 0x0400 // LPTx I/O Error #define COMM_ERRF_DNS 0x0800 // LPTx Device not selected #define COMM_ERRF_OOP 0x1000 // LPTx Out-Of-Paper #define COMM_ERRF_MODE 0x8000 // Requested mode unsupported #define COMM_STAT_CTS 0x0001 #define COMM_STAT_DSR 0x0002 #define COMM_STAT_RLSD 0x0003 #define COMM_STAT_XOFFHOLD 0x0004 #define COMM_STAT_XOFFSENT 0x0005 #define COMM_STAT_EOF 0x0006 #define COMM_STAT_TXIM 0x0007 #define COMM_MSTAT_CTS_ON ((DWORD)0x0010) #define COMM_MSTAT_DSR_ON ((DWORD)0x0020) #define COMM_MSTAT_RING_ON ((DWORD)0x0040) #define COMM_MSTAT_RLSD_ON ((DWORD)0x0080) #define COMM_FLOW_NONE 0 #define COMM_FLOW_XONXOFF 1 #define COMM_FLOW_RTSCTS 2 #define COMM_FLOW_DTRDSR 3 #define COMM_WARN_NYBTES 65060 #define COMM_WARN_TERMCHAR 65061 #define COMM_SUCCESS 0 #define COMM_ERR_TERMCHAR -65061 #define COMM_ERR_INVALIDLENGTH -65062 #define COMM_ERR_NOTIMPLEMENTED -65063 #define COMM_ERR_ACCESS -65064 #define COMM_ERR_OVERFLOW -65065 #define COMM_ERR_FRAMING -65066 #define COMM_ERR_PARITY -65067 #define COMM_ERR_TIMEOUT -65068 #define COMM_ERR_HANDLE -65069 #define COMM_ERR_SYSTEM -65070 #define COMM_ERR_RESOURCE -65071 #define COMM_ERR_ARGUMENT -65072 #define COMM_ERR_OUTOFMEMORY -65073 #define COMM_ERR_ABORTED -65074 #define COMM_ERR_SEMAPHORE -65075 #define COMM_ERR_LOCKTIMEOUT -65076 #define COMM_ERR_NOTLOCKED -65077 #if defined(__cplusplus) || defined(__cplusplus__) extern "C" { #endif long CommOpenPort(PHANDLE phComm, char * pszPort, int fDuplicate); long CommClosePort(HANDLE hComm); long CommWrite( HANDLE hComm, char * pcBuffer, unsigned long ulBytesToWrite, unsigned long * pulBytesWritten); long CommRead( HANDLE hComm, char *pcBuffer, unsigned long ulBytesToRead, unsigned long * pulBytesRead); long CommBreak(HANDLE hComm, unsigned long ulMilliseconds); long CommBuffer(HANDLE hComm, unsigned long ulInQueueSize, unsigned long ulOutQueueSize); long CommFlush(HANDLE hComm, unsigned long ulFlags); long CommStatus( HANDLE hComm, unsigned long * pulErrorFlags, unsigned long * pulStatusFlags, unsigned long * pulInQueue, unsigned long * pulOutQueue); long CommBytesAtPort( HANDLE hComm, unsigned long * pulBytesAtPort); long CommModemStatus(HANDLE hComm, unsigned long * pulModemStatus); long CommGetCTS(HANDLE hComm, int *pfCTS); long CommGetDSR(HANDLE hComm, int *pfDSR); long CommGetRING(HANDLE hComm, int *pfRING); long CommGetRLSD(HANDLE hComm, int *pfRLSD); long CommSetXOFF(HANDLE hComm); long CommSetXON(HANDLE hComm); long CommSetRTS(HANDLE hComm); long CommClrRTS(HANDLE hComm); long CommSetDTR(HANDLE hComm); long CommClrDTR(HANDLE hComm); long CommSetBreak(HANDLE hComm); long CommClearBreak(HANDLE hComm); long CommConfig( HANDLE hComm, unsigned long ulBaudRate, unsigned short usDataBits, unsigned short usParity, unsigned short usStopBits); long CommFlowControl( HANDLE hComm, unsigned short usFlowControl, unsigned char cXOFFCharacter, unsigned char cXONCharacter); long CommTermination( HANDLE hComm, int fTermCharEnable, char *pcTermCharacter, long lNumberOfTermChar); long CommTimeout(HANDLE hComm, unsigned long ulTimeout); long CommLock(HANDLE hComm, unsigned long ulTimeout); long CommUnLock(HANDLE hComm); long CommSetUserData(HANDLE hComm, unsigned long ulUserData); long CommGetUserData(HANDLE hComm, unsigned long *pulUserData); /* -----------------------------------------------------------------------------------*/ void lvCommOpenPort(PHANDLE phComm, LStrHandle shPort, LVBoolean *plfDuplicate, pErrC pError); void lvCommClosePort(HANDLE hComm, pErrC pError); void lvCommWrite( HANDLE hComm, LStrHandle Buffer, unsigned long * pulBytesWritten, pErrC pError); void lvCommRead( HANDLE hComm, LStrHandle shBuffer, unsigned long ulBytesToRead, unsigned long * pulBytesRead, pErrC pError); void lvCommBreak(HANDLE hComm, unsigned long ulMilliseconds, pErrC pError); void lvCommBuffer(HANDLE hComm, unsigned long ulInQueueSize, unsigned long ulOutQueueSize, pErrC pError); void lvCommFlush(HANDLE hComm, unsigned long ulFlags, pErrC pError); void lvCommStatus( HANDLE hComm, unsigned long * pulErrorFlags, unsigned long * pulStatusFlags, unsigned long * pulInQueue, unsigned long * pulOutQueue, pErrC pError); void lvCommBytesAtPort( HANDLE hComm, unsigned long * pulBytesAtPort, pErrC pError); void lvCommModemStatus(HANDLE hComm, unsigned long * pulModemStatus, pErrC pError); void lvCommGetCTS(HANDLE hComm, LVBoolean *plfCTS, pErrC pError); void lvCommGetDSR(HANDLE hComm, LVBoolean *plfDSR, pErrC pError); void lvCommGetRING(HANDLE hComm, LVBoolean *plfRING, pErrC pError); void lvCommGetRLSD(HANDLE hComm, LVBoolean *plfRLSD, pErrC pError); void lvCommSetXOFF(HANDLE hComm, pErrC pError); void lvCommSetXON(HANDLE hComm, pErrC pError); void lvCommSetRTS(HANDLE hComm, pErrC pError); void lvCommClrRTS(HANDLE hComm, pErrC pError); void lvCommSetDTR(HANDLE hComm, pErrC pError); void lvCommClrDTR(HANDLE hComm, pErrC pError); void lvCommSetBreak(HANDLE hComm, pErrC pError); void lvCommClearBreak(HANDLE hComm, pErrC pError); void lvCommConfig( HANDLE hComm, unsigned long ulBaudRate, unsigned short usDataBits, unsigned short usParity, unsigned short usStopBits, pErrC pError); void lvCommFlowControl( HANDLE hComm, unsigned short usFlowControl, unsigned char ucXOFFCharacter, unsigned char ucXONCharacter, pErrC pError); void lvCommTermination( HANDLE hComm, LVBoolean *plfTermCharEnable, LStrHandle shTermCharacter, pErrC pError); void lvCommTimeout( HANDLE hComm, unsigned long ulTimeout, pErrC pError); void lvCommLock(HANDLE hComm, unsigned long ulTimeout, pErrC pError); void lvCommUnLock(HANDLE hComm, pErrC pError); void lvCommSetUserData(HANDLE hComm, unsigned long ulUserData, pErrC pError); void lvCommGetUserData(HANDLE hComm, unsigned long *pulUserData, pErrC pError); #if defined(__cplusplus) || defined(__cplusplus__) } #endif --- NEW FILE: lvserial.def --- LIBRARY lvserial EXPORTS CommOpenPort EXPORTS CommClosePort EXPORTS CommWrite EXPORTS CommRead EXPORTS CommBreak EXPORTS CommBuffer EXPORTS CommFlush EXPORTS CommStatus EXPORTS CommBytesAtPort EXPORTS CommModemStatus EXPORTS CommGetCTS EXPORTS CommGetDSR EXPORTS CommGetRING EXPORTS CommGetRLSD EXPORTS CommSetXOFF EXPORTS CommSetXON EXPORTS CommSetRTS EXPORTS CommClrRTS EXPORTS CommSetDTR EXPORTS CommClrDTR EXPORTS CommSetBreak EXPORTS CommClearBreak EXPORTS CommConfig EXPORTS CommFlowControl EXPORTS CommTermination EXPORTS CommTimeout EXPORTS CommLock EXPORTS CommUnLock EXPORTS CommSetUserData EXPORTS CommGetUserData EXPORTS lvCommOpenPort EXPORTS lvCommClosePort EXPORTS lvCommWrite EXPORTS lvCommRead EXPORTS lvCommBreak EXPORTS lvCommBuffer EXPORTS lvCommFlush EXPORTS lvCommStatus EXPORTS lvCommBytesAtPort EXPORTS lvCommModemStatus EXPORTS lvCommGetCTS EXPORTS lvCommGetDSR EXPORTS lvCommGetRING EXPORTS lvCommGetRLSD EXPORTS lvCommSetXOFF EXPORTS lvCommSetXON EXPORTS lvCommSetRTS EXPORTS lvCommClrRTS EXPORTS lvCommSetDTR EXPORTS lvCommClrDTR EXPORTS lvCommSetBreak EXPORTS lvCommClearBreak EXPORTS lvCommConfig EXPORTS lvCommFlowControl EXPORTS lvCommTermination EXPORTS lvCommTimeout EXPORTS lvCommLock EXPORTS lvCommUnLock EXPORTS lvCommSetUserData EXPORTS lvCommGetUserData |