请帮忙将C++代码转成delphi代码,谢谢! ( 积分: 200 )

  • 主题发起人 主题发起人 zhaozhh1
  • 开始时间 开始时间
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(&amp;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, &quot;&quot;);
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, &quot;&quot;);
memcpy(&amp;(lpResult.AssayTime), &amp;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, &quot;&quot;);
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, &amp;dwError, &amp;ComStat);
while( ComStat.cbInQue ==0) //接收缓冲区无数据
{
do{//等待LF
WaitCommEvent(lpDevice->hComm, &amp;dwEvtMask, NULL);
}while((dwEvtMask &amp;
EV_RXFLAG) != EV_RXFLAG);
ClearCommError(lpDevice->hComm, &amp;dwError, &amp;ComStat);
}
do{
ReadFile(lpDevice->hComm, &amp;RxChar, 1, &amp;dwReadLength, NULL);
}while(RxChar !=STX);
memset(RxBuffer, 0, c_RxBufferLength);
RxBuffer[0] =RxChar;
i =1;
do{
ReadFile(lpDevice->hComm, &amp;RxChar, 1, &amp;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, &amp;dwWrittenLength, NULL);
WriteFile(lpDevice->hRawDataFile,&quot;/x0d/x0a&quot;
, 2, &amp;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, &amp;dwReadLength, NULL);
if (dwReadLength ==0)
return nItemTotalCount;
}while(RxBuffer[0]!=STX);

i=1;
do{
ReadFile(lpDevice->hRawDataFile, &amp;(RxBuffer), 1, &amp;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;
}
 
楼主一句都翻译不出来啊?
 
太多了,都懒汉了
 
C++ 看着就是舒服啊,写这代码的人,应该是高人。
写得这么规正。
 
仅供参考,我直接替换的,不对:
//********************************************************************
// 模块: MD_CA530.cpp
// 描述: 本模块为东亚公司的CA530血凝仪的联机程序(Win95版)
// 函数:
// DLLEXPORT DWORD WINAPI CommMonitorProc( PChar 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
function FormatResult(lpDataBuffer: PChar;
lpResult: PRESULT ):integer;
begin

wSampleID: WORD ;

static SYSTEMTIME AssayTime;
static integer i;
static PChar lpbegin
Pos, lpEndPos;
PChar lpTemp;
integer j, k;
GetLocalTime(@AssayTime);
//得到系统北京时间
if ((lpbegin
Pos :=strchr(lpDataBuffer, $02)) = '') then
Result:= 0;
lpEndPos :=lpbegin
Pos;
lpEndPos := lpEndPos + c_SampleIDOff;
for(lpEndPos;*(lpEndPos) = $30;lpEndPos++);
wSampleID :=atoi(lpEndPos);
lpbegin
Pos +=c_FirstItemOff;
for(i :=0;i<c_MaxItemNum;i++)
begin

lpResult.SampleID :=wSampleID;
strcpy(lpResult.SampleType, &quot;&quot;);
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, &quot;&quot;);
memcpy(@(lpResult.AssayTime), @AssayTime, sizeof(SYSTEMTIME));
DeleteSpace(lpResult.AssayResult);
j :=strlen(lpResult.AssayResult);
lpTemp :=lpResult.AssayResult;
for(k :=0;k<j;k++,lpTemp++)
begin

if(*(lpTemp) <=$2D or or *(lpTemp) = $2F or or *(lpTemp) >=$3A)
begin

strcpy(lpResult.AssayResult2,lpResult.AssayResult);
strcpy(lpResult.AssayResult, &quot;&quot;);
break;
end
end
lpbegin
Pos +=c_EachDistance;
if (*(lpbegin
Pos) = ETX)
break;
end
Result:= (i+1);
end
//************************************************************************
//DLLEXPORT DWORD WINAPI CommMonitorProc( PChar lpData )
//
// 描述:
// 串口监控线程的启动函数
// 参数:
// PChar lpData
// 生化仪接口控制块
//************************************************************************
DWORD WINAPI CommMonitor( PChar lpData)
begin

//定义变量
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];
//存储结果
integer i, nItemCount;
//赋初始值
for (i :=0;
i<c_MaxItemNum;
i++)do
begin

