我需要将数据发送到串口。要发送的内容的定义是:
Chr$(2) = Clear buffer
Chr$(48)&Chr(57) = Any number between 0 to 359
输入2090的尝试失败
int i, c;
char j;
NSString *tmpStr = [self.sendTextField stringValue];
NSString *tmpVal;
for (i = 0 ; i < [tmpStr length]; i++)
{
NSLog(@"Iteration: %d", i);
tmpVal = [tmpStr substringWithRange:NSMakeRange(i, 1)];
c = [tmpVal intValue];
j = (char)c;
tmpVal = [NSString stringWithFormat:@"%c", j];
NSData *dataToSend = [tmpVal.value dataUsingEncoding:NSUTF8StringEncoding]; **<Error here**
[self.serialPort sendData:dataToSend];
}
我不知道如何纠正控制台报告的错误。
2013-03-08 10:38:12.430 ORSSerialPortCocoaDemo[40656:303] Iteration: 0
2013-03-08 10:38:38.819 ORSSerialPortCocoaDemo[40656:303] -[__NSCFString value]: unrecognized selector sent to instance 0x1001626a0
2013-03-08 10:38:38.819 ORSSerialPortCocoaDemo[40656:303] -[__NSCFString value]: unrecognized selector sent to instance 0x1001626a0
2013-03-08 10:38:38.821 ORSSerialPortCocoaDemo[40656:303] (
0 CoreFoundation 0x00007fff858180a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff835b03f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff858ae6ea -[NSObject(NSObject) doesNotRecognizeSelector:] + 186
3 CoreFoundation 0x00007fff858065ce ___forwarding___ + 414
4 CoreFoundation 0x00007fff858063b8 _CF_forwarding_prep_0 + 232
5 ORSSerialPortCocoaDemo 0x0000000100008e81 -[ORSSerialPortDemoController send:] + 465
6 AppKit 0x00007fff868d6a59 -[NSApplication sendAction:to:from:] + 342
7 AppKit 0x00007fff868d68b7 -[NSControl sendAction:to:] + 85
8 AppKit 0x00007fff868d67eb -[NSCell _sendActionFrom:] + 138
9 AppKit 0x00007fff868d4cd3 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 1855
10 AppKit 0x00007fff868d4521 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 504
11 AppKit 0x00007fff868d3c9c -[NSControl mouseDown:] + 820
12 AppKit 0x00007fff868cb60e -[NSWindow sendEvent:] + 6853
13 AppKit 0x00007fff868c7744 -[NSApplication sendEvent:] + 5761
14 AppKit 0x00007fff867dd2fa -[NSApplication run] + 636
15 AppKit 0x00007fff86781cb6 NSApplicationMain + 869
16 ORSSerialPortCocoaDemo 0x0000000100001d62 main + 34
17 ORSSerialPortCocoaDemo
答案 0 :(得分:2)
删除对value
方法的调用:
NSData *dataToSend = [tmpVal dataUsingEncoding:NSUTF8StringEncoding];