GWSOFT.co.uk  

Site by Graham Wharton 
November 21st 2008 05:35:32 PM 



NOTE : This project is not currently in development and is totally unsupported. These pages are here for information only.

downloadPicture

Declaration

extern "C" status_t downloadPicture(BPath savedir);

Description

This function must be implemented in the plugin. This function accepts a BPath variable which the plugin should use to determin the location to save the images to. If the camera does not support filenames, then a virtual filename system may be used, basing the filenames on the dates of images if available, or at least, just by calling them Image1, Image2. The filename should be appended to the path, and used as the full name for the image file. If a virtual filename system is to be used, then it is advised that the optional Level 2 function getImageName should be implemented, and uses the same names for the images as this function would.

The function returns a status_t error code to indicate the success of the operation. Any of the status_t error codes can be used, but it is suggested that you stick to using B_NO_ERROR for success and B_ERROR for failure.

During the download of the image, status information may be sent back to the host app by using messaging. If the optional Level 2 function setMessageTarget has been implemented by the plugin, and has been called by the host app, then the plugin will know where to target these messages. If the function was not called, the plugin must never attempt to send any messages back to the host. The message in this case should be an MSG_UPDATEBAR message with an attatched float containing the number of bytes downloaded since the last message. MSG_UPDATEBAR should be defined as follows.

const int32 MSG_UPDATEBAR = 0x01012001;

Example Implementation - Kodak DC210 Plugin

status_t downloadPicture(BPath savedir) { int receivelength = 1024; unsigned char *buffer = new unsigned char[2000]; //In this plugin I store a map of filenames against picture numbers if (haveigotfilenames == false) if (getfiledata() < B_NO_ERROR) return(B_ERROR); //Obtain the filename map<int, char*&mt;::iterator pname; pname = imagenames.find(currentpicturenumber); char* filename = new char[255]; sprintf(filename, "%s", pname-&mt;second); savedir.Append(filename); //Create the file to save the image to BFile* file = new BFile(savedir.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); char* temp2; //Send the appropriate commands to the camera to start downloading ComPort->Write("\x64\x00", 2); temp2 = (char*)(currentpicturenumber &mt;&mt; 8); ComPort->Write(&temp2,1); temp2 = (char*)(currentpicturenumber &mt;&mt; 0); ComPort->Write(&temp2,1); ComPort->Write("\x00",1); ComPort->Write("\x00\x00\x1A",3); ComPort->Read(buffer,1); while (buffer[0] == 0xf0) ComPort->Read(buffer,1); //Check for busy byte if (buffer[0] == 0xe2) return(B_ERROR); else if (buffer[0] == 0xd1) { ComPort->Read(buffer,1); do { //Begin reading image data from camera if (msgtarget != NULL) { //If this has been set then we must be able to send status messages //Back to camera. MSG_UPDATEBAR informs the host app of the download //Progress. Sending a float with the number of bytes got. BMessage *msg; msg = new BMessage(MSG_UPDATEBAR); msg-&mt;AddFloat("updateby", (float)receivelength); msgtarget-&mt;PostMessage(msg); delete msg; } //Receive a packet and save to the file. //Luckily the DC210 gives straight jpg's //So no processing needed to be done. receivepacket(buffer,receivelength, true); file-&mt;Write(buffer,receivelength); ComPort->Read(buffer,1); while (buffer[0] == 0xf0) ComPort-&mt;Read(buffer,1); } while (buffer[0] == 0x01); if (buffer[0] == 0x00) { snooze(50000); return(B_NO_ERROR); } else return(B_ERROR); } else return(B_ERROR); }
BDCP Developers Home Page