The Nikon SDK allows for a request/response system from PC to camera through USB through the C programming language. When creating two camera objects in two seperate threads, it is not possible to send two commands simultaneously to two seperate cameras. One camera will get its command, and send back the response, and then the second camera will get its command and send back a response. I think it has to do with the fact the DLL开发者_高级运维 the Nikon SDK accesses uses global variables. The DLL is not open-source, so I cannot change or verify this. I did make two seperate copies of the DLL and each thread acesses a seperate copy. Is it possible to send two commands and get responses back at the same time?
Even though you made two copies of the DLL, they are both being loaded into the same address space / process, so any conflicts will still overlap.
The first thing I would try is two separate EXEs, each loading the original DLL, so that they are running in different processes. If this allows the two cameras to be controlled independently and simultaneously, you will just need to build some kind of process isolation system :-)
The only way I know to do this (and it's not easy) is to build a COM wrapper around the Nikon DLLs and use IIS to isolate the two instances into their own processes. A slightly easier approach might be to build your own "server" for each camera, running in an EXE process, and send messages to it (maybe just Windows messages) from a third master process.
A brute force solution would be to run each process in its own virtual machine using VMWare Workstation or a similar virtual PC architecture. Of course, now you've got the problem of communicating between two virtual PCs...
Those md3 files are not thread safe and contain static functions. I got this working on the Nikon SDK by dynamically creating a new copy of the md3 file each time a camera is connected. I had one main md3 for detecting the cameras and then would create a new md3 each time I connected.
Finally, make sure your class is thread safe and contains no global or static functions. I recommend encasing the base Nikon code into a class. If your writing a 3rd party dll that requires static functions use a pointer to the Nikon class, for each static call pass the void* object that is created by your constructor.
First think I would try is spawning 2 instances of your application. One for each camera.
Not sure exactly what you're trying to accomplish. Does the answer take too long, so that you want to get the answers at the same time? Why not simply just create a wrapper and make sure the question/answer are simply synchronous, so that you can access the SDK from any thread (and in case thread X is waiting for a response and thread Y makes a request, thread Y will wait until thread X is getting the response, and then make a request).
精彩评论