📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include <time.h>
#include <mmsystem.h>
#include "Unit1.h"
#include "sercap.h"
#include "bmp.h"
//---------------------------------------------------------------------------
//#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
DCB dcb;
HANDLE com1_handle;
BMP_Header_T BmpHeader;
unsigned char *BMPbuffer ,*CAMdata;
int index;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
bool Setup_COM1_Cfg(void)
{
if(BuildCommDCB("115200, N, 8, 1", &dcb))
ShowMessage("Build UART Communication!");
else{
ShowMessage("Fail to Build UART Communication!");
return false;
}
com1_handle = CreateFile("COM1", GENERIC_READ|GENERIC_WRITE,
0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if(com1_handle == INVALID_HANDLE_VALUE)
return false;
if(!SetCommState(com1_handle, &dcb)){
CloseHandle(com1_handle);
return false;
}
return true;
}
void __fastcall TForm1::Start1Click(TObject *Sender)
{ index = 0;
Setup_COM1_Cfg();
BMPbuffer = new unsigned char[800*600*3];
memset(BMPbuffer,0,800*600*3);
CAMdata = new unsigned char[800*600];
COM1_Thread = new TCOM1_Thread(true);
COM1_Thread->FreeOnTerminate = true;
COM1_Thread->Resume();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Stop1Click(TObject *Sender)
{COM1_Thread->Terminate();
CloseHandle(com1_handle);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
BmpHeader.bfType[0]='B';
BmpHeader.bfType[1]='M';
BmpHeader.bfSize = 800*600*3+54;
BmpHeader.bfOffBits = 54;
BmpHeader.biSize = 0x28;
BmpHeader.biWidth = 800;
BmpHeader.biHeight = 600;
BmpHeader.biPlanes = 1;
BmpHeader.biBitCount = 24;
BmpHeader.biCompression = 0;
BmpHeader.biSizeImage = 1440000;
BmpHeader.biXPelsPerMeter = 96;
BmpHeader.biYPelsPerMeter = 96;
BmpHeader.biClrUsed = 0;
BmpHeader.biClrImportant = 0;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -