Mac OS X app远程摄像头控制wi-fi

时间:2012-12-09 02:13:18

标签: objective-c

我想为Mac OS X构建一个程序来远程控制我的DSLR相机。我有的相机有一个WiFi适配器所以,我希望通过WiFi完成控制。我对C,Objective C / Xcode的基本中间知识有很好的理解,但没有使用WiFi的经验,我应该使用哪个框架来连接摄像机以及摄像机和计算机之间的通信?谢谢!

1 个答案:

答案 0 :(得分:1)

如果您指的是PTP over IP(PTP / IP),据我所知,这仅用于向/从相机传输媒体(不确定可能的远程控制功能),它基本上是TCP / IP连接。您需要建立TCP连接。正如NSBum建议的那样,这需要NSInputStream和NSOutputStream,并且有一个类作为NSStreamDelegate来处理流事件,例如Camera与计算机通信。

至于实际的协议,这应该由你下载的SDK处理,如果不是这里的一些文档可以帮助你开始:gPhoto PTP/IP Documentation

一些代码显示NSInputStream和NSOutputStream:

// This would either be part of a Class init method or called at some point after
CFReadStreamRef readStream;
    CFWriteStreamRef writeStream;
    CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.1.2", 1234, &readStream, &writeStream);
    inputStream = (__bridge NSInputStream *)readStream;
    outputStream = (__bridge NSOutputStream *)writeStream;

[inputStream setDelegate:self];
[outputStream setDelegate:self];

[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

[inputStream open];
[outputStream open];

作为一般例子写入outputStream:

// data is of class NSData, the following writes the data bytes to the outputStream
[outputStream write:[data bytes] maxLength:[data length]];

您的NSStreamDelegate还需要提供此方法的实现:

- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent

文档:NSStreamDelegate Protocol Reference(左侧边栏也是“流编程指南”的链接)