Jump to content
OMRON Forums

Code example - VB - How to communicate with a smart camera over an Ethernet TCP/IP socket


Recommended Posts

Posted

For the full project see the attachment. Below is a step by step description using Visual Basic:

1. Import the following libraries:

Imports System.Net.Sockets

Imports System.Text

2. Define the following variables which are used in the code lines later:

Dim ClientSocket As New TcpClient

Dim ServerStream As NetworkStream

Dim ServerAddress As String = "192.168.0.100"

Dim PortNumber As Integer = 49211

Dim ReceivedData As String

Dim inStream(10024) As Byte

3. Connect to camera:

ClientSocket.Connect(ServerAddress, PortNumber)

4. Send data:

Dim OutStream As Byte() = _

System.Text.Encoding.ASCII.GetBytes("jobinfo\r\n")

ServerStream.Write(OutStream, 0, OutStream.Length)

ServerStream.Flush()

5. Receive data:
To receive data from the camera in a safe way (without losing data), we need to listen to the socket continuously on a separate thread. The thread function will use a while loop in the following way:

While 1

ServerStream.Read(inStream, 0, CInt(ClientSocket.ReceiveBufferSize))

ReceivedData = Encoding.ASCII.GetString(inStream)

txtShow()

End While

*The function txtShow() is a local service routine to display the data.

Operating System

Any

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...