I have written a short program and set up my board and device so that
they are communicating. However, I am unsure how I can transfer that
information to my computer for evaluation and display. I'd prefer to
use MATLAB if anyone has done this before.
List of problems:
1. data being recorded from C328 camera doesn't seem long enough.
2. when output of camera is sent to display window and cut/paste
transferred to MATLAB the picture is nothing like what I expect.
Code attached:
#define CINBUFSIZE 511
#define COUTBUFSIZE 511
const long baud_rate = 14400L;
void main()
{
int moveon;
auto int transmitted;
auto int received;
auto int i;
auto int cmd[3];
auto int rec[6];
auto int Pic[5120];
char null;
brdInit(); //initialize board for this demo
serCopen(baud_rate);
serCwrFlush();
serCrdFlush();
printf("Starting...\n");
cmd[0] = 0x0DAA;
cmd[1] = 0x0000;
cmd[2] = 0x0000;
moveon=1;
while(moveon){
// sends SYNC command
for (i = 0; i < 1; i++)
{serCwrite(cmd,sizeof(cmd));}
// Waits for ACK command
for (i=0;i<6;i++)
{rec[i] = serCgetc();}
if(rec[0]==0xAA && rec[1]==0xE && rec[2]==0xD){moveon=0;printf
("\nConnecting...\n");} //ACK verified
printf("waiting...\n");
}
// checks for SYNC command
for (i=0;i<6;i++)
{rec[i] = serCgetc();}
if(rec[0]!=0xAA || rec[1]!=0xD || rec[2]!=0x00 || rec[3]!=0x00 ||
rec[4]!=0x00 || rec[5]!=0x00)printf("Failure\n");
if(rec[0]==0xAA && rec[1]==0xD && rec[2]==0x00 && rec[3]==0x00 &&
rec[4]==0x00 && rec[5]==0x00)printf("Success!!!\n");
// sends ACK command
cmd[0] = 0x0EAA;
cmd[1] = 0x000D;
cmd[2] = 0x0000;
for (i = 0; i < 1; i++)
{serCwrite(cmd,sizeof(cmd));}
//CAMERA IS NOW IN SYNC
//////////////////////////////////////////////////////////////////////
//////////
printf("hit keyboard for picture.");
while(kbhit()==0);
null=getchar();
// initial for VGA
moveon=1;
printf("Initializing for VGA (8-bit, 80/64 pixels)");
cmd[0] = 0x01AA;
cmd[1] = 0x0600;
cmd[2] = 0x0001;
while(moveon){
for (i = 0; i < 1; i++)
{serCwrite(cmd,sizeof(cmd));}
// checks for ACK command
for (i=0;i<6;i++)
{rec[i] = serCgetc();}
if(rec[0]==0xAA && rec[1]==0xE && rec[2]==0x1){printf
("ACK\n");moveon=0;} //ACK verified
printf("\nReceived: ");
for (i=0;i<3;i++)
{printf("0x%x ", rec[i]); }
printf("\n");
}
// Uncompressed Snapshot style
moveon=1;
printf("Setting mode to Uncompressed snapshot");
cmd[0] = 0x05AA;
cmd[1] = 0x0001;
cmd[2] = 0x0000;
while(moveon){
for (i = 0; i < 1; i++)
{serCwrite(cmd,sizeof(cmd));}
// checks for ACK command
while((rec[0]=serCgetc()) != 0xAA);
for (i=1;i<6;i++)
{rec[i] = serCgetc();}
if(rec[0]==0xAA && rec[1]==0xE && rec[2]==0x5 && rec[4]==0x0 && rec
[5]==0x0){printf("ACK\n");moveon=0;} //ACK verified
printf("\nReceived: ");
for (i=0;i<6;i++)
{printf("0x%x ", rec[i]); }
printf("\n");
}
//Take PICTURE!!!
moveon=1;
printf("Taking Picture");
cmd[0] = 0x04AA;
cmd[1] = 0x0001;
cmd[2] = 0x0000;
while(moveon){
for (i = 0; i < 1; i++)
{serCwrite(cmd,sizeof(cmd));}
// checks for ACK command
while((rec[0]=serCgetc()) != 0xAA);
for (i=1;i<6;i++)
{rec[i] = serCgetc();}
if(rec[0]==0xAA && rec[1]==0xE && rec[2]==0x4 && rec[4]==0x0 && rec
[5]==0x0){printf("ACK\n");moveon=0;} //ACK verified
printf("\nReceived: ");
for (i=0;i<6;i++)
{printf("0x%x ", rec[i]); }
printf("\n");
}
//Wait for start of picture
moveon=1;
while(moveon){
while((rec[0]=serCgetc()) != 0xAA);
for (i=1;i<6;i++)
{rec[i] = serCgetc();}
if(rec[0]==0xAA && rec[1]==0xA && rec[2]==0x1){
printf("\nReceived: 0x%x 0x%x 0x%x %x %x %x ",rec[0],rec[1],rec
[2],rec[3],rec[4],rec[5]);
printf("\n\nPixel data incoming...\n");moveon=0;}
}
//Picture Data
printf("pixel data:\n");
while(kbhit()==0)
{for (i=0;i<10;i++)
{Pic[i] = serCgetc();}
// printf("%d ",Pic[i]);}
// printf("\n");
printf("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, \n",Pic[0],Pic
[1],Pic[2],Pic[3],Pic[4],Pic[5],Pic[6],Pic[7],Pic[8],Pic[9]);
}
// sends ACK command
cmd[0] = 0x0EAA;
cmd[1] = 0x000D;
cmd[2] = 0x0000;
for (i = 0; i < 1; i++)
{serCwrite(cmd,sizeof(cmd));}
printf("EXIT");
}
------------------------------------

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )