Background
More than a year did not visit the garden, changed the industry circle, feeling that they are too playboy point, but can be exposed to different research and development of the culture is also a bit of harvest, the game circle of technical flow, the power of the circle of business flow, the media circle of art and so on.
The background of this application is to let the SLR camera automation, its own boss means to do for USB interface programming, but too low-level technology in C # to do is not very appropriate. Make a bargain, then do it for the SLR.
Assuming a scene, we need an n-SLR device aimed at a single flower, taking a picture every 30 seconds and automatically sending it to the microblog.
Technical points
Canon SDK
WIA Standard
Canon SDK provides a DLL to the. NET Developer reference, and by invoking the SDK it is convenient for the canon to correspond to the model camera, but for getting the data in the camera. NET version SDK is not available. Then how to get the data in the SLR camera becomes a problem point. Some students may be puzzled, SLR camera access to the computer USB jack will not produce a disk Fu Yi, directly with the driveinfo.getdrives () to get the disk character traversal is not OK. Here to give you a little literacy, USB from the device classification can be from the USB device interface descriptor corresponding to the Binterfaceclass this byte gets. The typical code for Binterfaceclass is 1,2,3,6,7,8,9,10,11,255. Represents the meaning of 1-audio: an audio device. 2-communication Device: Communications equipment, such as telephones, moden and so on. 3-hid: Human-computer interaction equipment, such as keyboard, mouse and so on. 6-image image equipment, such as scanners, cameras, and sometimes digital cameras can also be grouped into this category. 7-Printer class. such as one-way, two-way printers and so on. 8-mass Storage mass Storage class. All with a certain storage function can be grouped into this category. such as the majority of digital cameras belong to this category. 9-hub class. 11-chip Card/smart card. 255-vendor Specific. Factory custom class, mainly for some special equipment. such as interface transfer card.
Our DriveInfo can capture device types that are
Public enum DriveType
{
//Summary:
//The type of drive is unknown.
Unknown = 0,
///
Summary:
//The drive does not have a root directory.
Norootdirectory = 1,
///
Summary:
//The drive is a removable storage device, such as a floppy disk drive or a
// USB flash drive.
Removable = 2,
///
Summary:
//The drive is a fixed disk.
Fixed = 3,
///
Summary:
//The drive is a network drive.
Network = 4,
///
Summary:
//The drive is a optical disc device, such as a CD or DVD-ROM.
CDRom = 5,
///
Summary:
//The drive is a RAM disk.
Ram = 6,
}
General U disk equipment is removable, but SLR camera is Portabledevice, getdrives method is not to get this type. A series of API methods for Portabledevice are available in Windows Systems32 interested students can try
Here I choose WIA interface Programming, WIA is the abbreviation for Windows Image acquisition, the current version is WIA 1.0, which is Windows Millennium Edition (Windows Me) or a later version of wind OWS system provides digital image acquisition services, and it can also be used to manage digital image devices. WIA is a COM component that is implemented using out-of-process (out of process) services, and unlike most out-of-process service programs, WIA provides its own data transfer mechanism (Iwiadatatransfer interface) to avoid performance loss during image data transfer. The High-performance Iwiadatatransfer interface uses shared memory to transmit data to client programs.
WIA has three main components: Device manager,minidriver Service Library and Device minidriver.
Device Manager: Enumerates image devices, acquires device genera, establishes events for devices, and creates device objects;
MiniDriver Service Library: Perform all equipment-independent services;
Device MiniDriver interprets mappings: WIA properties and commands to a specific device.
Through Devicemanagerclass (). The information in Deviceinfos we can collect the device information which belongs to the Cameradevicetype in the SLR, as for other types such as video have other similar methods.
public void Downjpgfromallcamera ()
{
int i = 1;
foreach (Ideviceinfo DevInfo in New Devicemanagerclass (). Deviceinfos)
{
if (Devinfo.type = = Wiadevicetype.cameradevicetype)
{
string DeviceID = Devinfo.deviceid;
Device Wdevice = Devinfo.connect ();
Devparam dev = new Devparam {wiadevice=wdevice, DeviceID = DeviceID, index = i};
New Thread ((Camera) =>
{
downjpg ((Devparam) Camera). Wiadevice, ((Devparam) Camera). DeviceID, ((Devparam) Camera). Index)
. Start (dev);
i++
}}
}