Skip to main content

Protocol Emulator

The protocol emulator is used to directly establish Modbus or Siemens S7 slaves within GatewayRuntime, providing readable and writable simulation data to PLCs, host computers, configuration software, acquisition programs, and protocol testing tools. It is suitable for protocol joint debugging, point table verification, abnormal scene reproduction, training demonstrations, and automated testing, without the need to install additional standalone simulation software.

Pages use a unified three-level configuration model:

HierarchicalFunction
Simulation ChannelManage listening endpoints, serial ports, startup status, safety limits, diagnostic capacity, and fault injection.
Built-in protocol pluginSelect Modbus Slave or S7Slave from the dropdown to determine the protocol packet and address space.
Simulation variablesDefine protocol address, data type, initial value, access permissions, and automatic change patterns.
Difference from Collection Configuration

Protocol emulators use GatewayRuntime as a protocol server or slave. Collection Configuration usually uses GatewayRuntime as a client or master station to read field devices. Protocol simulation channels, protocol plugins, and simulation variables are managed only on this page.

Function Entry

Log in to GatewayRuntime Web and enter the "Developer Configuration → Protocol Emulator".

Protocol Emulator Workbench

Screenshot Description

The screenshots on this page are from the actual running page of the current GatewayRuntime, used to display the workbench layout, default parameters, and configuration entry. The sample channel in the screenshot is stopped and no variables are configured; actual running data is based on the user's own channel and client.

On the left side of the page is a list of simulation channels, at the top are the commands for refresh, import, edit, and run, and the workspace on the right contains the following content.

RegionDescription
Run SummaryDisplays listening endpoints, current client, number of requests, request rate, protocol errors, Reserved memory and the number of running generators.
VariablesPaginate variables, current values, change modes, and access modes, and perform add, batch add, write, pause, continue, save current value, and delete.
Raw memoryRead hexadecimal and ASCII data by protocol memory area; When permission is granted, it can preview and write to the original bytes.
ClientView connection endpoints, session phases, S7 negotiation PDUs, number of requests, error counts, and incoming traffic.
Messages and EventsQuery lifecycle, connections, requests, protocol errors, variable changes, and security denial events by page.
ConfigurationView protocols, security, diagnostics, and a complete configuration summary for the current channel.

When the browser width does not exceed 1024px, the channel list will automatically be included in the channel button to the left of the current channel name. Clicking this button allows you to switch or create a new channel in the drawer; The workspace occupies the remaining width, and filters, pagination, and forms are rearranged into two or single columns.

Preparations Before Configuration

Before configuration, determine the test client's protocol, network location, and target point table.

InformationContent to be confirmed
Protocol RoleThe tester must be connected as a Modbus master or S7 client GatewayRuntime.
Protocol pluginModbus client: Select Modbus Slave; For the S7 client, select S7Slave.
Channel TypeNetwork Listening uses TcpService; Modbus RTU serial port testing uses SerialPort.
Listen to endpointsConfirm available network card addresses, ports, firewalls, and port occupancy.
Address SpaceConfirm the Modbus station number and ribbon, or the I/Q/M/DB area and DB number of S7.
Write ScopeClarify which variables are allowed to be written by the client and which can only be modified by the page or generator.
Data patternsDetermine fixed values, waveforms, random quantities, sequences, pulse or string templates, and update cycles.
Event ScaleBefore long-term stress testing, determine event capacity, record successful requests, and capture the original packet.

Creating a New Simulation Channel

  1. On the left side, click "Protocol Emulator" under the title "Add" to the right.
  2. Enter the channel name in "Channel Configuration."
  3. In the "Protocol Plugin" dropdown, select Modbus Slave or S7Slave.
  4. Go to "Transmission Configuration," select the channel type, and fill in the monitoring or serial port parameters.
  5. Complete the Modbus or S7 Slave parameters according to the selected protocol.
  6. Check "Permissions & Security," "Diagnostics," and "Fault Injection."
  7. Click "Save". After saving, configure the variables first, then start the channel.

Create a new simulation channel

Channel configuration

Configuration itemsDescription
Channel NameThe unique name of the current simulation channel, recommended to include the protocol and purpose, such as modbus-line-demo.
Protocol Plugindropdown to select Modbus Slave or S7Slave. If you need to switch to another protocol after creation, you should create a new channel and re-verify the variable address.
Auto-startAfter starting, the simulation channel will automatically start when GatewayRuntime starts. Before officially activating, confirm that the listening port and variable configurations are correct.
DescriptionRecord the test subject, person in charge, port purpose, or joint debugging scope.

