请教: 关于串口接收到string类型数据转换的问题
下面是我写的程序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;
}
}
text就是我接收到的数据,为string类型。里面有8个字节数据,包含6个数字,一个小数点位,一个指示灯的数据。其中每个数据都是倒过来的,比如说本来仪器显示1234,可是接收到以后就成了4321了,我现在想把它改过来,在网上找了一个vb的源码
'------------------------------------------------read data-----------------------------------------------
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字节 指示灯点亮状态
'-------------------------------------------------end---------------------------------------------------
'---------------------------------------------Judge Dot-------------------------------------------------
DotPosition = 8 - (NumArray(0) And &HF&)
'-------------------------------------------------end----------------------------------------------------
If DotPosition < 2 Or DotPosition > 7 Then
Exit Sub
End If
'---------------------------------------------Judge Negative--------------------------
If NumArray(0) > 127 Then
NumArray(0) = "-"
Else
NumArray(0) = " "
End If
'-------------------------------------------------end----------------------------------------------------
For i% = 7 To DotPosition Step -1
NumArray(i) = NumArray(i - 1)
Next i
NumArray(DotPosition) = "."
iZero = 1
While ZeroSwitch = False
If NumArray(iZero) <> "0" Then
ZeroSwitch = True
Else
If NumArray(iZero + 1) <> "." Then
NumArray(iZero) = " "
iZero = iZero + 1
Else
ZeroSwitch = True
End If
End If
Wend
Temp$ = NumArray(0) + NumArray(1) + NumArray(2) + NumArray(3) + NumArray(4) + NumArray(5) + NumArray(6) + NumArray(7)
TextShow.Text = Temp
我看不大懂上面的意思,想请各位大侠帮帮我,最好能说得具体点,麻烦各位了