While BRIDGE_READ and BRIDGE_WRITE are limited to handling simple data variables, BRIDGE_CALL allows GPSS-Plus to execute remote methods or functions defined in the middleware or industrial devices.
This capability is essential for tasks that go beyond pure simulation, such as:
- Accessing external databases or the server's File System (FS).
- Making HTTP requests to third-party APIs (checking weather, prices, real-time stock).
- Executing complex algorithms or heavy mathematical operations outside the simulation engine.
Asynchronous Synchronization (Rest/Wake Pattern)
Since these calls occur over the network, the response is not instantaneous. To prevent an entity from proceeding before receiving the result, the Rest/Wake pattern is used:
- The entity triggers
BRIDGE_CALL. - Immediately after, it enters a wait state using
rest esperaCall. - When the
triggerprocedure receives the server's response, it identifies the entity viaP$(PARAM_B)and releases it withwake.
This mechanism allows for realistic modeling of network latencies and asynchronous processing in industrial systems.
Example
SYSTEM {TYPE:OPTIONS, REAL_TIME:1}
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
initial txt_error," "
Graphic {Type:TEXT,Name:Text1,X:295,Y:123}
Graphic {Type:TEXT,Name:Text2,X:295,Y:95}
Graphic {Type:TEXT,Name:Text3,X:295,Y:66}
Graphic {Type:TEXT,Name:Text4,X:295,Y:35}
Graphic {Type:TEXT,Name:TextError,X:192,Y:478,Text:"On error...."}
RestRoom {name:esperaCall,x:543,y:488}
Initial options,{user:"user", pass:"1234"}
BRIDGER {NAME:bridge1,X:542,Y:434
,SERVER:"wss://your-domain.com:3000"
,CLIENT:"opc.tcp://your-domain.com:4840"
,OPTIONS:V$options
,on_error:bridge1_on_error
}
POSITION {NAME:POS1,X:183,Y:300}
POSITION {NAME:POS2,X:422,Y:300}
POSITION {NAME:POS3,X:704,Y:300}
START 10
PROCEDURE PRE_RUN
; Subscriptions to monitor network or system errors
BRIDGE_SUBSCRIPTION { NAME: bridge1, VARIABLE: "HTTP_Request_Error", TRIGGER: bridge1_on_error }
BRIDGE_SUBSCRIPTION { NAME: bridge1, VARIABLE: "Topics_CurrentTime", TRIGGER: on_clock }
; Reading a file from the remote File System (FS)
ASSIGN params, [{}]
BRIDGE_CALL {name:bridge1, trigger:on_read_file, params:V$params, method:"Methods_FS_Read"}
; External API request via HTTP
ASSIGN params, [{ "method": "GET", "params": { "name": "Antonio" } }]
BRIDGE_CALL { name:bridge1, trigger:on_http, params:V$params, method:"Methods_HTTP_Request" }
TERMINATE_VE
ENDPROCEDURE 1
GENERATE 3,0,0,10 {NAME:GEN1,X:59,Y:300}
ADVANCE 3,0 {TO:POS1}
; Call a calculation method (Sum) on the server
ASSIGN params, [{ "Num1": (D$N), "Num2": (0) }]
BRIDGE_CALL {name:bridge1, trigger:on_call, params:V$params, method:"Methods_Do_Sum"}
; Asynchronous synchronization: the entity waits for the response
rest esperaCall
mod {subtitle:"Sum: P$(suma)"}
ADVANCE 4,4 {TO:POS2}
ASSIGN params, [{ "Num1": (D$N), "Num2": (D$N) }]
BRIDGE_CALL {name:bridge1, trigger:on_call, params:V$params, method:"Methods_Do_Sum"}
rest esperaCall
mod {subtitle:"Sum2: P$(suma)"}
ADVANCE 4,4 {TO:POS3}
ENDGENERATE 1
; --- Callback Procedures ---
procedure on_clock
move {name:Text2,TEXT:"Server Time: P$(PARAM_A.VALUE)"}
TERMINATE_VE
endprocedure
procedure on_read_file
move {name:Text3,TEXT:"File Content: P$(PARAM_A.VALUE)"}
TERMINATE_VE
endprocedure
procedure on_http
move {name:Text4,TEXT:"HTTP Response: P$(PARAM_A.VALUE.message)"}
TERMINATE_VE
endprocedure
procedure on_call
move {name:Text1,TEXT:"Remote Sum: P$(PARAM_A.sum) Entity: P$(PARAM_B)"}
assign suma,P$(PARAM_A.sum),P$(PARAM_B)
; Wake the specific entity that made the call
wake esperaCall,-1,P$(PARAM_B)
TERMINATE_VE
endprocedure
procedure bridge1_on_error
savevalue txt_error,"X$txt_error\nP$(PARAM_A.VALUE)"
move {name:TextError,TEXT:"X$txt_error"}
TERMINATE_VE
endprocedure