Libusb-win32 code to control Ricoh Theta
Kevin Cain <[email protected]>
| Newsgroups | gmane.comp.lib.libusb.devel.windows |
|---|---|
| Message-ID | <CACnUKRtKszqZnfF2DBaCqz=iA9H9qSTwAX5K_-z4Qphvy=6NuA@mail.gmail.com> |
Hello, listeros,
I’ve received a Ricoh Theta (https://theta360.com/en/), a fairly new 'one
shot' panoramic camera which I want to control via USB from a (Windows) PC.
There is no manufacturer API to control this unit, but like almost all
digital cameras it supports Universal Plug and Play for discovery and
Picture Transfer Protocol (PTP and PTP/IP) for data. Therefore, the Theta
can be controlled through various camera capture libraries, such as
libgPhoto2 (Linux). One example of controlling a Theta with PTP
instructions in Linux is here: http://mimosa-pudica.net/ricoh-theta.html.
As I'm running Windows 8.1, my first step was to replace the Theta's
device’s USB driver in Windows, in order to avoid the process of managing a
UPnP connection with the Theta under Windows via radio. I used Zadig for
its demonstrated compatibility with Win8.1: http://zadig.akeo.ie/ (see:
http://chdk.setepontos.com/index.php?topic=6231.msg106526#msg106526).
After launching Zagig, I changed the default ‘WinUSB’ selection to
‘libusb-win32’:
I had no trouble compiling libusb-win32 test code in MSVC++ 2013, including
the single .h and linking the single .lib from libusb-win32.
When I run the program below, I am able to find the device
(\\.\libusb0-0001--0x05ca-0x0364)
and 'usb_control_msg' correctly returns 64, the number of bytes I'm
sending. Based on PTP instructions successfully sent to the Ricoh Theta via
GPhoto (http://mimosa-pudica.net/ricoh-theta.html), I gather that
'trigger-capture' is the keyword I'd need to use to fire the camera.
Unfortunately the camera is not taking a picture. Can anyone have a look at
my simple code below so see if there is an obvious error, or suggest next
steps?
Thanks,
-Kevin
---
// USB_Device_Communication.cpp : Defines the entry point for the console
application. // #include "stdafx.h" #include "lusb0_usb.h" #include
<iostream> // std::cout #include <string> // std::string using namespace
std; int _tmain(int argc, _TCHAR* argv[]) { // Initialize USB Device
communication struct usb_bus *busses; cout << "Initializing USB..." <<
endl; usb_init(); cout << "Finding USB busses..." << endl;
usb_find_busses(); cout << "Finding devices..." << endl;
usb_find_devices(); busses = usb_get_busses(); struct usb_bus *bus; int c,
i, a; cout << "busses dir: " << busses->dirname << endl; // Iterate through
all busses for (bus = busses; bus; bus = bus->next) { struct usb_device
*dev; cout << "bus: " << bus->location << endl; // Iterate through all
devices // Find the libUSB device: \\.\libusb0-0001--0x05ca-0x0364 for (dev
= bus->devices; dev; dev = dev->next) { std::string str(dev->filename);
std::string str2("libusb0-0001--0x05ca-0x0364"); std::size_t found =
str.find(str2); if (found != std::string::npos) { cout << "device number: "
<< dev->devnum << endl; cout << "device vendor ID: " <<
dev->descriptor.idVendor << endl; cout << "device filename: " <<
dev->filename << "\n" << endl; /* Open the device, claim the interface and
do your processing */ cout << "Opening device..." << endl; //usb_dev_handle
*usb_open(); struct usb_dev_handle *devHandle; devHandle = usb_open(dev);
//usb_dev_handle *usb_open(struct usb_device *dev); cout << "Claiming the
interface..." << endl; usb_claim_interface(devHandle, 0); Sleep(200); //
Wait for USB Interface (perhaps not needed?) cout << "Triggering camera" <<
endl; //"theta --trigger-capture",0,0); unsigned char buffer[64];
memset(buffer, 0, 64); buffer[0] = 't'; buffer[1] = 'r'; buffer[2] = 'i';
buffer[3] = 'g'; buffer[4] = 'g'; buffer[5] = 'e'; buffer[6] = 'r';
buffer[7] = '-'; buffer[8] = 'c'; buffer[9] = 'a'; buffer[10] = 'p';
buffer[11] = 't'; buffer[12] = 'u'; buffer[13] = 'r'; buffer[14] = 'e'; int
result = usb_control_msg(devHandle, 0x21, 9, 0x2, 0x0, (char*)buffer, 64,
100); if (result == 64) cout << "Successfully sent all bytes to camera" <<
endl; } } } cout << "Exiting..." << endl; return 0; }
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Libusb-win32-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel