|
1 | 1 | # Open ModSim |
2 | 2 | Open ModSim is a free implimentation of modbus slave (server) utility for modbus-tcp and modbus-rtu protocols. |
3 | 3 |
|
4 | | - |
| 4 | + |
| 5 | + |
| 6 | + |
5 | 7 |
|
6 | | - |
7 | 8 |
|
8 | 9 |
|
9 | 10 | ## Features |
@@ -37,6 +38,55 @@ Registers |
37 | 38 | Random - simulate register randomly |
38 | 39 | Increment - simulate register from Low Limit to High Limit with a given Step |
39 | 40 | Decrement - simulate register from High Limit to Low Limit with a given Step |
| 41 | + |
| 42 | +## Scripting |
| 43 | + From version 1.2.0 Open ModSim supports scripting. Qt runtime implements the [ECMAScript Language Specification](http://www.ecma-international.org/publications/standards/Ecma-262.htm) standard, so Javascript is used to write code. |
| 44 | + |
| 45 | +  |
| 46 | + |
| 47 | + Scripts can be launched in two modes: Once or Periodically. If you run script in Once mode the script will stop after it finishes executing. In Periodically mode, the script will start after a certain period of time until the user stops it or the method is called |
| 48 | + ```javascript |
| 49 | + Script.stop(); |
| 50 | + ``` |
| 51 | +Here is an example of using the script in the Periodically mode |
| 52 | +```javascript |
| 53 | +/**************************************************************************/ |
| 54 | +/* |
| 55 | +/* Example script that store value after 3 seconds |
| 56 | +/* |
| 57 | +***************************************************************************/ |
| 58 | + |
| 59 | +function clear() |
| 60 | +{ |
| 61 | + /* Write to a Holding register at address 1 zero value */ |
| 62 | + Server.writeHolding(1, 0); |
| 63 | +} |
| 64 | + |
| 65 | +/* init function */ |
| 66 | +function init() |
| 67 | +{ |
| 68 | + clear(); |
| 69 | + |
| 70 | + /* Runs when Hodling register value at address 1 was changed */ |
| 71 | + Server.onChange(Register.Holding, 1, (value)=> |
| 72 | + { |
| 73 | + if(value === 1) |
| 74 | + { |
| 75 | + /* Runs after 3 seconds and increase Holding register value at address 10 |
| 76 | + * Then stop script execution |
| 77 | + */ |
| 78 | + Script.setTimeout(function() |
| 79 | + { |
| 80 | + Server.writeHolding(10, Server.readHolding(10) + 1); |
| 81 | + Script.stop(); |
| 82 | + }, 3000); |
| 83 | + } |
| 84 | + }); |
| 85 | +} |
| 86 | + |
| 87 | +/* Runs once when script started */ |
| 88 | +Script.onInit(init); |
| 89 | +``` |
40 | 90 |
|
41 | 91 | ## Building |
42 | 92 | Now building is available with Qt/qmake (version 5.15 and above) or Qt Creator. Supports both OS Microsoft Windows and Linux. |
|
0 commit comments