I'm a beginner of iPhone app development. I'm working on an app that communicate with an external hardware using the dock to RS232 cable I got from RedPark. I wrote the most code myself, but I am still confused about several things.
I want to have several views in my app and each view has a button, that when pressing the button, it sends different command to the hardware. So I create a NSObject to take care of the sending part. My question is how to properly call the send method of that NSObject. Communication.h
@interface Communication : NSObject<RscMgrDelegate>
{
RscMgr * rscMgr;
}
@property (nonatomic,retain)RscMgr *rscMgr;
- (void)sendRequest;
@end
Communication.m
@synthesize rscMgr=_rscMgr;
- (void)sendRequest{
if (!_rscMgr) {
rscMgr = [[RscMgr alloc]init];
[rscMgr setDelegate:self];
}
UInt8 sendData[4]={0x8E,0x8E,0x05,0x80};
[rscMgr write:sendData Length:4];
NSLog(@"sending request");
}
BTW, RscMgr is a NSObject provided by RedPark that uses their library. Singletest.m
- (Communication *)communication{
if(!_communication){
_communication=[[Communication alloc]init];
}
return _communication;
}
- (IBAction)sendData:(id)sender{
[self.communication sendRequest];
NSLog(@"Send Data");
}
What happens now is the first time I press the button, it did send a command, but not afterwards. I think I just made a stupid mistake since I'm still learning it. Please let me know.
Thank you.