strcpy(Result.InstCode, lpDevice.InstCode);
//仪器缩写
Result.ResultType :=c_Route;//c_TypeRoutine or c_TypeNumber;
Result.ErrorCode :=c_Reliable;
memset(PChar(Result.Comment), 0, c_MaxCommentLength);
end

PurgeComm( lpDevice.hComm, PURGE_RXCLEAR);
SetCommMask(lpDevice.hComm, EV_RXFLAG);
while (TRUE)
begin

//----第一步:接收数据----
ClearCommError(lpDevice.hComm, @dwError, @ComStat);
while( ComStat.cbInQue = 0) //接收缓冲区无数据
begin

do
begin
//等待LF
WaitCommEvent(lpDevice.hComm, @dwEvtMask, NULL);
end while((dwEvtMask @ EV_RXFLAG) <> EV_RXFLAG);
ClearCommError(lpDevice.hComm, @dwError, @ComStat);
end
do
begin

ReadFile(lpDevice.hComm, @RxChar, 1, @dwReadLength, NULL);
end while(RxChar <>STX);
memset(RxBuffer, 0, c_RxBufferLength);
RxBuffer[0] :=RxChar;
i :=1;
do
begin

ReadFile(lpDevice.hComm, @RxChar, 1, @dwReadLength, NULL);
RxBuffer[i++] :=RxChar;
end while(RxChar <>ETX);
//----第二步:将原始数据写入文本文件----
if (lpDevice.hRawDataFile <>INVALID_HANDLE_VALUE)
begin

SetFilePointer(lpDevice.hRawDataFile, 0, 0, FILE_END);
WriteFile(lpDevice.hRawDataFile, (PChar)RxBuffer, i, @dwWrittenLength, NULL);
WriteFile(lpDevice.hRawDataFile,&quot;/x0d/x0a&quot;
, 2, @dwWrittenLength, NULL);
end
//----第三步:处理数据----
nItemCount :=FormatResult((PChar)RxBuffer, Result);
if (nItemCount>0)
begin

(*(lpDevice.lpResultProcessRoutine))(Result, nItemCount);
lpDevice.dwRecordCount++;
lpDevice.wSampleID:=Result[nItemCount-1].SampleID;
end
//----第四步:----
end
Result:= TRUE;
end // end of CommWatchProc()
void WINAPI BeforeSetCommState(DCB *pComDcb)
begin

pComDcb.EvtChar :=ETX;
end
integer WINAPI ReadBakData(PDEVICE lpDevice)
begin

DWORD dwRxBufferLength:=0, dwReadLength:=0;

BYTE RxBuffer[c_RxBufferLength] ;//接收缓冲区
RESULT Result[c_MaxItemNum];
//存储结果
integer i, nItemCount, nItemTotalCount:=0, nMarkCount:=0;
//赋初始值
for (i :=0;
i<c_MaxItemNum;
i++)
begin

strcpy(Result.InstCode, lpDevice.InstCode);
//仪器缩写
Result.ResultType := c_Route ;//c_TypeRoutine or c_TypeNumber;
Result.ErrorCode :=c_Reliable;
memset(PChar(Result.Comment), 0, c_MaxCommentLength);
end
SetFilePointer(lpDevice.hRawDataFile, 0, 0, FILE_begin
);
while(TRUE)
begin

memset(RxBuffer, 0, c_RxBufferLength);
do
begin

ReadFile(lpDevice.hRawDataFile, RxBuffer, 1, @dwReadLength, NULL);
if (dwReadLength = 0)
Result:= nItemTotalCount;
end while(RxBuffer[0]<>STX);

i:=1;
do
begin

ReadFile(lpDevice.hRawDataFile, @(RxBuffer), 1, @dwReadLength, NULL);
if (dwReadLength = 0)
Result:= nItemTotalCount;
end while(RxBuffer[i++]<>ETX);
nItemCount :=FormatResult((PChar)RxBuffer, Result);
if (nItemCount>0)
begin

(*(lpDevice.lpResultProcessRoutine))(Result, nItemCount);
lpDevice.dwRecordCount++;
lpDevice.wSampleID:=Result[nItemCount-1].SampleID;
end
end
Result:= nItemTotalCount;
end
 
后退
顶部