//*********************************************************************** // execute_command : format and execute a command to uP/FPGA // =============== // // Parameters // cmd_name char IN single ASCII character representing uP/FPGA command // port int IN return address of command // register int IN register address (0->255) if FPGA command // in_data int IN data for command // out_data int OUT First piece of data returned by executed command // // Returned values // status Error value of type 'ErrorCode@ // out_data int returned from FPGA public FPGA_uP_IO.ErrorCode execute_command(char cmd_name, int port, int register, int in_data, out int out_data) { string command_str = cmd_name + " " + port + " " + register + " " + in_data + "\n"; FPGA_uP_IO.ErrorCode status = (do_command(command_str, out out_data)); return(status); }
//**************************************************************** // Run command to write to a specified register private void Write_Register_Click(object sender, EventArgs e) { int out_data; int data = int.Parse(textBox1.Text, System.Globalization.NumberStyles.HexNumber); FPGA_uP_IO.ErrorCode status = FPGA_uP_IO.execute_command('w', DEFAULT_PORT, (int)numericUpDown1.Value, data, out out_data); InfoWindow.AppendText("Return code = " + status + Environment.NewLine); }
private void Close__COM_port_Click(object sender, EventArgs e) { FPGA_uP_IO.ErrorCode status = FPGA_uP_IO.Close_comms(); if (status != FPGA_uP_IO.ErrorCode.NO_ERROR) { InfoWindow.AppendText("Cannot close COM port" + Environment.NewLine); return; } InfoWindow.AppendText("COM port now closed" + Environment.NewLine); }
//**************************************************************** // Run command to read a specified register private void Read_Register_Click(object sender, EventArgs e) { int data; int count = (int)numericUpDown8.Value; for (int i = 0; i < count; i++) { FPGA_uP_IO.ErrorCode status = FPGA_uP_IO.execute_command('r', DEFAULT_PORT, (int)numericUpDown2.Value, 0, out data); InfoWindow.AppendText("Register Value = " + data + "/0x" + Convert.ToString(data, 16) + Environment.NewLine); InfoWindow.AppendText("Return code = " + status + Environment.NewLine); } }
//*********************************************************** // do_command : execute command on uP/FPGA system // ========== public FPGA_uP_IO.ErrorCode do_command(string command, out int data) { string reply_string; FPGA_uP_IO.ErrorCode status = FPGA_uP_IO.ErrorCode.NO_ERROR; // // if in Debug mode execute a local version of 'do_command' thet // writes received debug information to a debug window. // if (!Debug) { int tmp_data = 0; status = FPGA_uP_IO.do_command(command, out tmp_data); data = tmp_data; return(status); } reply_string = "\n"; status = FPGA_uP_IO.send_command(command); data = 0; if (status != FPGA_uP_IO.ErrorCode.NO_ERROR) { return(status); } for (; ;) { status = FPGA_uP_IO.get_reply(ref reply_string); if ((reply_string[0] == 'D') && (reply_string[1] == ':')) { DebugWindow.AppendText(reply_string + Environment.NewLine); continue; } else { break; } } if (status != FPGA_uP_IO.ErrorCode.NO_ERROR) { return(status); } status = FPGA_uP_IO.parse_parameter_string(reply_string); if (status != FPGA_uP_IO.ErrorCode.NO_ERROR) { return(status); } data = FPGA_uP_IO.int_parameters[2]; return(status); }
//*********************************************************** // Open_COM_port : Open selected seial COM port // ============= private void Open_COM_port(object sender, EventArgs e) { if (comboBox1.SelectedItem == null) { InfoWindow.AppendText("No COM port selected " + Environment.NewLine); return; } string com_port = comboBox1.SelectedItem.ToString(); int baud_rate = Convert.ToInt32(comboBox2.SelectedItem); FPGA_uP_IO.ErrorCode status = FPGA_uP_IO.Init_comms(com_port, baud_rate); if (status != FPGA_uP_IO.ErrorCode.NO_ERROR) { InfoWindow.AppendText("Cannot open " + com_port + Environment.NewLine); return; } connected = true; button4.Enabled = true; InfoWindow.AppendText(com_port + " now open" + Environment.NewLine); }