📄 comm.cpp
字号:
para.integer=theApp.setpt[theApp.Pid_Channel];
break;
case 0x03:theApp.setpt[3]=(int)(theApp.rh3_temper_set*10);
para.integer=theApp.setpt[theApp.Pid_Channel];
break;
}
Com1_TxdBuffer[40]=para.B.B0;
Com1_TxdBuffer[41]=para.B.B1;
Com1_TxdBuffer[42]=para.B.B2;
Com1_TxdBuffer[43]=para.B.B3;
para.integer=theApp.slew[theApp.Pid_Channel];
Com1_TxdBuffer[44]=para.B.B0;
Com1_TxdBuffer[45]=para.B.B1;
Com1_TxdBuffer[46]=para.B.B2;
Com1_TxdBuffer[47]=para.B.B3;
para.integer=theApp.scale[theApp.Pid_Channel];
Com1_TxdBuffer[48]=para.B.B0;
Com1_TxdBuffer[49]=para.B.B1;
Com1_TxdBuffer[50]=para.B.B2;
Com1_TxdBuffer[51]=para.B.B3;
para.integer=theApp.zero[theApp.Pid_Channel];
Com1_TxdBuffer[52]=para.B.B0;
Com1_TxdBuffer[53]=para.B.B1;
Com1_TxdBuffer[54]=para.B.B2;
Com1_TxdBuffer[55]=para.B.B3;
para.integer=theApp.integral[theApp.Pid_Channel];
Com1_TxdBuffer[56]=para.B.B0;
Com1_TxdBuffer[57]=para.B.B1;
Com1_TxdBuffer[58]=para.B.B2;
Com1_TxdBuffer[59]=para.B.B3;
EscapeCommFunction(Com1_idComDev,SETRTS);//置发送允许,但是不发送
ch=0;
for (i=1; i<60; i++) ch=ch+Com1_TxdBuffer[i];
Com1_TxdBuffer[60]=ch;
Com1_dwLengthTX=(DWORD)61;
Com1_WorkStatus = NOUSER; //0x4000;
theApp.Pid_Channel++;
break;
case 0x04: //装参数
Com1_TxdBuffer[1]=0x16; //len
Com1_TxdBuffer[2]=0x04; //cmd
work.Word=theApp.PW_Count;
Com1_TxdBuffer[3]= work.B.Low;
Com1_TxdBuffer[4]= work.B.High;
work.Word=theApp.PW_Length;
Com1_TxdBuffer[5]= work.B.Low;
Com1_TxdBuffer[6]= work.B.High;
work.Word=theApp.Bjmd_speed;
Com1_TxdBuffer[7]= work.B.Low;
Com1_TxdBuffer[8]= work.B.High;
Com1_TxdBuffer[9]= 0;
Com1_TxdBuffer[10]=0;
Com1_TxdBuffer[11]=0;
Com1_TxdBuffer[12]=0;
Com1_TxdBuffer[13]=0;
Com1_TxdBuffer[14]=0;
Com1_TxdBuffer[15]=0;
Com1_TxdBuffer[16]=0;
Com1_TxdBuffer[17]=0;
Com1_TxdBuffer[18]=0;
Com1_TxdBuffer[19]=0;
Com1_TxdBuffer[20]=0;
Com1_TxdBuffer[21]=0;
Com1_TxdBuffer[22]=0;
Com1_TxdBuffer[23]=0;
Com1_TxdBuffer[24]=0;
EscapeCommFunction(Com1_idComDev,SETRTS);//置发送允许,但是不发送
ch=0;
for (i=1; i<25; i++) ch=ch+Com1_TxdBuffer[i];
Com1_TxdBuffer[25]=ch;
Com1_dwLengthTX=(DWORD)26;
Com1_WorkStatus = NOUSER; //0x4000;
break;
case 0x05: Com1_TxdBuffer[1]=0x00; //len 复归
Com1_TxdBuffer[2]=0x08; //cmd
Com1_TxdBuffer[3]=0x08;
Com1_dwLengthTX=(DWORD)4;
Com1_WorkStatus = NOUSER; //0x4000;
break;
case 0x06: //配置4018
/* 0AAH SYN */
/* 005H LEN 0 */
/* 005H CMD 1 */
/* old4018_node 2 */
/* new4018_node 3 */
/* TT 4 */
/* CC 5 */
/* FF 6 */
/* SUM 7 */
Com1_TxdBuffer[1]=0x05; //len
Com1_TxdBuffer[2]=0x09; //cmd
Com1_TxdBuffer[3]=0x01; //theApp.old4018_node;
Com1_TxdBuffer[4]=0x00; //theApp.new4018_node;
Com1_TxdBuffer[5]=theApp.U4018_TT;
Com1_TxdBuffer[6]=theApp.U4018_CC;
Com1_TxdBuffer[7]=theApp.U4018_FF;
EscapeCommFunction(Com1_idComDev,SETRTS);//置发送允许,但是不发送
ch=0;
for (i=1; i<8; i++) ch=ch+Com1_TxdBuffer[i];
Com1_TxdBuffer[8]=ch;
Com1_dwLengthTX=(DWORD)9;
Com1_WorkStatus = NOUSER;
break;
case 0x07: //配置4012
/* 0AAH SYN */
/* 005H LEN 0 */
/* 005H CMD 1 */
/* old4012_node 2 */
/* new4012_node 3 */
/* TT 4 */
/* CC 5 */
/* FF 6 */
/* SUM 7 */
Com1_TxdBuffer[1]=0x05; //len
Com1_TxdBuffer[2]=0x0A; //cmd
Com1_TxdBuffer[3]=0x02; //theApp.old4012_node;
Com1_TxdBuffer[4]=0x00; //theApp.new4012_node;
Com1_TxdBuffer[5]=theApp.U4012_TT;
Com1_TxdBuffer[6]=theApp.U4012_CC;
Com1_TxdBuffer[7]=theApp.U4012_FF;
EscapeCommFunction(Com1_idComDev,SETRTS);//置发送允许,但是不发送
ch=0;
for (i=1; i<8; i++) ch=ch+Com1_TxdBuffer[i];
Com1_TxdBuffer[8]=ch;
Com1_dwLengthTX=(DWORD)9;
Com1_WorkStatus = NOUSER;
break;
case 0x08: //配置4021
/* 0AAH SYN */
/* 005H LEN 0 */
/* 005H CMD 1 */
/* old4012_node 2 */
/* new4012_node 3 */
/* TT 4 */
/* CC 5 */
/* FF 6 */
/* SUM 7 */
Com1_TxdBuffer[1]=0x05; //len
Com1_TxdBuffer[2]=0x0B; //cmd
Com1_TxdBuffer[3]=0x02; //theApp.old4021_node;
Com1_TxdBuffer[4]=0x00; //theApp.new4021_node;
Com1_TxdBuffer[5]=theApp.U4021_TT;
Com1_TxdBuffer[6]=theApp.U4021_CC;
Com1_TxdBuffer[7]=theApp.U4021_FF;
EscapeCommFunction(Com1_idComDev,SETRTS);//置发送允许,但是不发送
ch=0;
for (i=1; i<8; i++) ch=ch+Com1_TxdBuffer[i];
Com1_TxdBuffer[8]=ch;
Com1_dwLengthTX=(DWORD)9;
Com1_WorkStatus = NOUSER;
break;
default: break;
};
Com1_RxdBuffer[0]=0;
Com1_RxdBuffer[1]=0;
Com1_RxdBuffer[2]=0;
}
//////////////////////////////////////////////////////////////////////////
// MakeFrame
void Ccomm::MakeFrame2(int idCommand)
{
UINT crcCode;
int i,len,m,k,j;
short int sum;
union WDAT work;
unsigned char ch,c;
unsigned int ui;
double dx;
union IWDAT para;
Com2_TxdBuffer[0]=0x02; //开始标志0x02
switch(idCommand)
{
case 0x00: //松下PLC
/* 0EBH 00*/
/* 090H 01*/
/* 0EBH 02*/
/* 090H 03*/
/* 0EBH 04*/
/* 090H 05*/
/* Length =35 06*/
/* Command=00 07*/
/* Control.Low 08*/
/* Control.High 09*/
/* Top.Low 10*/
/* Top.High 11*/
/* Bottom.Low 12*/
/* Bottom.High 13*/
/* Left.Low 14*/
/* Left.High 15*/
/* Right.Low 16*/
/* Right.High 17*/
/* bak 18*/
/* bak 19*/
/* bak 20*/
/* bak 21*/
/* bak 22*/
/* bak 23*/
/* bak 24*/
/* bak 25*/
/* bak 26*/
/* bak 27*/
/* bak 28*/
/* bak 29*/
/* bak 30*/
/* bak 31*/
/* bak 32*/
/* bak 33*/
/* bak 34*/
/* bak 35*/
/* bak 36*/
/* bak 37*/
/* bak 38*/
/* bak 39*/
/* XXH SUM 40*/
Com2_TxdBuffer[1] =0x20;
Com2_TxdBuffer[2] =0x2b;// +// 报文长度
Com2_TxdBuffer[3] =0x30;
Com2_TxdBuffer[4] =0x30;
Com2_TxdBuffer[5] =0x30;
Com2_TxdBuffer[6] =0x30;
Com2_TxdBuffer[7] =0x30;
Com2_TxdBuffer[8] =0x31;
Com2_TxdBuffer[9] =0x31;
Com2_TxdBuffer[10]=0x30;
if(theApp.WorkMode==0)
{//正常运行
theApp.plc_control=theApp.plc_control & 0xfffb;
}else
{//经济运行
theApp.plc_control=theApp.plc_control | 0x04;
}
if(theApp.yxtask.BitTestChar(theApp.yxtask.yxbuf,126))
{//复位
theApp.plc_control=theApp.plc_control | 0x08;
}else
{
theApp.plc_control=theApp.plc_control & 0xfff7;
}
if(theApp.yxtask.BitTestChar(theApp.yxtask.yxbuf,1))
{//紧急停止
theApp.plc_control=theApp.plc_control | 0x10;
}else
{
theApp.plc_control=theApp.plc_control & 0xffef;
}
if(theApp.yxtask.BitTestChar(theApp.yxtask.yxbuf,134))
{//波峰一
theApp.plc_control=theApp.plc_control | 0x20;
}else
{
theApp.plc_control=theApp.plc_control & 0xffdf;
}
if(theApp.yxtask.BitTestChar(theApp.yxtask.yxbuf,135))
{//波峰二
theApp.plc_control=theApp.plc_control | 0x40;
}else
{
theApp.plc_control=theApp.plc_control & 0xffbf;
}
if(theApp.yxtask.BitTestChar(theApp.yxtask.yxbuf,127))
{//熔锡状态
theApp.plc_control=theApp.plc_control | 0x80;
}else
{
theApp.plc_control=theApp.plc_control & 0xff7f;
}
if(theApp.yxtask.BitTestChar(theApp.yxtask.yxbuf,57))
{//板宽设置
theApp.plc_control=theApp.plc_control | 0x0100;
}else
{
theApp.plc_control=theApp.plc_control & 0xfeff;
}
if(theApp.yxtask.BitTestChar(theApp.yxtask.yxbuf,129))
{//开机(1) 关机(0)
theApp.plc_control=theApp.plc_control | 0x0200;
}else
{
theApp.plc_control=theApp.plc_control & 0xfDff;
}
if(theApp.yxtask.BitTestChar(theApp.yxtask.yxbuf,128))
{//自动(1) 手动(0)
theApp.plc_control=theApp.plc_control | 0x0400;
}else
{
theApp.plc_control=theApp.plc_control & 0xfBff;
}
work.Word=theApp.plc_control;
ch=work.B.High;
Com2_TxdBuffer[11] =0x20;
Com2_TxdBuffer[12]=0x2b;// +// 控制字
c=ch%10; ch=ch/10;
Com2_TxdBuffer[20]=0x30+c;
c=ch%10; ch=ch/10;
Com2_TxdBuffer[19]=0x30+c;
c=ch%10;
Com2_TxdBuffer[18]=0x30+c;
Com2_TxdBuffer[17]=0x30;
Com2_TxdBuffer[16]=0x30;
Com2_TxdBuffer[15]=0x30;
Com2_TxdBuffer[14]=0x30;
Com2_TxdBuffer[13]=0x30;
ch=work.B.Low;
Com2_TxdBuffer[21] =0x20;
Com2_TxdBuffer[22] =0x2b;// +// 控制字
c=ch%10; ch=ch/10;
Com2_TxdBuffer[30] =0x30+c;
c=ch%10; ch=ch/10;
Com2_TxdBuffer[29] =0x30+c;
c=ch%10;
Com2_TxdBuffer[28]=0x30+c;
Com2_TxdBuffer[27]=0x30;
Com2_TxdBuffer[26]=0x30;
Com2_TxdBuffer[25]=0x30;
Com2_TxdBuffer[24]=0x30;
Com2_TxdBuffer[23]=0x30;
j= theApp.PW_Length;//喷雾长度
j=j/10;
HexAsc(&Com2_TxdBuffer[31],j);
j= theApp.PW_Count;//喷雾原点
j=j/10;
HexAsc(&Com2_TxdBuffer[41],j);
j= theApp.PW_With; //喷雾宽度
j=j/10;
HexAsc(&Com2_TxdBuffer[51],j);
j= theApp.Bjmd_speed; //步进速率
j=j/50;
if(j<5) j=5;
HexAsc(&Com2_TxdBuffer[61],j);//5---20
j= theApp.boardbase; //板宽基数
HexAsc(&Com2_TxdBuffer[71],j);//5---20
j = theApp.jjrun_len; //经济超前
j = j/10;
HexAsc(&Com2_TxdBuffer[81],j);
j = theApp.jjback_len; //经济滞后
j = j/10;
HexAsc(&Com2_TxdBuffer[91],j);
/* for(i=0;i<1;i++)
{
Com2_TxdBuffer[i*10+91+0]=0x20;
Com2_TxdBuffer[i*10+91+1]=0x2b;
Com2_TxdBuffer[i*10+91+2]=0x30;
Com2_TxdBuffer[i*10+91+3]=0x30;
Com2_TxdBuffer[i*10+91+4]=0x30;
Com2_TxdBuffer[i*10+91+5]=0x30;
Com2_TxdBuffer[i*10+91+6]=0x30;
Com2_TxdBuffer[i*10+91+7]=0x30;
Com2_TxdBuffer[i*10+91+8]=0x30;
Com2_TxdBuffer[i*10+91+9]=0x30;
}
*/
sum=0;
for(i=0;i<50;i++)
{
work.B.Low =Com2_TxdBuffer[i*2+1];
work.B.High=Com2_TxdBuffer[i*2+2];
sum=sum+(short int)work.Word;
}
j=sum;
HexAsc(&Com2_TxdBuffer[101],j);
Com2_TxdBuffer[111]=0x0d;
Com2_dwLengthTX=(DWORD)112;
Com2_WorkStatus = NOUSER;
break;
default: break;
};
Com2_RxdBuffer[0]=0;
Com2_RxdBuffer[1]=0;
Com2_RxdBuffer[2]=0;
}
void Ccomm::ScanDataPlc()
{
Com2_Repeate = 0;
Com2_TimeOut = 0;
MakeFrame2(0);
SendFrame2();
}
void Ccomm::HexAsc(unsigned char *buf, int j)
{
unsigned char c;
buf[0]=0x20;
if(j>=0)
{
buf[1]=0x2b;
}else
{
buf[1]=0x2d;
j=-j;
}
c=j%10; j=j/10;
buf[9]=0x30+c;
c=j%10; j=j/10;
buf[8]=0x30+c;
c=j%10; j=j/10;
buf[7]=0x30+c;
c=j%10;j=j/10;
buf[6]=0x30+c;
c=j%10;
buf[5]=0x30+c;
buf[4]=0x30;
buf[3]=0x30;
buf[2]=0x30;
}
void Ccomm::ScanData()
{
Com1_Repeate = 0;
Com1_TimeOut = 0;
MakeFrame1(0);
SendFrame1();
}
void Ccomm::AskTemperPara()
{
Com1_Repeate = 0;
Com1_TimeOut = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -