realvirtual.io
  • Building Digital Twins with Unity and realvirtual.io
  • Basics
    • Installation
    • Demo Model
      • Old Demo Model
    • Editor User Interface
      • Hierarchy Window
      • 3D Views
      • Quick Edit
      • Move Pivot Points (Pro)
      • Selection Window (Pro)
      • Material Window (Pro)
      • Measurement (Pro)
      • Kinematic Tool (Pro)
      • Model Checker
    • Runtime UI
      • Group Manager
      • Debug Console
      • Responsiveness
      • Runtime Persistence
    • Importing and exporting
    • Folder structure
    • Tutorial
    • Physics
    • CAD import (Pro)
      • CADLink (Pro)
      • CAD Checker (Pro)
      • CAD Updater (Pro)
    • Reusable Components (Prefabs)
    • Cadenas parts4cad
    • Publishing the Digital Twin
    • Revision management
  • News
  • Login & Download Updates (Pro)
  • Components & Scripts
    • Realvirtual
      • Environment Controller
    • MU, Source and Sink
      • Source
      • Sink
    • Motion and Kinematic
      • Drive
      • Kinematic
      • Group
      • Joint
      • CAM
      • TransportSurface
      • Guided Transport
      • KinematicMU (Pro)
      • Drive behavior
      • Chain
      • Chain element
      • Motion for developers
    • Sensors
      • Sensor
      • Measure
      • MeasureRaycast
    • Picking and Placing MUs
      • Grip
      • Gripper
      • Fixer
      • Pattern
    • Changing MUs
      • MaterialChanger
      • PartChanger
      • Cutter
    • Scene Interaction
      • Tooltip (Pro)
      • 3D Buttons
      • Screen Overlay Buttons
      • Scene Selectables (Pro)
      • Lamp
      • Interact3D
      • UI components
      • HMI components (Pro)
        • Start your own HMI
        • HMI Tab
        • HMI DropDown
        • HMI Puschbutton
        • HMI Switch
        • HMI Value
        • HMI Text
        • HMI Slider
        • HMI Message
        • HMI Marker
      • ModelZoo (Pro)
    • Interfaces
      • Interface Tools
        • Signal Manager
        • Signal Importer Exporter
        • Signal Catcher
        • OnValueChangedReconnect
      • Signal Importer / Exporter
      • ABB RobotStudio (Pro)
      • Denso Robotics (Pro)
      • EthernetIP (Pro)
      • Fanuc (Pro)
      • FMI
      • Igus Rebel
      • MQTT (Pro)
      • Modbus (Pro)
      • OPCUA (Pro)
      • PLCSIM Advanced (Pro)
      • RoboDK (Pro)
      • RFSuite (Pro)
      • SEW SimInterface (Pro)
      • Siemens Simit Interface (Pro)
      • Simit Shared Memory (Pro)
      • Simulink (Pro)
      • S7 TCP
      • TwinCAT (Pro)
      • TwinCAT HMI (Pro)
      • UDP (Pro)
      • Universal Robots (Pro)
      • Wandelbots Nova (Pro)
      • Websocket (Pro)
      • Windmod Y200 (Pro)
      • Custom Interfaces
    • Performance Tools
      • Combine Meshes (Pro)
      • Create Prefab (Pro)
      • Hierarchy Cleanup (Pro)
      • Mesh Optimizer (Pro)
      • Performance Optimizer (Pro)
    • Defining Logic
      • Unity Scripting
      • Behavior Graph
      • Logicsteps
      • Unity Visual Scripting
      • Recorder
    • Robot Inverse Kinematics (Pro)
    • Volume Tracking (Pro)
  • Multiplayer (Pro)
  • Extensions
    • ModelZoo
      • Beckhoff TwinCAT
      • Siemens S7
      • Denso Cobotta 1300
      • Wandelbots Nova Fanuc CRX
      • Universal Robots UR10
      • Fanuc Roboguide
    • realvirtual.io AIBuilder
      • realvirtual.io AI Builder Overview
      • Generate AI Training Data
      • AI Training
      • Testing AI in a Digital Twin
      • Deploying the AI
    • realvirtual.io Simulation
      • Conveyor Library
      • Path System
        • Path finding
        • Line
        • Curve
        • Workstation
        • Catcher
        • Pathmover
    • realvirtual.io Industrial Metaverse
      • Setup Guide
      • VR Modules
      • AR Modules
      • Multiuser
    • AGX Physics
    • VR Builder
    • CMC ViewR
  • Advanced Topics
    • Render Pipelines
    • Mixed Reality with Meta Quest3
    • Upgrade Guide
      • Upgrade to 2022
    • Open Digital Twin Interface
    • Usefull Addons
    • Improving Performance
    • Supported Platforms
    • Compiler Defines
    • For Developers
      • Important Classes and Interfaces
      • Assembly Definitions
      • Starting your development
      • Class documentation
      • realvirtual Init Sequence
      • realvirtualBehavior Lifetime Methods
      • Testing
    • Newtonsoft JSON
    • Troubleshooting
  • Release Notes
  • AI Digital Twin Assistant (GPT4)
  • License Conditions
