刚入门 还是给代码吧
//发送卡寄存器
int byteLength = 516;
Byte outdate[byteLength];
memset(outdate, 0x00, byteLength);
outdate[0]=(Byte)0xaa;
outdate[1]=0x55;
outdate[2]=0x01;// 包类型,01写发送卡寄存器
for (int i=0; i<256; i++) {
outdate[2*i+3]=0xFF;
outdate[2*i+4]=0xFF;
}
//计算校验码
Byte sumByte = 0;
for (int j=0; j<(byteLength-1); j++) {
sumByte += outdate[j];
}
//校验码计算(包头到校验码前所有字段求和取反+1)
outdate[(byteLength-1)]=~(sumByte)+1;
long tag = outdate[1];
DLog(@"恢复默认列表 = %d",(int)commandType);
DLog(@"校验码====%x",outdate[byteLength-1]);
NSData *udpPacketData = [[NSData alloc] initWithBytes:outdate length:byteLength];
Byte *testByte = (Byte *)[udpPacketData bytes];
Byte bytes[udpPacketData.length+1];
for(int i = 0;i<[udpPacketData length];i++){
bytes[i]=testByte[i];
}
bytes[udpPacketData.length] ='\n';
DLog(@"udpPacketData=======%@",udpPacketData);
NSData *adata = [[NSData alloc] initWithBytes:bytes length:udpPacketData.length+1];
[_sendPlayerSocket writeData:adata withTimeout:-1 tag:tag];
//发送卡寄存器
int byteLength = 516;
Byte outdate[byteLength];
memset(outdate, 0x00, byteLength);
outdate[0]=(Byte)0xaa;
outdate[1]=0x55;
outdate[2]=0x01;// 包类型,01写发送卡寄存器
for (int i=0; i<256; i++) {
outdate[2*i+3]=0xFF;
outdate[2*i+4]=0xFF;
}
//计算校验码
Byte sumByte = 0;
for (int j=0; j<(byteLength-1); j++) {
sumByte += outdate[j];
}
//校验码计算(包头到校验码前所有字段求和取反+1)
outdate[(byteLength-1)]=~(sumByte)+1;
long tag = outdate[1];
DLog(@"恢复默认列表 = %d",(int)commandType);
DLog(@"校验码====%x",outdate[byteLength-1]);
NSData *udpPacketData = [[NSData alloc] initWithBytes:outdate length:byteLength];
Byte *testByte = (Byte *)[udpPacketData bytes];
Byte bytes[udpPacketData.length+1];
for(int i = 0;i<[udpPacketData length];i++){
bytes[i]=testByte[i];
}
bytes[udpPacketData.length] ='\n';
DLog(@"udpPacketData=======%@",udpPacketData);
NSData *adata = [[NSData alloc] initWithBytes:bytes length:udpPacketData.length+1];
[_sendPlayerSocket writeData:adata withTimeout:-1 tag:tag];