I recently wrote a Python script that used the FlexScript socket commands to control a model, and they worked really well. So you can use C++ with the DLL Maker or Module SDK if you want full control, but the FlexScript socket commands are quite effective for communicating between another language and FlexSim.
See the pdf in: how to use flexsim socket communication with server and client - FlexSim Community
Below are some snippets of my python code with socket communication that might help.
Most languages have functions for socket communication. You could use C# or something else if you wanted to.
I expect that trying to implement inter-process communication is not going to be more "convenient" for you to build UIs than using FlexSim's GUI Builder or Dashboard widgets, but you are welcome to try.
import os
import subprocess
import socket
class FlexSimConnection():
def __init__(self, flexsimPath, modelPath, address='localhost', port=5005, verbose=False, visible=False):
self.flexsimPath = flexsimPath
self.modelPath = modelPath
self.address = address
self.port = port
self.verbose = verbose
self.visible = visible
self._launch_flexsim()
def _launch_flexsim(self):
if self.verbose:
print("Launching " + self.flexsimPath + " " + self.modelPath)
args = [self.flexsimPath, self.modelPath]
if self.visible == False:
args.append("-maintenance")
args.append("nogui")
self.flexsimProcess = subprocess.Popen(args)
self._socket_init(self.address, self.port)
def _close_flexsim(self):
self.flexsimProcess.kill()
def _socket_init(self, host, port):
if self.verbose:
print("Waiting for FlexSim to connect to socket on " + self.address + ":" + str(self.port))
self.serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.serversocket.bind((host, port))
self.serversocket.listen();
(self.clientsocket, self.socketaddress) = self.serversocket.accept()
if self.verbose:
print("Socket connected")
if self.verbose:
print("Waiting for READY message")
message = self._socket_recv()
if self.verbose:
print(message.decode('utf-8'))
if message != b"READY":
raise RuntimeError("Did not receive READY! message")
def _socket_send(self, msg):
totalsent = 0
while totalsent < len(msg):
sent = self.clientsocket.send(msg[totalsent:])
if sent == 0:
raise RuntimeError("Socket connection broken")
totalsent = totalsent + sent
def _socket_recv(self):
chunks = []
while 1:
chunk = self.clientsocket.recv(2048)
if chunk == b'':
raise RuntimeError("Socket connection broken")
if chunk[-1] == ord('!'):
chunks.append(chunk[:-1])
break;
else:
chunks.append(chunk)
return b''.join(chunks)
def main():
con = FlexSimConnection(
flexsimPath = "C:/Program Files/FlexSim 2021 Update 2/program/flexsim.exe",
modelPath = "C:/Users/MyUser/Documents/FlexSim 2021 Projects/my_model.fsm",
verbose = True,
visible = True
)
if __name__ == "__main__":
main()
Phil BoBo
Sr. Manager, Software Development