//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#pragma hdrstop
#include "MCUTools.h"
//#include "port.h"
#include "crc.h"
#include "sermon.h"
#include "ioctlcmd.h"
//#include "LEDCode.h"
#include <tchar.h>
#include <commctrl.h> // includes the common control header
#include <string.h>
#include <winioctl.h>
//#include <stdlib.h>
#include "varForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
int cl1Value;
int cl2Value;
int cl3Value;
double cl4Value;
String cl5Value;
//const unsigned long
//bool
SerialPort * COMPort;
TRead * ReadPort;
TWrite * WritePort;
ULONG DispOffset;
PORTSTATUS pStatus;
BOOLEAN IsNT;
BOOLEAN Capture = FALSE;
HANDLE SysHandle = INVALID_HANDLE_VALUE;
// Filter strings
TCHAR FilterString[MAXFILTERLEN];
TCHAR ExcludeString[MAXFILTERLEN];
TCHAR HighlightString[MAXFILTERLEN];
// Recent filters
char RecentInFilters[NUMRECENTFILTERS][MAXFILTERLEN];
char RecentExFilters[NUMRECENTFILTERS][MAXFILTERLEN];
char RecentHiFilters[NUMRECENTFILTERS][MAXFILTERLEN];
// Filter-related
FILTER FilterDefinition;
// Buffer into which driver can copy statistics
char Stats[ LOGBUFSIZE ];
// Current fraction of buffer filled
DWORD StatsLen;
DWORD MaxLines = 64; // Max lines for Port Monitor
String SaveFileName; // Max lines for COMM Rx
DWORD rxMaxLines=60;
PORTSET SerialPortSet;
PORTSET ParallelPortSet;
FLT varFloat;
DBL varDbl;
LNG varLong;
WD varInt;
VARS Vars;
MEM memBlock;
TStringList * strRadix;
TStringList * strType;
bool fModemOnline = false;
bool fTimer=false;
#define h2b(p) ((Trans[p[0]] << 4) | Trans[p[1]])
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::rbRTASMStyleClick(TObject *Sender)
{
edDB->Enabled = true;
rbRTPrefix->Enabled = true;
rbRTPostfix->Enabled = true;
edRTFix->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::rbRTCStyleClick(TObject *Sender)
{
edDB->Enabled = false;
rbRTPrefix->Enabled = false;
rbRTPostfix->Enabled = false;
edRTFix->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnRTFileClick(TObject *Sender)
{
FILE * fp;
char * temp;
char * rt;
char str[255];
int line = 1;
OpenDialog1->Filter = "Data files (*.dat)|*.dat|All files (*.*)|*.*";
OpenDialog1->DefaultExt = "dat";
if(OpenDialog1->Execute()){
if((fp = fopen(OpenDialog1->FileName.c_str(),"rb")) == NULL){
Application->MessageBox("Open file error!","Error",MB_OK | MB_ICONERROR);
return;
}
/* seek to the start of the file */
fseek(fp, 0, SEEK_SET);
while (!feof(fp)){
/* read a string from the file */
if(fgets(str, 250, fp) != NULL){
temp = strtok(str,",");
rt = strtok(NULL,",");
rt = strtok(rt,"\r\n");
if(temp != NULL && rt != NULL){
sgRTVal->Cells[0][line] = temp;
sgRTVal->Cells[1][line] = rt;
line++;
if(line >= sgRTVal->RowCount){
sgRTVal->RowCount++;
}
}
}
}
fclose(fp);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnRTSaveClick(TObject *Sender)
{
String FileName,s;
int ret,i;
FILE *fp;
SaveDialog1->Filter = "Data files (*.dat)|*.dat|All files (*.*)|*.*";
SaveDialog1->DefaultExt = "dat";
if(SaveDialog1->Execute()){
FileName = SaveDialog1->FileName;
if(FileExists(FileName)){
ret = Application->MessageBox("File exist, Overwrite?","File overwrite",MB_OKCANCEL | MB_ICONWARNING);
if (ret == 2){
return;
}
}
if((fp = fopen(FileName.c_str(),"wb")) == NULL){
Application->MessageBox("Open file error!","Error",MB_OK | MB_ICONERROR);
} else {
for(i=1;i < sgRTVal->RowCount;i++){
if(!(sgRTVal->Cells[0][i].Trim().IsEmpty()) && !(sgRTVal->Cells[1][i].Trim().IsEmpty())){
s = sgRTVal->Cells[0][i].Trim() + "," + sgRTVal->Cells[1][i].Trim() + "\r\n";
if(fputs(s.c_str(),fp)<0){
Application->MessageBox("Write file error!","Error",MB_OK | MB_ICONERROR);
break;
}
}
}
}
fclose(fp);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::sgRTValKeyPress(TObject *Sender, char &Key)
{
double TStep;
if(Key == 13){
if(cbTInc->Checked && !(edTStep->Text.Trim().IsEmpty())){
try{
TStep = edTStep->Text.ToDouble();
}
catch(EConvertError &E)
{
Application->MessageBox("Please input temperature step correctly!","Error",MB_OK | MB_ICONERROR);
edTStep->SetFocus();
return;
}
try{
if(!(sgRTVal->Cells[0][sgRTVal->Row].Trim().IsEmpty()) && !(sgRTVal->Cells[1][sgRTVal->Row].Trim().IsEmpty())){
try{
sgRTVal->Cells[1][sgRTVal->Row].ToDouble();
}
catch(EConvertError &E)
{
Application->MessageBox("Please input resister value correctly!","Error",MB_OK | MB_ICONERROR);
return;
}
if(sgRTVal->Row >= sgRTVal->RowCount-1){
sgRTVal->RowCount++;
}
sgRTVal->Cells[0][sgRTVal->Row + 1]
= sgRTVal->Cells[0][sgRTVal->Row].ToDouble() + TStep;
sgRTVal->Row++;
sgRTVal->Col = 1;
} else {
if(sgRTVal->Cells[0][