关于serialPort 接受到串口数据以后处理理的问题
下面是我写的一段代码,在接到受到text的数据后,我想把里面的每一个数据都倒过来,再添加别的处理。类似于------------------------------------------------------------------------------------------------------------
NumArray(1) = Chr(StringTemp(6)) '6个字节的数据位
NumArray(2) = Chr(StringTemp(5))
NumArray(3) = Chr(StringTemp(4))
NumArray(4) = Chr(StringTemp(3))
NumArray(5) = Chr(StringTemp(2))
NumArray(6) = Chr(StringTemp(1))
NumArray(0) = StringTemp(8) '提取第9字节 数据的正负及小数点的位置
LightStatus = StringTemp(7) '提取第8字节 指示灯点亮状态
------------------------------------------------------------------------------------------------------
这种形式的,又没有人能帮帮我啊。先谢谢了阿
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
delegate void SetTextCallback(string text);
private void Form1_Load(object sender, EventArgs e)
{
try
{
this.serialPort1.Close();
this.serialPort1.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SetText(this.serialPort1.ReadExisting());
}
private void SetText(string text)
{
if (this.txtData.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.txtData.Text = text;
}
}