/// 获取校验和,ASCII编码
/// </summary>
/// <param name="s"></param>
/// <param checkSum="s"></param>
#region 获取校验和,ASCII编码
/// <summary>
/// 获取校验和,ASCII编码
/// </summary>
/// <param name="s"></param>
/// <param checkSum="s"></param>
private bool GetCheckSum( string s , out string checkSum )
{
checkSum = ""
if ( 0 == s.Length )
return false
int sIndex = s.IndexOf( '$' ) + 1
int eIndex = s.IndexOf( "**" )
string str = ""
if ( sIndex <1 || eIndex <1 )
str = s
else
str = s.Substring( sIndex , eIndex - sIndex )
byte [] cs = Encoding.ASCII.GetBytes( str )
//核心部分
for ( int i = 0 i <cs.Length - 1 i++ )
{
cs [i + 1] = (byte) ( cs [i] ^ cs [i + 1] )
}
checkSum = cs [cs.Length - 1].ToString( "x2" ).ToUpper()
//checkSum = Convert.ToString( cs [cs.Length - 1] , 16 ).ToUpper()
return true
}
你是想把checksum.exe运行后出现的信息写到txt是吧?比如这程序放在c:\
start c:\checksum.exe >c:\1.txt
如果它有反馈信息,就会写在c盘中1.txt里面
//========================================|功能函数//计算效验和
uint8
CHECK_SUM(uint8
*pt,uint8
pos,uint8
len)
reentrant
{
uint8
CHECKSUM=0
pt+=pos
//预置指针到pos
while(len--)
{
if(*pt
&
BIT0){CHECKSUM++}
if(*pt
&
BIT1){CHECKSUM++}
if(*pt
&
BIT2){CHECKSUM++}
if(*pt
&
BIT3){CHECKSUM++}
if(*pt
&
BIT4){CHECKSUM++}
if(*pt
&
BIT5){CHECKSUM++}
if(*pt
&
BIT6){CHECKSUM++}
if(*pt
&
BIT7){CHECKSUM++}
pt++
}
//
F_Wtd
return
CHECKSUM
}
//========================================|
用法:
tmp=CHECK_SUM(UART_BUF,0,UART_RX_LEN)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)