Transmission Configuration

The channel type belongs to "Transmission Configuration". Network services and serial ports are channel capabilities, not protocol plugins.

Simulation Channel Transmission Configuration

Channel TypeSupported ProtocolKey ParametersDescription
TcpServiceModbus, S7Slavelisten addresses, ports, listening queues, TCP NoDelay Handshake timeoutGatewayRuntime listens to the port and waits for the client to connect actively.
SerialPortModbusserial port, baud rate, data bits, parity bits, stop bits, flow control, receive timeout, frame intervals,used for Modbus RTU serial slave station simulation. The S7Slave does not use serial ports.

TcpService Common Settings:

Configuration ItemsDescription
Listening address127.0.0.1 Only local connections are allowed; LAN joint debugging and filling in the designated network card address; To monitor all network cards, you can enter 0.0.0.0.
PortsModbus TCP commonly uses 502, S7 commonly uses 102; Non-administrator test environments can use unoccupied high-level ports.
Listen queueControl the number of connections waiting to be received. Generally, the default value is maintained, and during concentrated stress testing, adjustments are made according to the planned number of clients.
TCP NoDelayreduces the wait time for small packets, and protocol debugging usually remains enabled.
Handshake TimeoutThe maximum waiting time for the protocol handshake to complete after client connection. When network latency is high, it can be appropriately increased.
port and network exposure

Listening 0.0.0.0 will open the port to all accessible network cards. The production network should be configured simultaneously with "allowed subnets," operating system firewalls, and border access policies; do not rely solely on ports without making them public.

Configure Modbus Slave

After selecting Modbus Slave, the channel supports the following combinations.

Simulation MethodChannel TypeMessage Format
Modbus TCPTcpServiceModbus TCP
RTU over TCPTcpServiceModbus RTU
Modbus RTU SerialSerialPortModbus RTU

Modbus Parameter

Configuration ItemsDescription
Station NumberOne or more slave station numbers can be configured, ranging from 1 to 247 and cannot be duplicated within the same channel.
Number of coilsAllocate the Coil address space for read/write booleans.
Discrete Input QuantityAllocate Discrete Input address space for read-only Booleans.
Number of input registersAllocate Input Register address space for read-only register data.
Maintain the number of registersAllocate the Holding Register address space for read/write register data.
Default byte orderSet the default byte/word order for multi-register values; Individual variables can still be configured individually.
Strict address modeRefuses access beyond allocated space or without valid mappings after enabled.

Variable addresses can be structured in format, for example:

address examplemeaning
S=1;F=1;0Station number 1, functional area 1, coil offset 0.
S=1;F=2;0Station number 1, ribbon 2, discrete input offset 0.
S=1;F=3;0Station number 1, Function Area 3, Offset 0 holding register.
S=1;F=4;0Station number 1, ribbon 4, input register offset 0.
S=1;F=3;10.3Keep the register offset to bit 3 in 10.

Configure S7Slave

After selecting S7Slave, GatewayRuntime runs as the real S7 slave/server, establishes connections via ISO-on-TCP, and handles COTP and Setup Communication, Read Var, and Write Var. It does not convert the S7 address into a Modbus address.

S7Slave Configuration

Configuration ItemsDescription
Frame Number / Slot NumberUsed to determine the local S7 connection identifier, it should match the client connection parameters.
Local TSAPlocal TSAP used by GatewayRuntime, such as 0x0101.
Allowed remote TSAPsClient TSAPs that can be restricted to which sessions can be established; If left vacant, assess according to the on-site safety strategy.
Maximum PDU Lengththe maximum PDU length negotiated by the S7 session; client settings cannot exceed server capacity.
Input area bytesAllocate volume to Area I.
Output bytes in the output areaAllocate Q area capacity.
Flag area bytesAllocate volume to the M section.
Data BlockConfigure one or more DB numbers and the number of bytes per DB.
Strict address modeWhen enabled, rejects access beyond the I/Q/M/DB allocation range.

The S7Slave variable can be mapped to the following address areas:

Address ExampleMeaning
IX0.0Input Region Byte 0 Bit, Bit 0.
QW10Words with output area offset by 10.
MD20double word with the logo area offset by 20.
DB1.DBX0.0DB1 byte 0, bit 0.
DB1.DBW2DB1 offsets the word by 2.
DB1.DBD4DB1 offset by 4 double words.

