首页 论坛 问答 博客
 
查看文章
 
标题:与各种PLC通信时,检验算法子程序集
2008-05-23 12:15:36

和检验程序:

char *plc_ADD(const uchar *pstr,uchar icount,uchar *pADD)
{
 uchar i,ch,ct,temp;
 if(pstr==NULL || pADD==NULL)
  return NULL;
 ch=*pstr;
 for(i=1;i {
  ch +=*(pstr+i);
 }
 temp=ch;
 ct=temp>>4;
 if(ct>9)
  ct+='A'-10;
 else
  ct+='0';
 *pADD=ct;
 ct=ch&0x0F;
 if(ct>9)
  ct+='A'-10;
 else
  ct+='0';
 *(pADD+1)=ct;
 return pADD; 
}

FCS检验程序:

char *Omron_FCS(const uchar *pstr,uchar icount,uchar *pFCS)
{
 uchar i,ch,ct,temp;
 if(pstr==NULL || pFCS==NULL)
  return NULL;
 ch=*pstr;
 for(i=1;i {
  ch ^=*(pstr+i);
 }
 temp=ch;
 ct=temp>>4;
 if(ct>9)
  ct+='A'-10;
 else
  ct+='0';
 *pFCS=ct;
 ct=ch&0x0F;
 if(ct>9)
  ct+='A'-10;
 else
  ct+='0';
 *(pFCS+1)=ct;
 return pFCS; 
}
LRC检验程序:
char *plc_LRC(const uchar *pstr,uchar icount,uchar *pLRC)
{
 uchar temp,i,ct,ch;
 if(pstr==NULL || pLRC==NULL)
  return NULL;
 for(i=0,ch=0;i {
  ct=valstr(pstr+i);
  temp=valstr(pstr+i+1);
  ch+=(ct<<4)|(temp&0x0F);
 }
 ch=0xff-ch+1;
 temp=ch;
 ct=temp>>4;
 if(ct>9)
  ct+='A'-10;
 else
  ct+='0';
 *pLRC=ct;
 ct=ch&0x0F;
 if(ct>9)
  ct+='A'-10;
 else
  ct+='0';
 *(pLRC+1)=ct;
 return pLRC;
}


本文引用通告地址:http://aax1985.spaces.eepw.com.cn/articles/trackback/item/23889
类别:技术资料 | 浏览(109) 引用(0)
 
网友评论:
发表评论:
姓 名: [ 登陆 ]
内 容:
验证码:
 

     
©2007 eepw.com.cn