using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO.Ports; using System.IO; using System.Text.RegularExpressions; using System.Configuration; using System.Timers; namespace Daya_Bay_Princeton_2009 { public partial class SetSerialNumber : Form { //uint addr= 0; //ushort len = 0; private byte[] blkout = new byte[Constants.MaxDataBytes]; /* Transmit buffer */ // private byte[] blkin = new byte[MAX_DATA_BYTES]; /* Receive buffer */ private byte[] blkin = new byte[32]; /* Receive buffer */ string PortName; //string SerialNumber; string passwdFile = null; //string SerialNumberFileName; private MainForm themainform; private byte[] serialnumber = new byte[40]; /* Hold Serial Number*/ SerialPort Port; Microcontroller SSNSP; Dictionary AllPorts = new Dictionary(); public SetSerialNumber(MainForm parentform) { InitializeComponent(); themainform = parentform; } private void button1_Click(object sender, EventArgs e) { int i = 0; string thisserialnumber = textBox1.Text; foreach (char ch in thisserialnumber.ToCharArray()) { blkout[i]=(byte)ch; i++; } Port = new SerialPort(); PortName = System.Convert.ToString(listBox1.SelectedItem); SSNSP.InitializePorts(); SSNSP.BslReset(true); SSNSP.TransmitPassword(); SSNSP.BslTxRx(Constants.BSLTransmitBlock,4096, 8, blkout, blkin); themainform.textBoxStatus.Text = "Done"; if (Port.IsOpen == true) Port.Close(); } private void button2_Click(object sender, EventArgs e) { PortName = textBox2.Text; SSNSP.InitializePorts(); SSNSP.BslReset(true); SSNSP.TransmitPassword2(); SSNSP.BslTxRx(Constants.BSLReceiveBlock, 4096, 8, null, blkin); string str; System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); str = enc.GetString(blkin); if (Port.IsOpen == true) Port.Close(); } private void button3_Click(object sender, EventArgs e) { PortName = textBox2.Text; SSNSP.InitializePorts(); SSNSP.BslReset(true); SSNSP.TransmitPassword2(); SSNSP.BslTxRx(Constants.BSLMassErase, /* Command: Mass Erase */ 0x1000, /* Any address within flash memory. */ 0xa502, /* Required setting for mass erase! */ null, blkin); if (Port.IsOpen == true) Port.Close(); } private void button4_Click(object sender, EventArgs e) { PortName = textBox2.Text; SSNSP.InitializePorts(); SSNSP.BslReset(true); SSNSP.TransmitPassword(); SSNSP.BslTxRx(Constants.BSLReceiveBlock, 0xFFE0, 32, null, blkin); string str; System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); str = enc.GetString(blkin); if (Port.IsOpen == true) Port.Close(); } private void button5_Click(object sender, EventArgs e) { PortName = textBox2.Text; SSNSP.InitializePorts(); SSNSP.BslReset(true); SSNSP.TransmitPassword(); SSNSP.BslTxRx(Constants.BSLMassErase, /* Command: Mass Erase */ 0xff00, /* Any address within flash memory. */ 0xa502, /* Required setting for mass erase! */ null, blkin); if (Port.IsOpen==true) Port.Close(); } private void SetSerialNumber_Load(object sender, EventArgs e) { for (int c=0;c<=12;c++) listBox1.Items.Add(Properties.Settings.Default.ComportStartingNumber+c); } //private void InitializeComponent() //{ // this.SuspendLayout(); // // // // SetSerialNumber // // // this.ClientSize = new System.Drawing.Size(292, 266); // this.Name = "SetSerialNumber"; // this.ResumeLayout(false); //} } }