Permissions and Security

"Permissions and Security" control protocol: whether clients can access and write to the protocol; System role permission control allows logged-in users to execute management commands on the web. Both should be configured together.

Simulate Channel Permissions and Security

Channel Security Parameters

Configuration ItemsDescription
Allowed SegmentsAllowed IPv4/IPv6 CIDR Connections. The default loop segment is suitable for local testing; When debugging a local area network, only the segments actually needed are added.
Allows external protocols to write tomaster switches. When closing, the client's protocol write request will not modify the specification; After enabling it, also check variable access modes and external write policies.
Maximum number of clientsThe total number of clients allowed to connect simultaneously in the current channel.
Number of clients per IPThe maximum number of connections allowed by the same source IP.
Idle TimeoutThe number of seconds a client disconnects after a long period of inactivity.
Limit the continuous request rate perper second for a single client request.
Burst CapacityThe number of requests allowed for short-term bursts.
Invalid Frame Disconnection ThresholdProactively disconnects when the same connection generates too many invalid messages consecutively.

Web Role Permissions

Go to "System Management → Role Management" to assign page and button permissions to roles that need to use the protocol emulator. It is recommended to delegate according to the minimum responsibilities.

Permission groupsExecutable operations
View and refreshView channels, variables, runtime, memory, client, and pagination events.
Channel ManagementAdd, edit, and delete simulation channels.
Variable ManagementAdd, edit, batch add, and delete variables.
Operation controlstart, stop, and restart channels.
Data WritingPage Writes and Original Memory Writes.
Generator ControlPause or continue the generator of the selected variable.
Save the current valueSave the current runtime value as the initial value for the next startup.
Client ManagementDisconnect a specific client or disconnect all clients.
Incident ManagementClear diagnostic events in the current lane.
Import and ExportImport/export JSON channel configuration and Excel variable point table.
Read-only joint debugging account

Users who only need to observe the running results can be granted viewing and refresh permissions only. Pages hide or disable unauthorized commands to add, write, run, disconnect, and empty.

Configure simulation variables

After saving the channel, click "Add variable" or "Batch create variables" on the "Variables" page. The structural configuration can only be modified when the channel stops, preventing changes in the address space during client-side communication.

  1. Enter the unique variable name.
  2. Use the Address Assistant to select the protocol area, station number or DB number, offset, and bit number, or directly fill in the standard address.
  3. Select the data type and array length.
  4. Select byte order for multi-byte data in Modbus; Fill in the memory format for the string.
  5. Set access mode, external write policy, and initial value.
  6. When automatic changes are needed, enter the "Data Change Designer" to activate the generator.
  7. Check for usage range, out-of-bounds, and address conflict prompts, then save them.

Data Type

Data TypeDescription
BooleanBoolean values, which can be mapped to bit addresses, coils, or discrete inputs.
Byte8-bit unsigned integer.
Int16 / UInt1616-bit signed/unsigned integers.
Int32 / UInt3232-bit signed/unsigned integers.
Int64 / UInt6464-bit signed/unsigned integers, pages processed as exact decimal values.
Float / DoubleSingle-precision / double-precision floating-point count.
DecimalHigh-precision decimal numbers, suitable for test values requiring precise decimal representation.
StringFixed or length-headed strings, also supports S7 WSTRING.

When the "array length" exceeds 1, the variable occupies a contiguous address as a fixed-length array. Before increasing the array length, check whether subsequent addresses have been occupied by other variables.

Byte Order and Strings

Configuration ItemsDescription
Byte orderModbus multibyte variables can be selected ABCD,BADC,CDAB, DCBA. S7 Processing byte order according to protocol.
Number of bytes per elementReserve fixed space for each element of the string's array.
EncodingYou can choose or fill in UTF-8,ASCII, UTF-16BE, and other codes.
Length headerActual length information is stored in string memory; client-side parsing must be consistent.
S7 WSTRINGused only by S7Slave, distributed and encoded according to the S7 wide string format.

Access Modes and External Write Policies

Configuration ItemsBehaviors
Read-onlyNeither client nor page can use this variable as a regular writable point.
Read and writePages are writable; When the channel allows external protocols to write, the client can also write according to the external write policy.
Pages are writable and external rejectionWeb pages can write values, but Modbus/S7 client writes will be rejected.
Accept and continue changingAccept client-side writes, while the generator continues updating according to the original timeline.
Accepts and pauses the generatorAccepts client writes and pauses the variable generator to facilitate client-sent values.
Rejects external writesEven if the channel allows external writes, the variable still rejects client-side write requests.
Three-layer write check

