从rs232设备的文本视图中附加了一个sting。所有东西都会导入,但是有一些字符串会被concatinated,就好像附加了一个空值来结束并导入一些数据。任何想法如何在字符串中查找空值?从rs232导入的字符串中包含空值
- (void)readBytesAvailable:(NSInteger)count {
DataSource *sharedManager = [DataSource sharedManager];
const int bufferLength = 1024;
uint8_t buffer[bufferLength];
NSString *s;
NSInteger bytesRead = [session read:buffer bufferLength:bufferLength];
if (bytesRead > 0) {
// Convert to a string - note that the remote device is sending only well- formed UTF8 text data (e.g. no binary data, no VT100 excampe codes, etc).
s = [[NSString alloc] initWithBytes:buffer length:bytesRead encoding: NSUTF8StringEncoding];
AllDataTextView.text = [AllDataTextView.text stringByAppendingString:s];
解决的课题:数据是ASCII格式,而不是UTF-8和缓冲区的长度是由发送到该方法计数设置。 – Wilbe