I'll try to summarize the issue the best way I can. I recently purchased a dual interface board that has TCP communication capabilities. In order to get information from the board an array of bytes needs sent to the board in which it will respond with the desired information. In node red I have been able to send the array of bytes using a function and receive a response from the TCP module.
However I would like to use this in an application I am developing that is more user-friendly than node red. Unfortunately, no matter what I have tried I have not been able to receive a response from the device using Visual Basic.
In node red, the array looks something like this:
Msg.payload = Buffer.from([8,121,50,3,100)];
Without buffer.from the device would not respond. I have tried encoding the string in VB into a byte variable and sending via socket, but am having no luck. Any suggestions? Here is the VB code.
Imports System.Net
Public Class Form1
Dim TCPClientz As Sockets.TcpClient
Dim TCPClientStream As Sockets.NetworkStream
Private Sub SendBytesButton_Click(sender As Object, e As EventArgs) Handles SendBytesButton.Click
'Dim intcount As Integer
Dim sendbytes() As Byte = System.Text.Encoding.UTF8.GetBytes(bytestextbox.Text)
TCPClientz = New Sockets.TcpClient(ServerTextBox.Text, PortTextBox.Text) 'Device IP and Port are working. Changing port throws error.
TCPClientStream = TCPClientz.GetStream()
'intcount = TCPClientz.Client.Send(sendbytes)
TCPClientStream.Write(sendbytes, 0, sendbytes.Length)
If TCPClientStream.DataAvailable = True Then 'At this point, I NEVER have gotten the stream to indicate there is available data.
Dim rcvbytes(TCPClientz.ReceiveBufferSize) As Byte
TCPClientStream.Read(rcvbytes, 0, CInt(TCPClientz.ReceiveBufferSize))
replytextbox.Text = System.Text.Encoding.UTF8.GetString(rcvbytes)
End If
End Sub
Does anyone know of any way to capture the bytes being sent by NODE-RED? I can view the payload, but I don't believe this is a representation of the actual bytes being sent. I could try to pair this up with the BYTE array in VB to see if they match.