Successful protocol write requires simultaneously satisfying the following permissions for role or page operations, the channel "Allow external protocol writes," and variable access modes/external write policies. Test points involving control logic should prioritize read-only or external denial modes.

Configure Data Changes and Seeds

Each variable can independently enable the generator. Common parameters include update cycle, startup latency, recovery strategy, algorithm version, and seed.

Change ModeApplicable Scenarios
FixedMaintain a fixed value.
RampIncreases or decreases step size, with selectable clamping, looping, round-trip, or out-of-bounds error modes.
Sinegenerates sine waves based on center value, amplitude, period, and phase.
Trianglegenerates a triangle wave.
Sawtoothgenerates sawtooth waves.
SquareGenerate square waves based on high/low values, period, and duty cycle.
RandomGenerate random values within a range according to a uniform or Gaussian distribution.
RandomWalkRandomly walks from the initial value according to the maximum step size.
Toggleflips periodically between Boolean true and false.
PulsePulses are generated by period, high level duration, and initial level.
SequencePlayback by step value and holding chronological order, can loop, repeat, or keep the last value.
TemplateGenerate strings such as batch numbers or time labels using counters and simulated time.

Deterministic Seeds

Random, RandomWalk, noise modifiers, and fault injection can all use configured seeds. The same algorithm version, seed, and configuration produce repeatable sequences suitable for automated regression testing and issue reproduction.

OperationRecommends
Fixing the seedRecord in the test case, Ensure that each run has the same trajectory.
Generate seedsTemporarily explore different random sequences; After confirming the issue, the generated value should be recorded.
Separating seedsMain generator, noise, and fault injection use different seeds for easy individual reproduction.
Modifying the algorithm versionwill alter the sequence results and should be fixed together with the seed in regression testing.

The numeric generator can also overlay zoom, offset, noise, mini/max clamping, quantization step size, and decimal places. First configure the basic waveform, then add modifiers item by item and preview to more quickly identify parameter issues.

Startup and Operation Control

  1. Confirm that the channel is "Stopped" and complete the configuration of the channel and variable structure.
  2. Click "Start" at the top. After successful startup, the summary area displays the listening endpoint and reserved memory.
  3. Connect to this endpoint using the actual Modbus master or S7 client and read and write variables.
  4. Observe the current value and generator status in the variable list; After selecting a variable, you can pause, continue, or save the current value as the initial value.
  5. Stop the channel before modifying the structural configuration; You can use "Restart" only when re-establishing listens and sessions.
CommandInstructions
Startallocate protocol memory and start listening or open the serial port.
StopDisable listening and client connections, allowing modification of channel and variable structures.
RestartAfter stopping, restart as configured as currently is.
Write ValueSet the current value for a single writable variable and choose whether to apply an external write strategy.
Pause/ContinueBatch control of the generator of the selected variable.
Save the current value as the initial valuePersist the current value for the next startup recovery. For bulk storage, it is recommended to select by business grouping.

Original Memory and Client

Original Memory

"Original Memory" is used to check whether variable values match protocol bytes.

ProtocolsOptional memory
ModbusCoils, Discrete Inputs, Holding Registers, Input Registers, and select the station number.
S7SlaveInputs, Outputs, Markers, Data Block; The Data Block also requires selecting the DB number.

After entering the byte offset and the number of bytes to be read, click "Read Memory". Before writing to hexadecimal, the page checks the coverage area; When intersecting with variable mapping, it will require reconfirmation. Original memory writes directly affect the corresponding variable and should only be used when the address layout is clearly understood.

Client

The "Client" page displays the remote endpoint of each connection, connection time, recent activity, number of requests/errors, and bytes sent and received. S7Slave also displays the session phase and negotiation PDU. If you need to terminate an abnormal connection, you can disconnect a single client or all clients.

Messages and Events

Determine the scope of records in the channel "diagnostics."

Protocol emulator diagnostic configuration

Configuration itemsDescription
Capture raw messagesSave hexadecimal content of requests and responses. It only activates during joint debugging and error troubleshooting to avoid recording unnecessary data.
Event CapacityThe maximum number of events held in the current channel. After reaching capacity, the oldest event is covered and will not grow indefinitely.
Maximum one-way capture byteLimits the number of raw bytes stored in a single request or response.
Record variable changesRecord changes caused by generator writes, page writes, and protocol writes. It can be turned off when there are many high-frequency points.
Record successful requestsRecord normal protocol requests. It can be turned off during prolonged high-frequency stress testing, retaining only errors and key events.

