. Net Play SLR Tips

Source: Internet
Author: User
This article shares the use of. Net Play SLR

Background

More than a year did not visit the garden, for a trade circle, feel too much fun, but can contact the different research and development culture is also a bit of harvest, the game circle of technology flow, the business flow of e-commerce circles, the art stream of media circles and so on.

The background of this application is to automate the SLR camera, which is meant to be programmed for the USB interface, but it is not appropriate to use C # for the underlying technology. Bargain, then do it for the SLR.

Assuming a scenario, we need an n-SLR device aiming at a flower, taking a picture every 30 seconds and automatically sending it to Weibo.

Technical points

Canon SDK

WIA Standard

The Canon SDK provides a DLL to the. NET Developer reference, which can be handy for Canon's camera model by calling the SDK, but not available in the Get camera data. NET Version SDK. So how to get the data inside the SLR camera becomes a problem point. Some students may be puzzled, SLR camera access to the computer USB jack will produce a disk Fu Yi, directly with the driveinfo.getdrives () to get the drive character traversal can not do it. Here first of all literacy, USB from the device classification can be from the USB device interface descriptor corresponding to the Binterfaceclass this one byte. The typical code for Binterfaceclass is 1,2,3,6,7,8,9,10,11,255. respectively represents the meaning of 1-audio: represents an audio device. 2-communication Device: Communication devices such as telephones, moden, etc. 3-hid: Human-computer interaction equipment, such as keyboard, mouse and so on. 6-image image equipment, such as scanners, cameras, etc., sometimes digital cameras can also be classified into this category. 7-Printer class. such as unidirectional, bidirectional printers. 8-mass Storage mass Storage class. All functions with a certain storage function can be grouped into this category. For example, most of the digital cameras belong to this category. 9-hub class. 11-chip Card/smart card. 255-vendor specific. Manufacturer's custom class, mainly used for some special equipment. such as interface adapter cards.

The types of devices that our driveinfo can capture are


Public enum DriveType    {        //Summary:        //The type of drive is     unknown.        Unknown = 0,/////Summary://The drive does is not     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 was     a network drive.        Network = 4,        /////        Summary://The drive was an     optical disc device, such as a CD or DVD-ROM.        CDRom = 5,        /////        Summary://The drive is     a RAM disk.        Ram = 6,    }


The general U-disk device is removable, but the SLR camera is Portabledevice, with the 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 the WIA interface programming, WIA is the abbreviation of Windows Image acquisition, the current available version is WIA 1.0, it is Windows Millennium Edition (Windows Me) or a later version of wind The Digital Image Acquisition service provided in the OWS system, and it can also be used to manage digital imaging devices. WIA is a COM component that is implemented using out of process services, and unlike most out-of-process service programs, WIA avoids performance loss during image data transfer by providing its own data transfer mechanism (Iwiadatatransfer interface). 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, obtains device genera, establishes events for devices, and creates device objects;
MiniDriver Service Library: Perform all device-independent services;
Device MiniDriver explains the mapping: WIA properties and commands to a specific device.
Through Devicemanagerclass (). Information in Deviceinfos we can collect the device information belonging to Cameradevicetype in the SLR, as for other types of video and 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++;}}}        


To talk about the SDK, 5 kinds of handle delegates are available in the Canon SDK. NET version


        Public delegate uint Edsprogresscallback (UINT inpercent, IntPtr incontext, ref bool outcancel);        Public delegate uint Edscameraaddedhandler (IntPtr incontext);        Public delegate uint Edspropertyeventhandler (UINT inevent, uint Inpropertyid, uint inparam, IntPtr incontext);         Public delegate uint Edsobjecteventhandler (UINT inevent, IntPtr inref, IntPtr incontext);         Public delegate uint Edsstateeventhandler (UINT inevent, uint inparameter, IntPtr incontext);


The first is used for data processing such as data copying, picture saving, and so on.

The second one for the PC to discover the new camera device

Third notification for changes in attribute state such as data flow in the camera, such as series changes resulting from a photo action

The fourth one for file operations such as file creation delete and so on

The fifth one is used for the camera's own state time, such as the switch machine abnormality.

Various applications of the scene we see the demo program although the Load method is multi-threaded but the hard disk IO itself is serial here is just writing to play we don't have to seriously

New camera Device added

Program Control Camera Photo

Local loading of photo data in camera

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.