📄 pcom.cpp
字号:
#include <vcl.h>
#pragma hdrstop
#include "mn.h"
#include "csh.h"
#include "loop3.h"
#include "unit1.h"
#include "Pcom.h"
#pragma package(smart_init)
int LoopFrequenz[8];
int KalPunkte[11];
int KalAnalog[10];
AnsiString KalPunkteStr[10];
AnsiString KalAnalogStr[10];
int SysParameter[25];
int SysFactor[44];
struct
{
int MessNummer;
int Geschwindigkeit;
int AchsAnzahl;
long int GesamtGewicht;
int AchsGewichte[10];
int AchsAbstaende[10];
} FzgDaten;
bool NeuesGewicht;
int DAW50Gewicht;
int DirektWert ;
bool Send1Tel_OK=false;
bool DynMode_OK =false;
bool StaMode_OK =false;
bool ZeroSet_OK =false;
bool StartoV_OK =false;
bool ComplV_OK =false;
bool EndoV_OK =false;
bool ReqStat_OK =false;
bool KalDat_OK =false;
bool KalPkt_OK =false;
bool NeuesFzg =false;
bool NeuesFzgAll=false;
bool NeueDigIn =true;
bool NeueLoops =true;
bool NeueFrequenz=false;
bool NeueUhrZeit =true;
unsigned char DigInByte =0;
unsigned char DigInByte2 =0;
unsigned char DigOutByte =0;
unsigned char DigOutByte2=0;
unsigned char LoopByte =0;
unsigned char LoopByte2 =0;
unsigned char WaageByte =0;
//for the thread;
HANDLE hMutex;
//for no values;
AnsiString disStr=""; //发送显示字符串
AnsiString recDisStr=""; //接收显示字符串
int chVal;
bool displ=true;
// ************************************************************)
//(* Receiver fuer COM1 --> DAW400 / DAW50 *)
//***************************************************************)
void ReceiveCom1()
{
//for declare;
int ret;
int data;
int InPtr;
bool ready;
unsigned char Chk,Kenn1,Kenn2;
unsigned char ByteZaehler,ByteAnzahl;
unsigned char DatenByte[256];
//for init;
ready=false;
InPtr=0;
Chk=0;
hMutex=CreateMutex(0,false,0);
ret = sio_open(com1);
if ( ret != SIO_OK )
{
ShowMessage("无法打开端口!");
}
ret = sio_ioctl ( com1, B19200, P_NONE | BIT_8 | STOP_2 );
if (ret != SIO_OK)
{
ShowMessage("无法打开端口!");
}
while(true)
{
data= sio_getch(com1);
if (data>=0)
{
if(!ready)
{
switch(InPtr)
{
case 0 :
Chk=Byte(-0x55);
if(data==0x55 )
{
InPtr++;
}
break;
case 1 :
Kenn1=data;
Chk-=Kenn1;
InPtr++;
break;
case 2 :
Kenn2=data;
Chk-=Kenn2;
InPtr++;
break;
case 3 :
ByteZaehler=0;
ByteAnzahl =data;
Chk-=ByteAnzahl;
if(ByteAnzahl>0)
InPtr++;
else
InPtr=InPtr+2;
break;
case 4 :
DatenByte[ByteZaehler]=data;
Chk-=data;
ByteZaehler++;
if(ByteZaehler>=ByteAnzahl)
InPtr++;
break;
case 5 :
if(data==0xaa)
{
Chk-=data;
InPtr++;
}
else
InPtr=0;
break;
case 6 :
if(data==Chk)
{
ready=true;
InPtr=0;
}
else
InPtr=0;
}//for swtich;
}//for not Fertig;
}//for data is empty;
if(ready)
{
if (Kenn2==Tel_OK) //Tel_OK=0x20
{
Send1Tel_OK=true; //发送报文成功
switch(Kenn1)
{
case StartoV_T : //开始信息响应
StartoV_OK=true;
case ComplV_T : //
ComplV_OK =true;
case EndoV_T : //结束信息响应
EndoV_OK =true;
case KalPkt_T : //校准信息响应
KalPkt_OK =true;
case ZeroSet_T : //零点信息设置响应
ZeroSet_OK=true;
}
}
else
{
switch(Kenn1)
{
case DynMode_T:
case StaMode_T:
case StartoV_T:
case KalPkt_T :
case ReqStat_T:
case ZeroSet_T:
case Cominit_T: //不考虑响应信息
case EndoV_T : //结束信号,接收数据
if(ByteAnzahl>0)
{
FzgDaten.MessNummer=DatenByte[0]*256+DatenByte[1];
FzgDaten.Geschwindigkeit=DatenByte[2]*256+DatenByte[3];
FzgDaten.AchsAnzahl=DatenByte[4];
FzgDaten.GesamtGewicht=0;
for (int k=0;k<9;k++)
{
FzgDaten.AchsGewichte [k]=0;
FzgDaten.AchsAbstaende[k]=0;
}
for(int i=1;i<=FzgDaten.AchsAnzahl;i++)
{
FzgDaten.AchsGewichte[i]=0;
FzgDaten.AchsAbstaende[i]=0;
FzgDaten.AchsGewichte[i]=DatenByte[i*4+1]*256+DatenByte[i*4+2];
FzgDaten.AchsAbstaende[i]=DatenByte[i*4+3]*256+DatenByte[i*4+4];
FzgDaten.GesamtGewicht+=FzgDaten.AchsGewichte[i];
}
}
NeuesFzg=true;
ConvRecStr(0x55);
Form5->Memo2->Lines->Add(recDisStr);
recDisStr="";
break;
case Comsend_T :
/*if (ByteAnzahl==SendSio.Return)
{
for(int i=0;i<ByteAnzahl;i++)
{
SendSio.Daten[i+3]=DatenByte[i];
SendSio.Delay= 0;
}
}
*/
break;
case Digin_T :
/* recDisStr="";
ConvRecStr(0x55);
ConvRecStr(Kenn1);
Form5->Memo2->Lines->Add(recDisStr); */
if(ByteAnzahl>0)
{
DigInByte=DatenByte[0];
if (ByteAnzahl>1)
{
DigInByte2= DatenByte[1];
NeueDigIn = true;
}
};
break;
case Loop_T :
if(ByteAnzahl>0)
{
LoopByte=DatenByte[0];
WaageByte=DatenByte[1];
if(ByteAnzahl>2)
{
LoopByte2=DatenByte[2];
NeueLoops=true;
}
}
break;
case Freq_T :
if(ByteAnzahl>0)
{
for(int i=0;i<8;i++)
LoopFrequenz[i]=DatenByte[i*2]+DatenByte[i*2+1]*256;
NeueFrequenz=true;
}
break;
case Displ_T :
if(!NeuesGewicht )
{
NeuesGewicht=true;
DAW50Gewicht=DatenByte[0]*256 + DatenByte[1] ;
}
break;
case AxleWgh_T:
if(ByteAnzahl>0)
{
}
break;
/*
case ComplV_T :
if(ByteAnzahl>0)
With FzgDatenAll do
Begin
With LowSpeed[DatenByte[4]] do
Begin
A001 := DatenByte[ 4];
A := DatenByte[ 4];
T1 := ((( DatenByte[ 5] * 256 ) + DatenByte[ 6] ) * 256 + DatenByte[ 7] ) * 256
+ DatenByte[ 8];
T2 := ((( DatenByte[ 9] * 256 ) + DatenByte[10] ) * 256 + DatenByte[11] ) * 256
+ DatenByte[12];
T3 := ((( DatenByte[13] * 256 ) + DatenByte[14] ) * 256 + DatenByte[15] ) * 256
+ DatenByte[16];
T4 := ((( DatenByte[17] * 256 ) + DatenByte[18] ) * 256 + DatenByte[19] ) * 256
+ DatenByte[20];
Abst := ((( DatenByte[21] * 256 ) + DatenByte[22] ) * 256 + DatenByte[23] ) * 256
+ DatenByte[24];
Gesch := ((( DatenByte[25] * 256 ) + DatenByte[26] ) * 256 + DatenByte[27] ) * 256
+ DatenByte[28];
GZ := ((( DatenByte[29] * 256 ) + DatenByte[30] ) * 256 + DatenByte[31] ) * 256
+ DatenByte[32];
GI := ((( DatenByte[33] * 256 ) + DatenByte[34] ) * 256 + DatenByte[35] ) * 256
+ DatenByte[36];
M := ((( DatenByte[37] * 256 ) + DatenByte[38] ) * 256 + DatenByte[39] ) * 256
+ DatenByte[40];
NP := ( DatenByte[41] * 256 ) + DatenByte[42];
WGT := ( DatenByte[43] * 256 ) + DatenByte[44];
NeuesFzgAll := True;
End;
With HiSpeed[DatenByte[48]] do
Begin
A := DatenByte[48];
T1 := ((( DatenByte[49] * 256 ) + DatenByte[50] ) * 256 + DatenByte[51] ) * 256
+ DatenByte[ 8];
T2 := ((( DatenByte[53] * 256 ) + DatenByte[54] ) * 256 + DatenByte[55] ) * 256
+ DatenByte[56];
T3 := ((( DatenByte[57] * 256 ) + DatenByte[58] ) * 256 + DatenByte[59] ) * 256
+ DatenByte[60];
T4 := ((( DatenByte[61] * 256 ) + DatenByte[62] ) * 256 + DatenByte[63] ) * 256
+ DatenByte[64];
Abst := ((( DatenByte[65] * 256 ) + DatenByte[66] ) * 256 + DatenByte[67] ) * 256
+ DatenByte[68];
Gesch := ((( DatenByte[69] * 256 ) + DatenByte[70] ) * 256 + DatenByte[71] ) * 256
+ DatenByte[72];
GI := ((( DatenByte[77] * 256 ) + DatenByte[78] ) * 256 + DatenByte[79] ) * 256
+ DatenByte[80];
M := ((( DatenByte[81] * 256 ) + DatenByte[82] ) * 256 + DatenByte[83] ) * 256
+ DatenByte[84];
NP := ( DatenByte[85] * 256 ) + DatenByte[86];
WGT := ( DatenByte[87] * 256 ) + DatenByte[88];
End;
End; */
case Param_T:
if(ByteAnzahl>0)
{
for(int i=0;i<26;i++)
SysParameter[i]=DatenByte[i*2+1] * 256 +DatenByte[i*2];
SysParameter[26]=DatenByte[52];
}
break;
case CLW_P_T:
if(ByteAnzahl>0)
{
for(int i=0;i<28;i++) //12->28
SysFactor[i]=DatenByte[i*2] * 256 +DatenByte[i*2+1];
}
break;
case KalDat_T:
if(ByteAnzahl>0)
{
KalDat_OK=true;
for(int i=0;i<10;i++)
{
KalAnalog [i]=DatenByte[i*2]*256+DatenByte[i*2+1];
KalPunkte [i]=DatenByte[i*2+20]*256+DatenByte[i*2+21];
}
}
break;
}//for switch();
}//tel ok;
ready=false;
}//for ready;
}//for while
}
////for send
//(****************************************************************************)
//(* *)
//(* Send1Telegramm *)
//(* *)
//(****************************************************************************)
void Send1Telegramm ( unsigned char Kenn1,unsigned char Kenn2)
{
int I,ret;
unsigned char Chk;
I=0;
I++;
disStr="";
WaitForSingleObject(hMutex,INFINITE);
Send1Tel_OK = false;
switch(Kenn1)
{
case Displ_T :
case Direkt_T :
case StartoV_T:
case AxleWgh_T:
case EndoV_T :
case ReqStat_T:
// case Param_T :
case ComplV_T :
case DynMode_T:
case StaMode_T:
case ZeroSet_T:
case Digin_T :
case Freq_T :
case Loop_T :
Chk=Byte(-(0x55+Kenn1+Kenn2+0xAA));
do
{
ret=sio_putch (com1,0x55);
}
while(ret!=1);
disStr+="55 ";
do
{
ret=sio_putch (com1,Kenn1);
}
while(ret!=1);
if (ret==1)
{
Convstr(Kenn1);
}
do
{
ret=sio_putch (com1,Kenn2);
}
while(ret!=1);
if (ret==1)
{
Convstr(Kenn2);
}
do
{
ret=sio_putch (com1,0x00);
}
while(ret!=1);
do
{
ret=sio_putch (com1,0xAA);
}
while(ret!=1);
disStr+="00 AA ";
do
{
ret=sio_putch (com1,Chk);
}
while(ret!=1);
if (ret==1)
{
Convstr(Chk);
}
break;
case KalDat_T :
if(Kenn2==0x01 ) //显示
{
KalDat_OK =false;
Chk =Byte(-(0x55+Kenn1+Kenn2+0xAA));
do
{
ret=sio_putch (com1,0x55);
}
while(ret!=1);
do
{
ret=sio_putch (com1,Kenn1);
}
while(ret!=1);
do
{
ret=sio_putch (com1,Kenn2);
}
while(ret!=1);
do
{
ret=sio_putch (com1,0x00);
}
while(ret!=1);
do
{
ret=sio_putch (com1,0xAA);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -