if(TESTING==1)
{ for(i=0;i<number;i++)uRead_value[i]=0;
return TRUE;
}
init_plc();
num=number;
if((num/16)>=10)
uSend[6]=(unsigned char)(num/16+0x41-10);
else
uSend[6]=(unsigned char)(num/16+0x30);
if((num%16)>=10)
uSend[7]=(unsigned char)((num%16)+0x41-10);
else
uSend[7]=(unsigned char)((num%16)+0x30);
uAddress=uAddress/8+0x100;
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);
uSum=0;
for(i=1;i<9;i++)
uSum=uSum+(unsigned char)uSend[i];
uTmp=uSum&0x000f;
uSend[10]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uSum>>4)&0x000f;
uSend[9]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
for(i=0;i<11;i++)
{ for(lTmp=0L;lTmp<DELAY_TIMES;lTmp++)
{ if((inportb(STATS_PORT)&0x20)!=0)
break;
}
if(lTmp>=DELAY_TIMES)
{
/*enable();*/
return(FALSE);
}
outportb(DATA_PORT,uSend[i]);
}
disable();
for(lTmp=0;lTmp<DELAY_TIMES;lTmp++)
{ if((inportb(STATS_PORT)&1)!=0)
break;
}
if(lTmp>=DELAY_TIMES)
{
enable();
return(FALSE);
}
uReceive[0]=inportb(DATA_PORT);
if(uReceive[0]!=2)
{
enable();
return(FALSE);
}
for(i=1;i<number*2+4;i++)
{ for(lTmp=0L;lTmp<DELAY_TIMES;lTmp++)
{ if((inportb(STATS_PORT)&1)!=0)
break;
}
if(lTmp>=DELAY_TIMES)
{
enable();
return(FALSE);
}
uReceive[i]=inportb(DATA_PORT);
}
enable();
uSum=0;
for(i=1;i<number*2+2;i++)
uSum=uSum+(unsigned int)uReceive[i];
uTmp=uSum&0xf;
uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
if((unsigned char)uTmp!=uReceive[number*2+3])return(FALSE);
uTmp=(uSum>>4)&0xf;
uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
if((unsigned char)uTmp!=uReceive[number*2+2])return(FALSE);
for(j=0;j<number;j++)
{ for(i=j*2+1;i<j*2+3;i++)
uReceive[i]=(uReceive[i]>0x39)?uReceive[i]-0x41+0xa:uReceive[i]-0x30;
uRead_value[j]=((uReceive[j*2+1])<<4)+uReceive[j*2+2];
}
return TRUE;
}
上一篇:三菱plc基本结构和原理概述