GXDN: Gurux Developer Network
Send Method (data, type)
NamespacesGurux.SerialGXSerialSend(Object, VariantType)
Sends data asynchronously.
No reply from the receiver, whether or not the operation was successful, is expected.
Parameters
data (Object)
Data to send to the device.
type (VariantType)
The type that data is converted to, before sending.
Remarks
Reply data is received through OnReceived event.
Examples
CopyVBScript
                Sub SendBtn_Click()
    On Error GoTo GXErr
    'Send ASCII (text) string to the device.
    dim dataToSend as string
    dataToSend = "Test"
    GXSerial1.Send dataToSend, GX_VT_NONE

    'Send Hex string to the device.
    dim dataToSend as string
    dataToSend = "0x01 0x02 03 04"
    GXSerial1.Send dataToSend, GX_VT_HEX_STR

    'Send byte to the device.
    dim dataToSend
    dataToSend = "55"
    GXSerial1.Send dataToSend, GX_VT_BYTE
    'Send byte array to the device.
    dim dataToSend(3)
    dataToSend(0) = 0
    dataToSend(1) = 1
    dataToSend(2) = 2
    GXSerial1.Send dataToSend, GX_VT_NONE
    Exit Sub
GXErr:
    MsgBox Err.Description
End Sub
Examples
CopyC#
                /// <summary>
/// Sends data to the serial port.
/// </summary>
/// <param name="eventSender"></param>
/// <param name="eventArgs"></param>
private void SendBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
{
    try
    {
        ReceivedText.Text = string.Empty;
        object Data;
        if (SyncBtn.Checked) // Sends data synchronously.
        {
            if (HexCB.Checked)
            {
                // Sends data as byte array.
                gxSerial1.SendSync(SendText.Text, Gurux.Common.VariantType.HexString, EOPText.Text, Convert.ToInt32(MinSizeTB.Text), Convert.ToInt32(WaitTimeTB.Text), true, Gurux.Common.VariantType.HexString, out Data);
                ReceivedText.Text = Convert.ToString(Data);
            }
            else
            {
                // Sends data as ASCII string.
                gxSerial1.SendSync(SendText.Text, Gurux.Common.VariantType.None, EOPText.Text, Convert.ToInt32(MinSizeTB.Text), Convert.ToInt32(WaitTimeTB.Text), true, Gurux.Common.VariantType.String, out Data);
                ReceivedText.Text = Convert.ToString(Data);
            }
        }
        else // Sends data asynchronously.
        {
            if (HexCB.Checked)
            {
                // Sends data as byte array.
                gxSerial1.Send(SendText.Text, Gurux.Common.VariantType.HexString);
            }
            else
            {
                // Sends data as ASCII string.
                gxSerial1.Send(SendText.Text, Gurux.Common.VariantType.String);
            }
        }
    }
    catch (Exception Ex)
    {
        MessageBox.Show(Ex.Message);
    }
}
CopyVB.NET
                ''' <summary>
''' Sends data to the serial port.
''' </summary>
Private Sub SendBtn_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles SendBtn.Click
    ReceivedText.Text = String.Empty
    Try
        Dim Data As String
        Data = Nothing
        If SyncBtn.CheckState = 1 Then 'Sends data synchronously.
            If HexCB.CheckState = 1 Then
                'Sends data as byte array.
                GxSerial1.SendSync(SendText.Text, Gurux.Common.VariantType.HexString, EOPText.Text, MinSizeTB.Text, WaitTimeTB.Text, True, Gurux.Common.VariantType.HexString, Data)
                ReceivedText.Text = Data
            Else
                'Send data as ASCII string.
                GxSerial1.SendSync(SendText.Text, Gurux.Common.VariantType.None, EOPText.Text, MinSizeTB.Text, WaitTimeTB.Text, True, Gurux.Common.VariantType.String, Data)
                ReceivedText.Text = Data
            End If
        Else 'Sends data asynchronously.
            If HexCB.CheckState = 1 Then
                'Sends data as byte array.
                GxSerial1.Send(SendText.Text, Gurux.Common.VariantType.HexString)
            Else
                'Sends data as ASCII string
                GxSerial1.Send(SendText.Text, Gurux.Common.VariantType.String)
            End If
        End If
    Catch Ex As Exception
        MessageBox.Show(Ex.Message)
    End Try
End Sub
CopyVBScript
                'Send data
Private Sub SendBtn_Click()
On Error GoTo GXErr
    Dim Data As String
    If SyncBtn.Value = 1 Then 'Send data syncronous
        If HexCB.Value = 1 Then
            'Send data as byte array.
            GXSerial1.SendSync SendText.Text, GX_VT_HEX_STR, CByte(&H7D), 9, -1, True, GX_VT_HEX_STR, Data
            ReceivedText.Text = Data
        Else
            'Send data as ASCII string
            GXSerial1.SendSync SendText.Text, GX_VT_NONE, Empty, 9, -1, True, GX_VT_STR, Data
            ReceivedText.Text = Data
        End If
    Else 'Send data asyncronous
        If HexCB.Value = 1 Then
            'Send data as byte array.
            GXSerial1.Send SendText.Text, GX_VT_HEX_STR
        Else
            'Send data as ASCII string
            GXSerial1.Send SendText.Text, GX_VT_STR
        End If
    End If
    Exit Sub
GXErr:
    MsgBox Err.Description
End Sub
See Also

Assembly: Gurux.Serial (Module: Gurux.Serial) Version: 5.0.0.2