question

Patryk avatar image
0 Likes"
Patryk asked Ben Wilson answered

How to check device name

Is it possible to display or check the device name in FlexSim?

1670961475416.png

FlexSim 22.2.2
scriptusing codefunctions
1670961475416.png (5.8 KiB)
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image
0 Likes"
Ben Wilson answered

I've played a bit with code like the following:

  1. string cmd = programdatadir()+"gethostname.bat";
  2. string hostfile = programdatadir()+"hostname.txt";
  3. fileopen(cmd, "w");
  4. fpt("hostname > \""+hostfile+"\"");
  5. fileclose();
  6. runprogram(cmd);
  7. fileopen(hostfile, "r");
  8. string hostname = filereadline();
  9. fileclose();
  10. return hostname;

It isn't ideal. It works best if FlexSim is running with elevated privileges. If not, sometimes it takes running it twice to actually read the hostname from the written file.

It also flashes a black command prompt window, and sometimes makes FlexSim lose window focus.

If anything, it is a starting point to discover maybe a better way of doing it.

Joerg's C++ suggestion might be the best way. You could encapsulate the functionality you need in a DLL, then call it from FlexSim and get the value directly, rather than the above workaround writing and reading to files and launching a command prompt.

Good luck!

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.