Jump to content
OMRON Forums

Code Example - C# - How to send commands to a smart camera over TCP/IP


Recommended Posts

  1. Add the following reference to use Microsoft TCP sockets:
using System.Net.Sockets;
  1. Create the client object:
System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
  1. Connect to the camera:

int port = System.Convert.ToInt32("49211");


clientSocket.Connect("192.168.188.2", port); Create stream object:

 

  1. Send data to the camera:

NetworkStream serverStream = clientSocket.GetStream();

Prepare text to send (sending jobinfo command - see user manual for details):

byte[] outStream = System.Text.Encoding.ASCII.GetBytes("jobinfo\r\n");

 

Send the data:

serverStream.Write(outStream, 0, outStream.Length);

serverStream.Flush();

  1. Receive data from the camera:

byte[] inStream = new byte[10025];

serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);

string returndata = System.Text.Encoding.ASCII.GetString(inStream);

For the complete VisualStudio project, see attachment.

Operating System

Any

Link to comment
Share on other sites

  • 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...