GXSerial component sends received data through this method.
private void gxSerial1_OnReceived(object sender, byte[] Data, string SenderInfo)
{
try
{
// Byte array received from GXSerial, and must be changed to chars.
if (HexCB.Checked)
{
ReceivedText.Text += BitConverter.ToString((byte[])Data);
}
else
{
// Gets received data as string.
ReceivedText.Text += System.Text.Encoding.ASCII.GetString((byte[])Data);
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
''' <summary>
''' Show received data.
''' </summary>
Private Sub GxSerial1_OnReceived(ByVal sender As System.Object, ByVal Data() As System.Byte, ByVal SenderInfo As System.String) Handles GxSerial1.OnReceived
Try
'Byte array received from GXSerial, and must be changed to chars.
If (HexCB.Checked) Then
ReceivedText.Text += BitConverter.ToString(Data)
Else
'Gets received data as string.
ReceivedText.Text += System.Text.Encoding.ASCII.GetString(Data)
End If
Catch Ex As Exception
MessageBox.Show(Ex.Message)
End Try
End Sub
'New data from GXSerial is received
Private Sub GXSerial1_OnReceived(ByVal sender As Object, var As Variant, ByVal SenderInfo As String)
On Error GoTo GXErr
'We receive byte array from GXSerial and this must be changed to chars.
Dim a As Long, str As String
For a = 0 To UBound(var)
If HexCB.Value = 1 Then
str = str + Hex(var(a)) + " "
Else
'Convert byte to chr
str = str + Chr(var(a))
End If
Next
ReceivedText.Text = str
ReceivedTB.Text = ReceivedTB.Text + UBound(var)
Exit Sub
GXErr:
MsgBox Err.Description
End Sub
Assembly: Gurux.Serial (Module: Gurux.Serial) Version: 5.0.0.2