Z
zhaozhh1
Unregistered / Unconfirmed
GUEST, unregistred user!
//********************************************************************
// 模块: MD_CA530.cpp
// 描述: 本模块为东亚公司的CA530血凝仪的联机程序(Win95版)
// 函数:
// DLLEXPORT DWORD WINAPI CommMonitorProc( LPSTR lpData );
// DLLEXPORT void BeforeSetCommState(DCB *pComDcb);
// 编写:
// 最后修改日期: 09/02/1999
//********************************************************************
#include <stdio.h>
#include <Const.h>
#include <Device.h>
#include <str.h>
#define c_RxBufferLength 4096 //接收缓冲区长
#define c_MaxItemNum 50 //一个包的最大项目数
#define c_SampleIDOff 26
#define c_FirstItemOff 53
#define c_ItemLen 3
#define c_ResultLen 5
#define c_EachDistance 9
int WINAPI FormatResult(LPSTR lpDataBuffer, PRESULT lpResult)
{
static WORD wSampleID;
static SYSTEMTIME AssayTime;
static int i;
static LPSTR lpbegin
Pos, lpEndPos;
LPSTR lpTemp;
int j, k;
GetLocalTime(&AssayTime); //得到系统北京时间
if ((lpbegin
Pos =strchr(lpDataBuffer, 0x02))==NULL)
return 0;
lpEndPos =lpbegin
Pos;
lpEndPos +=c_SampleIDOff;
for(lpEndPos;*(lpEndPos) ==0x30;lpEndPos++);
wSampleID =atoi(lpEndPos);
lpbegin
Pos +=c_FirstItemOff;
for(i =0;i<c_MaxItemNum;i++)
{
lpResult.SampleID =wSampleID;
strcpy(lpResult.SampleType, ""
strncpy(lpResult.ItemID, lpbegin
Pos, c_ItemLen);
lpResult.ItemID[c_ItemLen] ='/0';
strncpy(lpResult.AssayResult, lpbegin
Pos+c_ItemLen, c_ResultLen);
lpResult.AssayResult[c_ResultLen] ='/0';
strcpy(lpResult.AssayResult2, ""
memcpy(&(lpResult.AssayTime), &AssayTime, sizeof(SYSTEMTIME));
DeleteSpace(lpResult.AssayResult);
j =strlen(lpResult.AssayResult);
lpTemp =lpResult.AssayResult;
for(k =0;k<j;k++,lpTemp++)
{
if(*(lpTemp) <=0x2D || *(lpTemp) ==0x2F || *(lpTemp) >=0x3A)
{
strcpy(lpResult.AssayResult2,lpResult.AssayResult);
strcpy(lpResult.AssayResult, ""
break;
}
}
lpbegin
Pos +=c_EachDistance;
if (*(lpbegin
Pos) ==ETX)
break;
}
return (i+1);
}
//************************************************************************
//DLLEXPORT DWORD WINAPI CommMonitorProc( LPSTR lpData )
//
// 描述:
// 串口监控线程的启动函数
// 参数:
// LPSTR lpData
// 生化仪接口控制块
//************************************************************************
DWORD WINAPI CommMonitor( LPSTR lpData)
{
//定义变量
DEVICE * lpDevice =(LPDEVICE)lpData;
DWORD dwReadLength=0, dwWrittenLength=0, dwRxBufferLength=0;
DWORD dwError =0, dwEvtMask;
COMSTAT ComStat;
BYTE RxChar=0, RxBuffer[c_RxBufferLength] ;//接收缓冲区
RESULT Result[c_MaxItemNum]; //存储结果
int i, nItemCount;
//赋初始值
for (i =0;
i<c_MaxItemNum;
i++)
{
strcpy(Result.InstCode, lpDevice->InstCode);
//仪器缩写
Result.ResultType =c_Route;//c_TypeRoutine | c_TypeNumber;
Result.ErrorCode =c_Reliable;
memset(LPSTR(Result.Comment), 0, c_MaxCommentLength);
}
PurgeComm( lpDevice->hComm, PURGE_RXCLEAR);
SetCommMask(lpDevice->hComm, EV_RXFLAG);
while (TRUE)
{
//----第一步:接收数据----
ClearCommError(lpDevice->hComm, &dwError, &ComStat);
while( ComStat.cbInQue ==0) //接收缓冲区无数据
{
do{//等待LF
WaitCommEvent(lpDevice->hComm, &dwEvtMask, NULL);
}while((dwEvtMask &
EV_RXFLAG) != EV_RXFLAG);
ClearCommError(lpDevice->hComm, &dwError, &ComStat);
}
do{
ReadFile(lpDevice->hComm, &RxChar, 1, &dwReadLength, NULL);
}while(RxChar !=STX);
memset(RxBuffer, 0, c_RxBufferLength);
RxBuffer[0] =RxChar;
i =1;
do{
ReadFile(lpDevice->hComm, &RxChar, 1, &dwReadLength, NULL);
RxBuffer[i++] =RxChar;
}while(RxChar !=ETX);
//----第二步:将原始数据写入文本文件----
if (lpDevice->hRawDataFile !=INVALID_HANDLE_VALUE)
{
SetFilePointer(lpDevice->hRawDataFile, 0, 0, FILE_END);
WriteFile(lpDevice->hRawDataFile, (LPSTR)RxBuffer, i, &dwWrittenLength, NULL);
WriteFile(lpDevice->hRawDataFile,"/x0d/x0a"
, 2, &dwWrittenLength, NULL);
}
//----第三步:处理数据----
nItemCount =FormatResult((LPSTR)RxBuffer, Result);
if (nItemCount>0)
{
(*(lpDevice->lpResultProcessRoutine))(Result, nItemCount);
lpDevice->dwRecordCount++;
lpDevice->wSampleID=Result[nItemCount-1].SampleID;
}
//----第四步:----
}
return TRUE;
} // end of CommWatchProc()
void WINAPI BeforeSetCommState(DCB *pComDcb)
{
pComDcb->EvtChar =ETX;
}
int WINAPI ReadBakData(PDEVICE lpDevice)
{
DWORD dwRxBufferLength=0, dwReadLength=0;
BYTE RxBuffer[c_RxBufferLength] ;//接收缓冲区
RESULT Result[c_MaxItemNum]; //存储结果
int i, nItemCount, nItemTotalCount=0, nMarkCount=0;
//赋初始值
for (i =0;
i<c_MaxItemNum;
i++)
{
strcpy(Result.InstCode, lpDevice->InstCode);
//仪器缩写
Result.ResultType = c_Route ;//c_TypeRoutine | c_TypeNumber;
Result.ErrorCode =c_Reliable;
memset(LPSTR(Result.Comment), 0, c_MaxCommentLength);
}
SetFilePointer(lpDevice->hRawDataFile, 0, 0, FILE_begin
);
while(TRUE)
{
memset(RxBuffer, 0, c_RxBufferLength);
do{
ReadFile(lpDevice->hRawDataFile, RxBuffer, 1, &dwReadLength, NULL);
if (dwReadLength ==0)
return nItemTotalCount;
}while(RxBuffer[0]!=STX);
i=1;
do{
ReadFile(lpDevice->hRawDataFile, &(RxBuffer), 1, &dwReadLength, NULL);
if (dwReadLength ==0)
return nItemTotalCount;
}while(RxBuffer[i++]!=ETX);
nItemCount =FormatResult((LPSTR)RxBuffer, Result);
if (nItemCount>0)
{
(*(lpDevice->lpResultProcessRoutine))(Result, nItemCount);
lpDevice->dwRecordCount++;
lpDevice->wSampleID=Result[nItemCount-1].SampleID;
}
}
return nItemTotalCount;
}
// 模块: MD_CA530.cpp
// 描述: 本模块为东亚公司的CA530血凝仪的联机程序(Win95版)
// 函数:
// DLLEXPORT DWORD WINAPI CommMonitorProc( LPSTR lpData );
// DLLEXPORT void BeforeSetCommState(DCB *pComDcb);
// 编写:
// 最后修改日期: 09/02/1999
//********************************************************************
#include <stdio.h>
#include <Const.h>
#include <Device.h>
#include <str.h>
#define c_RxBufferLength 4096 //接收缓冲区长
#define c_MaxItemNum 50 //一个包的最大项目数
#define c_SampleIDOff 26
#define c_FirstItemOff 53
#define c_ItemLen 3
#define c_ResultLen 5
#define c_EachDistance 9
int WINAPI FormatResult(LPSTR lpDataBuffer, PRESULT lpResult)
{
static WORD wSampleID;
static SYSTEMTIME AssayTime;
static int i;
static LPSTR lpbegin
Pos, lpEndPos;
LPSTR lpTemp;
int j, k;
GetLocalTime(&AssayTime); //得到系统北京时间
if ((lpbegin
Pos =strchr(lpDataBuffer, 0x02))==NULL)
return 0;
lpEndPos =lpbegin
Pos;
lpEndPos +=c_SampleIDOff;
for(lpEndPos;*(lpEndPos) ==0x30;lpEndPos++);
wSampleID =atoi(lpEndPos);
lpbegin
Pos +=c_FirstItemOff;
for(i =0;i<c_MaxItemNum;i++)
{
lpResult.SampleID =wSampleID;
strcpy(lpResult.SampleType, ""
strncpy(lpResult.ItemID, lpbegin
Pos, c_ItemLen);
lpResult.ItemID[c_ItemLen] ='/0';
strncpy(lpResult.AssayResult, lpbegin
Pos+c_ItemLen, c_ResultLen);
lpResult.AssayResult[c_ResultLen] ='/0';
strcpy(lpResult.AssayResult2, ""
memcpy(&(lpResult.AssayTime), &AssayTime, sizeof(SYSTEMTIME));
DeleteSpace(lpResult.AssayResult);
j =strlen(lpResult.AssayResult);
lpTemp =lpResult.AssayResult;
for(k =0;k<j;k++,lpTemp++)
{
if(*(lpTemp) <=0x2D || *(lpTemp) ==0x2F || *(lpTemp) >=0x3A)
{
strcpy(lpResult.AssayResult2,lpResult.AssayResult);
strcpy(lpResult.AssayResult, ""
break;
}
}
lpbegin
Pos +=c_EachDistance;
if (*(lpbegin
Pos) ==ETX)
break;
}
return (i+1);
}
//************************************************************************
//DLLEXPORT DWORD WINAPI CommMonitorProc( LPSTR lpData )
//
// 描述:
// 串口监控线程的启动函数
// 参数:
// LPSTR lpData
// 生化仪接口控制块
//************************************************************************
DWORD WINAPI CommMonitor( LPSTR lpData)
{
//定义变量
DEVICE * lpDevice =(LPDEVICE)lpData;
DWORD dwReadLength=0, dwWrittenLength=0, dwRxBufferLength=0;
DWORD dwError =0, dwEvtMask;
COMSTAT ComStat;
BYTE RxChar=0, RxBuffer[c_RxBufferLength] ;//接收缓冲区
RESULT Result[c_MaxItemNum]; //存储结果
int i, nItemCount;
//赋初始值
for (i =0;
i<c_MaxItemNum;
i++)
{
strcpy(Result.InstCode, lpDevice->InstCode);
//仪器缩写
Result.ResultType =c_Route;//c_TypeRoutine | c_TypeNumber;
Result.ErrorCode =c_Reliable;
memset(LPSTR(Result.Comment), 0, c_MaxCommentLength);
}
PurgeComm( lpDevice->hComm, PURGE_RXCLEAR);
SetCommMask(lpDevice->hComm, EV_RXFLAG);
while (TRUE)
{
//----第一步:接收数据----
ClearCommError(lpDevice->hComm, &dwError, &ComStat);
while( ComStat.cbInQue ==0) //接收缓冲区无数据
{
do{//等待LF
WaitCommEvent(lpDevice->hComm, &dwEvtMask, NULL);
}while((dwEvtMask &
EV_RXFLAG) != EV_RXFLAG);
ClearCommError(lpDevice->hComm, &dwError, &ComStat);
}
do{
ReadFile(lpDevice->hComm, &RxChar, 1, &dwReadLength, NULL);
}while(RxChar !=STX);
memset(RxBuffer, 0, c_RxBufferLength);
RxBuffer[0] =RxChar;
i =1;
do{
ReadFile(lpDevice->hComm, &RxChar, 1, &dwReadLength, NULL);
RxBuffer[i++] =RxChar;
}while(RxChar !=ETX);
//----第二步:将原始数据写入文本文件----
if (lpDevice->hRawDataFile !=INVALID_HANDLE_VALUE)
{
SetFilePointer(lpDevice->hRawDataFile, 0, 0, FILE_END);
WriteFile(lpDevice->hRawDataFile, (LPSTR)RxBuffer, i, &dwWrittenLength, NULL);
WriteFile(lpDevice->hRawDataFile,"/x0d/x0a"
, 2, &dwWrittenLength, NULL);
}
//----第三步:处理数据----
nItemCount =FormatResult((LPSTR)RxBuffer, Result);
if (nItemCount>0)
{
(*(lpDevice->lpResultProcessRoutine))(Result, nItemCount);
lpDevice->dwRecordCount++;
lpDevice->wSampleID=Result[nItemCount-1].SampleID;
}
//----第四步:----
}
return TRUE;
} // end of CommWatchProc()
void WINAPI BeforeSetCommState(DCB *pComDcb)
{
pComDcb->EvtChar =ETX;
}
int WINAPI ReadBakData(PDEVICE lpDevice)
{
DWORD dwRxBufferLength=0, dwReadLength=0;
BYTE RxBuffer[c_RxBufferLength] ;//接收缓冲区
RESULT Result[c_MaxItemNum]; //存储结果
int i, nItemCount, nItemTotalCount=0, nMarkCount=0;
//赋初始值
for (i =0;
i<c_MaxItemNum;
i++)
{
strcpy(Result.InstCode, lpDevice->InstCode);
//仪器缩写
Result.ResultType = c_Route ;//c_TypeRoutine | c_TypeNumber;
Result.ErrorCode =c_Reliable;
memset(LPSTR(Result.Comment), 0, c_MaxCommentLength);
}
SetFilePointer(lpDevice->hRawDataFile, 0, 0, FILE_begin
);
while(TRUE)
{
memset(RxBuffer, 0, c_RxBufferLength);
do{
ReadFile(lpDevice->hRawDataFile, RxBuffer, 1, &dwReadLength, NULL);
if (dwReadLength ==0)
return nItemTotalCount;
}while(RxBuffer[0]!=STX);
i=1;
do{
ReadFile(lpDevice->hRawDataFile, &(RxBuffer), 1, &dwReadLength, NULL);
if (dwReadLength ==0)
return nItemTotalCount;
}while(RxBuffer[i++]!=ETX);
nItemCount =FormatResult((LPSTR)RxBuffer, Result);
if (nItemCount>0)
{
(*(lpDevice->lpResultProcessRoutine))(Result, nItemCount);
lpDevice->dwRecordCount++;
lpDevice->wSampleID=Result[nItemCount-1].SampleID;
}
}
return nItemTotalCount;
}