Xcode sending character over bluetooth
I have built a program for OS X using xcode. I have the internal bluetooth
pairing successfully with the chip on my dev board. I am having issues
sending a character to the dev board. Here's what I have so far.
- (IBAction)setting1:(id)sender {
myText.stringValue = [NSString stringWithFormat:@"Setting 1"];
[self sendData:@"1" toChannel:mRFCOMMChannel];}
I have the sendData setup as this
- (void) sendData:(NSString *)string
toChannel:(IOBluetoothRFCOMMChannel *)rfcommChannel
{
int i;
// Turn the string into data.
NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding];
char buffer[ [data length] +4];
char *bytes = (char *) [data bytes];
// Add a CRLF to the start
buffer[0] = 13;
buffer[1] = 10;
// Copy the data into the buffer.
for (i=0;i<[data length];i++)
{
buffer[2+i] = bytes[i];
}
// Append a CRLF
buffer[ [data length]+2] = 13;
buffer[ [data length]+3] = 10;
// Synchronously write the data to the channel.
[rfcommChannel writeSync:&buffer length:[data length]+4];
}
I just need the code to be able to send a 1, 2 or 3 depending on which
button is pressed in the window.
Any help is appreciated.
No comments:
Post a Comment