//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "PACSDK.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //const int PAC_MEM_SRAM = 0; //pacsdk.h had #define this //const int PAC_MEM_EEPROM = 1; int MEM_TYPE; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { unsigned int sizeOfSRAM = 0; unsigned int sizeOfEEPROM = 0; RadioButton1->Checked = true; MEM_TYPE = 0; //SRAM sizeOfSRAM = pac_GetMemorySize(PAC_MEM_SRAM); sizeOfEEPROM = pac_GetMemorySize(PAC_MEM_EEPROM); Label1->Caption = "of size, " + IntToStr(sizeOfSRAM) + " bytes"; Label2->Caption = "of size, " + IntToStr(sizeOfEEPROM) + " bytes"; } //--------------------------------------------------------------------------- void __fastcall TForm1::RadioButton1Click(TObject *Sender) { if (RadioButton1->Checked == true) MEM_TYPE = PAC_MEM_SRAM; else MEM_TYPE = PAC_MEM_EEPROM; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { unsigned int index; byte buf[64]; AnsiString writeString = edWrite->Text; strcpy((char *)buf, writeString.c_str()); int length = writeString.Length(); unsigned int size = pac_GetMemorySize(MEM_TYPE); int messageBoxReturned; messageBoxReturned = Application->MessageBoxA( "The data stored in memory may be erased!", "Warning!", MB_OKCANCEL); if (IDOK == messageBoxReturned) { try { index = StrToInt(edIndex->Text); if (index < 0) index = 0; if (index > size - 1) index = size - 1; } catch(...) { index = 0; edIndex->Text = "0"; } if (MEM_TYPE == PAC_MEM_EEPROM) pac_EnableEEPROM(true); pac_WriteMemory(index, buf, length, MEM_TYPE); if (MEM_TYPE == PAC_MEM_EEPROM) pac_EnableEEPROM(false); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { unsigned int index; unsigned int byteNum2Read; byte buf[64]; unsigned int size = pac_GetMemorySize(MEM_TYPE); try { index = StrToInt(edIndex->Text); if (index < 0) index = 0; if (index > size - 1) index = size - 1; } catch(...) { index = 0; edIndex->Text = "0"; } try { byteNum2Read = StrToInt(edByteNum->Text); } catch(...) { byteNum2Read = 1; edByteNum->Text = "1"; } pac_ReadMemory(index, buf, byteNum2Read, MEM_TYPE); edRead->Text = AnsiString((char*)buf); } //---------------------------------------------------------------------------