using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Memory { public partial class Form1 : Form { const int PAC_MEM_SRAM = 0; const int PAC_MEM_EEPROM = 1; int MEM_TYPE; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { uint sizeOfSRAM = 0; uint sizeOfEEPROM = 0; radioButton1.Checked = true; MEM_TYPE = 0; //SRAM sizeOfSRAM = PACNET.Memory.GetMemorySize(PAC_MEM_SRAM); sizeOfEEPROM = PACNET.Memory.GetMemorySize(PAC_MEM_EEPROM); label1.Text = "of size, " + sizeOfSRAM.ToString() +" bytes"; label2.Text = "of size, " + sizeOfEEPROM.ToString() +" bytes"; } private void button1_Click(object sender, EventArgs e) { uint index; byte[] buf = new byte[64]; string writeString = tbWrite.Text; buf = PACNET.MISC.AnsiString(writeString); uint length = Convert.ToUInt32(writeString.Length); uint size = PACNET.Memory.GetMemorySize(MEM_TYPE); DialogResult dR; dR = MessageBox.Show("The data stored in memory may be erased!", "Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); if (dR == DialogResult.OK) { try { index = uint.Parse(tbIndex.Text); if (index < 0) index = 0; if (index > size - 1) index = size - 1; } catch { index = 0; tbIndex.Text = "0"; } if (MEM_TYPE == PAC_MEM_EEPROM) PACNET.Memory.EnableEEPROM(true); PACNET.Memory.WriteMemory(index, buf, length, MEM_TYPE); if (MEM_TYPE == PAC_MEM_EEPROM) PACNET.Memory.EnableEEPROM(false); } } private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked == true) MEM_TYPE = PAC_MEM_SRAM; else MEM_TYPE = PAC_MEM_EEPROM; } private void button2_Click(object sender, EventArgs e) { uint index; uint byteNum2Read; byte[] buf = new byte[64]; uint size = PACNET.Memory.GetMemorySize(MEM_TYPE); try { index = uint.Parse(tbIndex.Text); if (index < 0) index = 0; if (index > size - 1) index = size - 1; } catch { index = 0; tbIndex.Text = "0"; } try { byteNum2Read = uint.Parse(tbByteNum.Text); } catch { byteNum2Read = 1; tbByteNum.Text = "1"; } PACNET.Memory.ReadMemory(index, buf, byteNum2Read, MEM_TYPE); tbRead.Text = PACNET.MISC.WideString(buf); } } }