I have b1 and b2 which are all in byte, I am using serialport.write to send them separately. Can I send them at the same time? As in using one command instead of two. My existing code:
private void SConvert_Click(object sender, EventArgs e)
{
byte[] b1 = null, b2 = null;
string[] coords = textBox1.Text.Split('\n');
for (int i = 0; i <= coords.Length - 1; i++)
{
if (coords[i].Length > 0)
{
GetValue(coords[i], out b1, out b2);
}
if (serialPort.IsOpen)
{
serialPort.Write(b1, 0, 4);
serialPort.Write(b2, 0, 4);
}
}
}
private void GetValue(string strValue, out byte[] b1, out byte[] b2)
{
string S1, S2, S = strValue;
string[] x = S.Split(',');
string y = x[0].ToString();//{lat=-36.123333
string z = x[1].ToString();//lng=174.333333} // index outside bounds of the array
S1 = y.Substring(y.IndexOf('=') + 1);
string z1 = z.Replace("}", "0"); // replace } by 0 since do not know length of }
S2 = z1.Substring(z1.IndexOf('=') + 1);
float f1 = float.Parse(S1), f2 = float.Parse(S2);
b1 = System.BitConverter.GetBytes(f1);
b2 = System.BitConverter.GetBytes(f2);
}