我对 iOS 编码非常陌生,我一直在练习使用网上找到的小应用程序示例。
我正在阅读“带有 Arduino 的 iOS 传感器应用程序”一书中的示例,并且我一直在使用适用于 iPhone/iPad 的 Redpark 串行电缆与 Adruino UNO 板进行串行通信示例的说明
我有 Redpark 串行电缆和他们的演示应用程序,以及一个注册的工作开发者资料。我已经能够通过串行通信与 iPhone 上的演示应用程序和计算机上的串行端口进行通信。
在使用书中的示例时,我已将此行复制到 iOS 代码中:
bytesRead = [rscMgr read:rxBuffer length:numBytes];
但是,当用其余代码编译它时,它会抛出一个错误,描述为
使用未声明的标识符“if”
我到处寻找“如果”这个词,但找不到。我还查看了来自 Redpark 的示例代码,除了缓冲区名称之外,如果不相同,它们也是相似的。
如果我提供了足够的详细信息,请告诉我,我很期待这个社区可能有的任何建议,再次感谢您提供时间。
贝娄是更多的代码:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
rscMgr = [[RscMgr alloc] init];
[rscMgr setDelegate:self];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)sendString:(id)sender {
[self.textEntry resignFirstResponder];
//Add code here
}
#pragma mark - RscMgrDelegate methods
- (void)cableConnected:(NSString *)protocol {
[rscMgr setBaud:9600];
[rscMgr open];
}
- (void)cableDisconnected {
}
- (void)portStatusChanged {
- (void) readBytesAvailable:(UInt32)numBytes {
int bytesRead;
// Read the data out
**bytesRead = [rscMgr read:rxBuffer length:numBytes];**
NSLog( @"Read %d bytes from serial cable.", bytesRead);
for(int i = 0;i < numBytes;++i) {
lf.serialView.text =
[NSString stringWithFormat:@"%@%c",
self.textView.text,
((char *)rxBuffer)[i]];
}
}
- (BOOL) rscMessageReceived:(UInt8 *)msg TotalLength:(int)len {
return FALSE;
}
- (void) didReceivePortConfig {
}
@end