Şu anda bir Mac uygulamasıyla veriyi Arduino'ya göndermeye çalışıyorum.Verileri Arduino Uno'yu Cocoa (IOKit) kullanarak gönderemiyorum
void setup()
{
pinMode (2, OUTPUT);
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);
Serial.begin (9600);
}
void loop()
{
digitalWrite (2, HIGH);
if (Serial.available() > 0)
{
int c = Serial.read();
if (c == 255)
{
digitalWrite (3, HIGH);
}
else
digitalWrite (4, HIGH);
}
}
İşte XCode projesinde benim kodudur: my Arduino Uno kod şöyle Uygulamayı çalıştırdığınızda
// Open the serial like POSIX C
serialFileDescriptor = open(
"/dev/tty.usbmodemfa131",
O_RDWR |
O_NOCTTY |
O_NONBLOCK);
struct termios options;
// Block non-root users from using this port
ioctl(serialFileDescriptor, TIOCEXCL);
// Clear the O_NONBLOCK flag, so that read() will
// block and wait for data.
fcntl(serialFileDescriptor, F_SETFL, 0);
// Grab the options for the serial port
tcgetattr(serialFileDescriptor, &options);
// Setting raw-mode allows the use of tcsetattr() and ioctl()
cfmakeraw(&options);
speed_t baudRate = 9600;
// Specify any arbitrary baud rate
ioctl(serialFileDescriptor, IOSSIOSPEED, &baudRate);
NSLog (@"before");
sleep (5); // Wait for the Arduino to restart
NSLog (@"after");
int val = 255;
write(serialFileDescriptor, val, 1);
NSLog (@"after2");
Yani, beş saniye bekler, ama sonra donar. Konsoldaki çıktı şudur: Burada neyi yanlış yapıyorum?
GÜNCELLEME: Ben
fcntl(serialFileDescriptor, F_SETFL, 0);
üzerinden bu satırı yorum yaparken programı dondurmak değil, ama benim Arduino hala herhangi bir veri olsun yok Yani.
Bu IOKit kodu değil, değil mi? –
Burada sağlanan kodu kullanıyorum: http://playground.arduino.cc/Interfacing/Cocoa#IOKit – Jan
Bu, doğrudan sorunuzu yanıtlamıyor (Josh Freeman'ın cevabı böyle yapıyor), ancak [ORSSerialPort] 'a bir göz atabilirsiniz. (https://github.com/armadsen/ORSSerialPort), Objective-C/Cocoa'da seri portları kullanmayı oldukça kolaylaştırır. –