I am working on a C# Algorithm in which i need to write dynamic inputs to the hardware platform. I am new to c# But i do have an algorithm in which i can write single input using winform textbox. Now i am trying to use the same winform, apply any iterative loop and update the values on the winform textboxes to get dynamic inputs, so i can have multiple outputs continuously. This is the following design equation on which my hardware model is working
Fx= kxx( x-xt)
Fy = kyy(y-yt)
Text boxes are
Kxx, kyy, xt, yt
I wanna apply some algorithm on kx and ky so i can have multple values for Fx and Fy. But again my winform right now is working on just one input i.e if i write discrete values to the textboxes and hit the button target_pos then hardware handle is moving toward given target. The syntax for the particular part is the following:
private void set_target_btn_Click(object sender, EventArgs e)
{
try
{
//parse params into 1 string
byte[] ui8Buffer = new byte[77];
byte[] floatByte = new byte[4];
float kxx = float.Parse(k_xx_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float kyy = float.Parse(k_yy_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float kxy = float.Parse(k_xy_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float kyx = float.Parse(k_yx_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float bxx = float.Parse(b_xx_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float byy = float.Parse(b_yy_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float bxy = float.Parse(b_xy_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float byx = float.Parse(b_yx_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float tar_gain = float.Parse(target_gain_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float tar_rot_angle = float.Parse(target_rot_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float targetx = float.Parse(targ_X_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
float targety = float.Parse(targ_Y_textbox.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
//pack into 1 data
ui8Buffer[0] = packetCheck[0];
ui8Buffer[1] = packetCheck[1];
ui8Buffer[2] = CMD_MSG;
ui8Buffer[3] = 0x00;
ui8Buffer[4] = 0x08;
ui8Buffer[5] = 67;
//ui8Buffer[6] = (byte)(N_target_index_comboBox.SelectedIndex + 1);
ui8Buffer[6] = (byte)(EXERCIZE_TARG);
ui8Buffer[7] = (byte)(((Int16)targetx) >> 8);
ui8Buffer[8] = (byte)(((Int16)targetx));
ui8Buffer[9] = (byte)(((Int16)targety) >> 8);
ui8Buffer[10] = (byte)(((Int16)targety));
ui8Buffer[11] = (byte)(en_target_comboBox.SelectedIndex);
ui8Buffer[12] = (byte)(en_main_comboBox.SelectedIndex);
GetBytesSingle(kxx, out floatByte);
floatByte.CopyTo(ui8Buffer, 13);
GetBytesSingle(kyy, out floatByte);
floatByte.CopyTo(ui8Buffer, 17);
GetBytesSingle(kxy, out floatByte);
floatByte.CopyTo(ui8Buffer, 21);
GetBytesSingle(kyx, out floatByte);
floatByte.CopyTo(ui8Buffer, 25);
GetBytesSingle(bxx, out floatByte);
floatByte.CopyTo(ui8Buffer, 29);
GetBytesSingle(byy, out floatByte);
floatByte.CopyTo(ui8Buffer, 33);
GetBytesSingle(bxy, out floatByte);
floatByte.CopyTo(ui8Buffer, 37);
GetBytesSingle(byx, out floatByte);
floatByte.CopyTo(ui8Buffer, 41);
GetBytesSingle(tar_gain, out floatByte);
floatByte.CopyTo(ui8Buffer, 45);
GetBytesSingle(tar_rot_angle, out floatByte);
floatByte.CopyTo(ui8Buffer, 49);
//get checksum
ui8Buffer[73] = 0;
for (int i = 2; i < (6 + ui8Buffer[5]); i++)
{
ui8Buffer[73] ^= ui8Buffer[i];
}
ui8Buffer[74] = packetCheck[2];
ui8Buffer[75] = packetCheck[3];
ui8Buffer[76] = ENCRYPT_EN;
Console.WriteLine(ByteArrayToHexViaLookup32(ui8Buffer));
//send data if open
if (host_listening)
{
//send data
// Sends data asynchronously to a connected Socket
client_handler.BeginSend(ui8Buffer, 0, ui8Buffer.Length, 0,
new AsyncCallback(SendCallback), client_handler);
}
}
catch (Exception exc) { MessageBox.Show(exc.ToString()); }
}