The "Messages and Events" page supports keyword and event type filtering, as well as server-side pagination.

Protocol Emulator Event Pagination

Event ContentDescription
Time and TypeDistinguishes lifecycle, client connection/disconnection, protocol requests, protocol errors, variable changes, generator status, security denial, and buffer coverage.
Messages and ClientsDisplays event summaries and associated clients.
Variables and Error CodesDisplays associated variables and protocol error codes.
Processing TimeDisplays request processing time to help locate abnormal and slow requests.
Request/Response MessageView the captured hexadecimal request and response after clicking the event.

The event list loads only the current page at a time. Switching page numbers, page sizes, or filter criteria will re-query the server; Automatic refresh cancels expired requests and does not cause concurrent stacking and repeated refreshes. The page will also show the number of old events that have been overwritten by the circular buffer.

Fault Injection

Fault injection is used for repeatable verification of client timeouts, reconnections, and exception handling, and should not be enabled long-term in production debugging channels.

Configuration ItemDescription
Enable fault injectionmaster switch. After turning off, do not apply delay, jitter, lost response, or active disconnect.
Fault seedFixed random fault sequence to facilitate reproduction of the same test process.
Fixed LatencyAdds fixed processing delay per request.
Random jitteradds random wait on top of fixed latency.
Lost response probabilityNo response is sent by probability, used to verify client timeout and retry.
Disconnect after processing the number of requestsAfter reaching the specified number of requests, actively disconnect the client to verify automatic reconnection.

Import and Export

At the top, "Import JSON" allows you to import the full channel configuration; The "More" menu provides channels for exporting JSON, importing Excel, exporting Excel, and deleting channels.

FormatPurposeNotes
JSONBackup or copy of channels, protocols, security, diagnostics, faults, and variable configurations.Before importing, you can choose to create a new channel or override a stopped channel from the same protocol, and preview first.
Excelbatch maintenance variable point tables.Only handle variables; The channel must be stopped before the structural configuration is imported. Exporting the template first and then filling in can reduce formatting errors.

If other users have already modified the same channel during import, the page will prompt a configuration version conflict. Refresh and verify the latest configuration before re-importing; do not overwrite unknown changes directly.

Large-scale Simulation and Performance Recommendations

ScenariosRecommendations
Many variablesUse batch creation of variables or import them in Excel; Filter by name, address, type, and access mode, manage by page, without relying on displaying all variables at once.
High-frequency automatic changeEnable generators only for variables that require dynamic behavior, set update cycles reasonably, and avoid millisecond-level changes at all points.
Long-term protocol stress testingSet fixed event capacity; During the non-troubleshooting phase, the original packet, successful request, or high-frequency variable change record is closed.
Event queriesUse event types and keywords to narrow the scope and maintain pagination; The page only keeps the current page and does not accumulate all historical events in the browser.
Auto RefreshSelect a refresh cycle that matches the test rate. If the previous round is not yet completed, it will not be triggered concurrently to refresh again.
Multi-clientSet the total number, single IP limit, and request rate according to the planned number of connections, gradually increasing the load and observing request rates, errors, and memory summaries.

Frequently Asked Questions

PhenomenaHandling Suggestions
Client Cannot ConnectCheck if the channel is started, listen for addresses and ports, operating system firewall, allowed subnets, maximum number of clients, and port usage.
Modbus request returns an incorrect addressCheckstation number, message format, ribbon, offset, allocated quantity, and strict address mode.
S7 client handshake failurecheck ports, rack/slot numbers, local and remote TSAP, maximum PDU, allowed segments, and handshake timeouts.
S7 Address Read FailureCheck I/Q/M/DB address formats, whether the DB exists, DB capacity, and strict address mode.
Client write value is rejectedCheck the channel in sequence for "Allow external protocol writes," variable access mode, external write policy, and request address/data type.
The value changes again after writingThe external writing strategy is "accept and continue changing." When you need to keep the write value, switch to "Accept and pause the generator."
Random results cannot be reproducedFixed algorithm version, generator seed, noise seed, fault seed, and initial value at startup.
Too many page eventsReduce event capacity, close successful requests or variable change records, and use type/keyword filtering and pagination.
Unable to edit channels or variablesStop the channel first, then check whether the current role has the corresponding management permissions.