10

I'm currently running the followin in Terminal to send a command over USB serial.

/Users/drummerboyx/Library/Scripts/arduino-serial -b 9600 -p /dev/tty.usbserial-A800ev0Z -s 1

Is there a way to do this in Objective-C?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
objectiveccoder001
  • 2,981
  • 10
  • 48
  • 72

4 Answers4

21

ORSSerialPort is a newer, easier to use alternative to AMSerialPort.

Using ORSSerialPort to open a port and send data can be as simple as this:

ORSSerialPort *serialPort = [ORSSerialPort serialPortWithPath:@"/dev/cu.KeySerial1"];
serialPort.baudRate = [NSNumber numberWithInteger:4800];
[serialPort open];
[serialPort sendData:someData]; // someData is an NSData object
[serialPort close];
danVnest
  • 959
  • 10
  • 11
8

Some google-fu found:

I know pretty much nothing about it, but the name "IOKit" also sounds pretty promising...

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
1

If you just want to run that command from your code, you can use the system function:

#include <stdio.h>
#include <stdlib.h>

system("/Users/drummerboyx/Library/Scripts/arduino-serial -b 9600 -p /dev/tty.usbserial-A800ev0Z -s 1");

You'll need to set your Objective-C source code file extension to .mm, which tells Xcode to compile it as Objective-C++.

Julio Gorgé
  • 10,056
  • 2
  • 45
  • 60
1

If you want to stick to Cocoa - Have a look at NSTask.

Abizern
  • 146,289
  • 39
  • 203
  • 257