Powered by GitBook
On this page
  • Prerequisites
  • Using the interface
  • Implementing the interface as a client to your Application
Edit on GitHub
  1. Components & Scripts
  2. Interfaces

Websocket (Pro)

Interfacing external applications with realvirtual.io

PreviousWandelbots Nova (Pro)NextWindmod Y200 (Pro)

Last updated 12 months ago

This interface is currently in Beta

The Websocket Realtime Interface offers high performance with low cycle times and rapid signal communication. It serves as a public interface, enabling connectivity between any application and realvirtual.io. Leveraging websocket as the underlying technology provides versatility, as it is compatible with all platforms, including WebGL.

Prerequisites

To enable the Websocket Realtime Interface, ensure that you add REALVIRTUAL_JSON to your Scripting Define Symbols. This interface utilizes Newtonsoft.Json. For detailed instructions, refer to the section for more information.

Using the interface

You can utilize the WebSocket Realtime Interface as both a server and a client, allowing for example also to connect two Unity instances for distributed simulations.

Setting Up the Server:

  • Address: Set the address to 127.0.0.1 (localhost).

  • Port: Choose a port according to your preference. Standard ports include 80 and 443.

Configuring the Client:

  • Address: Input the server's public IP address.

  • Port: Select a port as needed.

Importing Signal Data:

During edit mode, you have the option to import signal data, simplifying the configuration process by only requiring setup on one side. To enable this feature, start the server during edit mode.

Automatic Connection:

By enabling "Connect On Play," the server and client automatically establish a connection when the simulation is initiated.

Implementing the interface as a client to your Application

To implement the Websocket Interface, the client must send the following JSON when connecting to the server:

{"tag":"init","content":"Client"}

This informs the server that the client named "Client" is connected. After the connection is established, the client will receive the server's data (which includes all PLC inputs on the server side) via a JSON like this:

{"tag":"data","content":"{"InputBools":[{"name":"Bool 2","value":true}],"InputInts":[],"InputFloats":[{"name":"Float 1","value":0.2}],"InputTexts":[],"OutputBools":[{"name":"Bool 1","value":false}],"OutputInts":[],"OutputFloats":[],"OutputTexts":[]}"}

You can utilize the following C# classes for serializing and deserializing the JSONs:

using System;
using System.Collections.Generic;

[Serializable]
public class SignalData
{
    public List<Signal<bool>> InputBools;
    public List<Signal<int>> InputInts;
    public List<Signal<float>> InputFloats;
    public List<Signal<string>> InputTexts;
    public List<Signal<bool>> OutputBools;
    public List<Signal<int>> OutputInts;
    public List<Signal<float>> OutputFloats;
    public List<Signal<string>> OutputTexts;
}

[Serializable]
public class Signal<T>
{
    public string name;
    public T value;
}

[Serializable]
public class Message
{
    public string tag;
    public string content;
}

The message structure consists of a header "tag" defining the content of the message, followed by "content". The content is always a string which can include the message or the include the full json of the serialized "SignalData". The following tags are used:

  • init: Followed by the client name sent from the client to the server at the start of the communication.

  • request_import: From the client to the server or vice versa for requesting the full input and output signal list from the server or client. This is used for signal initialization on one side based on the predefined signals on the other side.

  • data: Followed by all SignalData during signal exchange.

Newtonsoft Json
Websocket Interface Server Side
Websocket Interface Client Side