Sends data asynchronously.
No reply from the receiver, whether or not the operation was successful, is expected.
No reply from the receiver, whether or not the operation was successful, is expected.
- data (Object)
- Data to send to the device.
- type (VariantType)
- The type that data is converted to before sending.
- receiver (String)
- IP address of the receiver (optional).
Reply data is received through OnReceived event.
'Send ASCII (text) string to the device.
dim dataToSend as string
dataToSend = "Test"
GXNet1.Send dataToSend, 0, ""
'Send Hex string to the device.
dim dataToSend as string
dataToSend = "0x01 0x02 03 04"
GXNet1.Send dataToSend, GX_VT_HEX_STR, ""
'Send byte to the device.
dim dataToSend
dataToSend = "55"
GXNet1.Send dataToSend, GX_VT_BYTE, ""
'Send byte array to the device.
dim dataToSend(3)
dataToSend(0) = 0
dataToSend(1) = 1
dataToSend(2) = 2
GXNet1.Send dataToSend, 0, ""
/// <summary>
/// Send data.
/// </summary>
/// <param name="eventSender"></param>
/// <param name="eventArgs"></param>
private void SendBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
{
try
{
ReceivedText.Text = "";
Gurux.Common.VariantType SendType;
object reply;
//Is data send as hex or string.
if (HexCB.Checked)
{
SendType = Gurux.Common.VariantType.HexString;
}
else
{
SendType = Gurux.Common.VariantType.String;
}
if (SyncBtn.Checked)
{
//Send sync data and wait reply for 1 second.
if (gxNet1.SendSync(SendText.Text, SendType, Receiver.Text, 0, -1, 1000, true, Gurux.Common.VariantType.HexString, out reply))
{
ReceivedText.Text = Convert.ToString(reply);
}
else
{
ReceivedText.Text = "Reply not received.";
}
}
else
{
gxNet1.Send(SendText.Text, SendType, Receiver.Text);
}
}
catch (Exception Ex)
{
//disable timer is exists
if (IntervalTimer.Enabled)
{
IntervalBtn_Click(IntervalBtn, new System.EventArgs());
}
MessageBox.Show(Ex.Message);
}
}
''' <summary>
''' Send data.
''' </summary>
Private Sub SendBtn_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles SendBtn.Click
Try
ReceivedText.Text = ""
Dim SendType, reply As Object
reply = Nothing
'Is data send as hex or string.
If HexCB.CheckState = 1 Then
SendType = Gurux.Common.VariantType.HexString
Else
SendType = Gurux.Common.VariantType.String
End If
If SyncBtn.CheckState Then
'Send sync data and wait reply for 1 second.
If GxNet1.SendSync(SendText.Text, SendType, Receiver.Text, 0, -1, 1000, True, Gurux.Common.VariantType.HexString, reply) Then
ReceivedText.Text = reply
Else
ReceivedText.Text = "Reply not received."
End If
Else
'UPGRADE_WARNING: Couldn't resolve default property of object SendType. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
GxNet1.Send(SendText.Text, SendType, Receiver.Text)
End If
Catch Ex As Exception
'disable timer is exists
If IntervalTimer.Enabled Then
IntervalBtn_Click(IntervalBtn, New System.EventArgs())
End If
MessageBox.Show(Ex.Message)
End Try
End Sub
'Send data
Private Sub SendBtn_Click()
On Error GoTo GXErr
ReceivedText.Text = ""
Dim SendType, reply
'Is data send as hex or string.
If HexCB.Value = 1 Then
SendType = GX_VT_HEX_STR
Else
SendType = GX_VT_STR
End If
If SyncBtn.Value Then
'Send sync data and wait reply for 1 second.
If GXNet1.SendSync(SendText.Text, SendType, Receiver.Text, 0, -1, 1000, True, GX_VT_HEX_STR, reply) Then
ReceivedText.Text = reply
Else
ReceivedText.Text = "Reply not received."
End If
Else
GXNet1.Send SendText.Text, SendType, Receiver.Text
End If
Exit Sub
GXErr:
'disable timer is exists
If IntervalTimer.Enabled Then
IntervalBtn_Click
End If
MsgBox Err.Description
End Sub
Assembly: Gurux.Net (Module: Gurux.Net) Version: 5.0.0.1