public void viewBinaryDump(BinaryGenerator binGen) { //if (string.IsNullOrEmpty(source)) return; //this.binGen = binGen; var tmp = binGen.getBinaryDump(); if (tmp[tmp.Count - 1] == null) { tmp.RemoveAt(tmp.Count - 1); } bytes = (byte[])tmp.ToArray(typeof(byte)); string[] dump = binGen.getBinaryDumpToString(len); string[] ASCIIDump = binGen.getACIIDumpToString(len); updateDataGrid(dump, ASCIIDump, binGen.getStartAddress()); }
private void sendToKR580ToolStripMenuItem_Click(object sender, EventArgs e) { if (CurrentTB == null) { return; } if (string.IsNullOrEmpty(PS.ComPortName)) { MessageBox.Show("Choose an appropriate COM-Port first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (GetBinary(CurrentTB.Text, Constants.defaultStartingAdress + Constants.smallProgramLoaderSize + Constants.BigProgramLoader.Length) == null) { return; } byte[] tmp = GetNewSettings(PS); Constants.BigProgramLoader[16] = tmp[0]; Constants.BigProgramLoader[20] = tmp[1]; SendBigLoader(Constants.BigProgramLoader); var port = new SerialPort(PS.ComPortName, PS.baud, PS.par, PS.databits, PS.sb); try { stStrip.Items[0].Text = "Sending to KR580..."; stStrip.Refresh(); port.Open(); var _data = new ArrayList(BinGen.getBinaryDump()); byte[] startAddr = BitConverter.GetBytes(BinGen.getStartAddress()); stStrip.Items[1].Text = "| Start address of your program in memory = " + startAddr[0] + startAddr[1]; var data = new byte[_data.Count * 2 + 3]; data[0] = 1; data[1] = startAddr[1]; data[2] = startAddr[0]; int j = 0; for (int i = 3; i < data.Count(); i++) { if (i % 2 == 1) { data[i] = 2; } else { data[i] = (_data[j] != null ? (byte)_data[j] : (byte)0); j += 1; } } Cursor.Current = Cursors.WaitCursor; for (int i = 0; i < data.Length; ++i) { port.Write(data, i, 1); Thread.Sleep(Constants.sleepDelay); } Cursor.Current = Cursors.Default; port.Close(); stStrip.Items[0].Text = "Sending succesfully comleted"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }