C328 Camera - Blank Images

I am attempting to use a C328 camera to stream pictures from my Arduino to a base station, and from my base station to a web server.

I am using the C328R library from here: Google Code Archive - Long-term storage for Google Code Project Hosting.

Using this library, I can go through all the steps required to get a picture from this camera. It syncs, it initializes, I can change the baud rate, take a snapshot, and retrieve the picture. However, once the pictures have been saved to files on my computer, they are blank. They appear as valid JPEGs of the correct size, but no actual picture data.

 Serial.begin(9600);
  Serial1.begin(14400);
  
  // Sync camera
  synced = camera.sync();
  
  // Run camera setup
  if (synced == true) {
    
    Serial.println("Camera synced.");
    
    // Initialize camera
    initialized = camera.initial(camera.CT_JPEG, camera.PR_80x60, camera.JR_320x240);
    if (initialized == true) {
      Serial.println("Camera initialized.");
    }
    
    // Set camera data package size to 512B
    acked = camera.setPackageSize(64);
    if (acked == true) {
      Serial.println("Package size set.");
      acked = false;
    }
    
    // Increase camera baud rate to 115200 bps
    acked = camera.setBaudRate(camera.BAUD115200);
    if (acked == true) {
      Serial.println("Baud rate set.");
      acked = false;
      Serial1.begin(115200);
    }
    
    // Take snapshot
    acked = camera.snapshot(camera.ST_COMPRESSED, 2);
    if (acked == true) {
      Serial.println("Snapshot taken.");
      acked = false;
    }
    
    // Retrieve image and send to base station
    acked = camera.getJPEGPicture(camera.PT_SNAPSHOT, 1000, &transmitImageChunk);
    if (acked == true) {
      Serial.println("Image received.");
      acked = false;
    }

Here is my callback function:

void transmitImageChunk(uint16_t picSize, uint16_t packPicDataSize, uint16_t packCount, byte* pack) {

  // Mark start of image transmission
  if (packCount < 1) {
    Serial.println("s");
    transmittedDataSize = 0;
  }
  
  // Transmit current package
  Serial.write(pack, packPicDataSize);
  
  transmittedDataSize += packPicDataSize;
  
  // Mark end of image transmission
  if (transmittedDataSize == picSize) {
    Serial.println("");
    Serial.println("e");
  }
  
}

On the computer end, I use a perl script to send out the image data as it is received, and on my web server, the data is saved to a file. I have tested the perl scripts using other image files, and they worked fine, but I suppose reading the image data from a serial port rather than a file could mess with that, so here is my perl code to transmit the data:

	while (1) {
		$byte = $serial->read(1);
		if ($byte) {
			$string = $string . $byte;
			if ($byte =~ "\n") {
				if ($string =~ "s\r\n") {
					print $handle "newImage\n";
					$imageFlag = 1;
				} elsif ($string =~ "e\r\n") {
					print $handle "endImage\n";
					$imageFlag = 0;
				} elsif ($imageFlag == 1) {
					$string =~ s/\r\n//;
					print $handle $string;
				} else {
					print STDOUT $string;
				}
				$string = "";
			}
		}
	}

Finally, here is my server code that receives and saves the image:

			if ($line =~ "newImage\n") {
				$imageName = time;
				open FILE, ">", "imagesOut/$imageName.jpg" || die $!;
				while (defined($line = <$client>)) {
					if ($line =~ "endImage\n") {
						last;
					} else {
						print FILE $line;
					}
				}
				close FILE;
                          }

The camera only successfully syncs about once every 20 or so attempts (I have to power cycle it each attempt), so given this and my blank image problem, I am beginning to suspect my camera may be broken.

If any could offer me any advice, I would be very grateful.

Thanks!