I'm currently running the followin in Terminal to send a command over USB serial.
我目前正在终端中运行followin以通过USB串口发送命令。
/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?
有没有办法在Objective-C中执行此操作?
4 个解决方案
#1
8
Some google-fu found:
一些google-fu发现:
- Serial Communication Cocoa Framework (on arduino.cc!)
- AMSerialPort
串行通信Cocoa框架(在arduino.cc上!)
I know pretty much nothing about it, but the name "IOKit" also sounds pretty promising...
我几乎一无所知,但名字“IOKit”听起来也很有希望......
#2
20
ORSSerialPort is a newer, easier to use alternative to AMSerialPort.
ORSSerialPort是AMSerialPort的一种更新,更易于使用的替代方案。
Using ORSSerialPort to open a port and send data can be as simple as this:
使用ORSSerialPort打开端口并发送数据可以像这样简单:
ORSSerialPort *serialPort = [ORSSerialPort serialPortWithPath:@"/dev/cu.KeySerial1"];
serialPort.baudRate = [NSNumber numberWithInteger:4800];
[serialPort open];
[serialPort sendData:someData]; // someData is an NSData object
[serialPort close];
#3
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++.
您需要将Objective-C源代码文件扩展名设置为.mm,它告诉Xcode将其编译为Objective-C ++。
#1
8
Some google-fu found:
一些google-fu发现:
- Serial Communication Cocoa Framework (on arduino.cc!)
- AMSerialPort
串行通信Cocoa框架(在arduino.cc上!)
I know pretty much nothing about it, but the name "IOKit" also sounds pretty promising...
我几乎一无所知,但名字“IOKit”听起来也很有希望......
#2
20
ORSSerialPort is a newer, easier to use alternative to AMSerialPort.
ORSSerialPort是AMSerialPort的一种更新,更易于使用的替代方案。
Using ORSSerialPort to open a port and send data can be as simple as this:
使用ORSSerialPort打开端口并发送数据可以像这样简单:
ORSSerialPort *serialPort = [ORSSerialPort serialPortWithPath:@"/dev/cu.KeySerial1"];
serialPort.baudRate = [NSNumber numberWithInteger:4800];
[serialPort open];
[serialPort sendData:someData]; // someData is an NSData object
[serialPort close];
#3
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++.
您需要将Objective-C源代码文件扩展名设置为.mm,它告诉Xcode将其编译为Objective-C ++。