uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
if((unsigned char)uTmp!=uReceive[number*4+3])return(FALSE);
uTmp=(uSum>>4)&0xf;
uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
if((unsigned char)uTmp!=uReceive[number*4+2])return(FALSE);
for(j=0;j
{ for(i=j*4+1;i
uReceive[i]=(uReceive[i]>0x39)?uReceive[i]-0x41+0xa:uReceive[i]-0x30;
uRead_value[j]=(((((uReceive[j*4+3]<<4)+uReceive[j*4+4])<<4)+uReceive[j*4+1])<<4)+uReceive[j*4+2];
}
return TRUE;
}
int write_data_register(unsigned int uAddress,unsigned int number)
{ int i;
for(i=0;i<3;i++)
if(_write_data_register(uAddress,number)==TRUE)
return TRUE;
return FALSE;
}
int _write_data_register(unsigned int uAddress,unsigned int number)
{ unsigned char uSend[111];
unsigned int uTmp,uSum,num;
long lTmp;
int i;
if(TESTING==1)return TRUE;
init_plc();
uSend[0]=2;
uSend[1]=0x31;
uSend[number*4+8]=3;
num=(number*2)/16;
if(num>=10)uSend[6]=num+0x41-10;
else uSend[6]=num+0x30;
num=(number*2)%16;
if(num>=10)uSend[7]=num+0x41-10;
else uSend[7]=num+0x30;
uAddress=0x1000+2*uAddress;
uTmp=uAddress&0x000f;
uSend[5]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>4)&0x000f;
uSend[4]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>8)&0x000f;
uSend[3]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>12)&0x000f;
uSend[2]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
for(i=0;i
{
uTmp=uWrite_value[i]&0x000f;
uSend[i*4+9]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uWrite_value[i]>>4)&0x000f;
uSend[i*4+8]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uWrite_value[i]>>8)&0x000f;
uSend[i*4+11]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uWrite_value[i]>>12)&0x000f;
uSend[i*4+10]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
}
uSum=0;
for(i=1;i<9+number*4;i++)
uSum+=uSend[i];
uTmp=uSum&0x000f;
uSend[number*4+10]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uSum>>4)&0x000f;
uSend[number*4+9]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
for(i=0;i<11+number*4;i++)
{ for(lTmp=0L;lTmp
{ if((inportb(STATS_PORT)&0x20)!=0)
break;
}
if(lTmp>=DELAY_TIMES)
{
/*enable();*/
return(FALSE);
}
outportb(DATA_PORT,uSend[i]);
}
disable();
for(lTmp=0L;lTmp
{ if((inportb(STATS_PORT)&1)!=0)
break;
}
if(lTmp>=DELAY_TIMES)
{
enable();
return(FALSE);
}
if(inportb(DATA_PORT)!=6)
{
enable();
return(FALSE);
}
else
{
enable();
return(TRUE);
}
}
int force_m_contact(unsigned uAddress,unsigned char ucOn_off)
{ int i;
for(i=0;i<3;i++)
if(_force_m_contact(uAddress,ucOn_off)==TRUE)
return TRUE;
return FALSE;
}
int _force_m_contact(unsigned uAddress,unsigned char ucOn_off)
{ unsigned uSend[]={2,0x37,0x30,0x30,0x30,0x30,3,0x30,0x30};
unsigned uTmp,uSum,i;
long lTmp;
if(TESTING==1)return TRUE;
init_plc();
uAddress=uAddress+0x800;
uSend[1]=ucOn_off;
uTmp=uAddress&0x000f;
uSend[3]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>4)&0x000f;
uSend[2]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>8)&0x000f;
uSend[5]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>12)&0x000f;
uSend[4]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uSum=0;
for(i=1;i<7;i++)
uSum+=uSend[i];
如果觉得《plc通信程序 c语言 三菱PLC编程口通信C语言源代码(3)》对你有帮助,请点赞、收藏,并留下你的观点哦!