Test engineers and software developers always face a challenge to continue their job without having the instrument needed. This happen when the instrument has long lead time or the instrument is still under development phase.
For some proactive engineers, they will use similar instrument as temporary replacement. If there is no replacement model, then we have to use software approach to over come this. For example, we can use Factory pattern with a temperory class to replace IO library class to fake the IO response. While some would prefer to wait for the real instrument as they feel it is double effor if they start coding immediately and then fix or debug the code when they have the actually instrument.
Here is another option: using Agilent VEE to create a virtual instrument. The main idea of this solution is to use the LAN Socket as the communication interface. VEE has a "To/From Socket" container which allow us to send and receive messages from the network port. This allow us to connect the software to a virtual instrument host in VEE.
There are some challenges in creating virtual instrument using VEE:
- Support loading multiple virtual instruments at the same time: This is because the port scanning will take some amount of time. If the scanning time is too long or too short, the instrument's response might be slow.
- Port scanning timing: We cannot set the port to listen without timeout. This will cause the VEE program to keep waiting for the port's message and hang. Also, as the Virtual Instrument program will support multiple virtual instrument, that means each port must be given time frame to listen.
- Supports dynamic response: This is to allow the virtual instrument to 'remember' the previous setting and also response based on certain logic. For example, if we would like to simulate a Power Supply's response. When user set "OUTP 1", the query "OUTP?" should return the correct value. Also, "Meas:VOLT?" should return 0V if the output is disabled.
Virtual Instrument 1.txt
[\*IDN\?]
"My virtual E3631A Power Supply"
[System_Init]
VIHash.Item("Var_Voltage") = 0;
VIHash.Item("Var_Current") = 0;VIHash.Item("Var_Enabled") = 0;
[VMax\?]
"1.23456767"
[volt ([-+]?[0-9]*\.?[0-9]*)]
VIHash.Item("Var_Voltage") = Groups.Item(1).Value;
[volt\?]
(asBoolean(VIHash.Item("Var_Enabled"))? VIHash.Item("Var_Voltage"):0);
[Outp (\w+)]
VIHash.Item("Var_Enabled") = (asBoolean(Groups.Item(1).Value)? 1:0);
[Outp\?]
VIHash.Item("Var_Enabled");
The supported SCPI commands are defined as a subsystem. The VEE program will scan the SCPI command by user with the commands provided in the txt file loaded. It will be using Regular Expression for pattern matching. When VEE finds the match subsystem, it will use the VEE formula container to evaluate the subsystem's content.
Picture below shows the main VEE program's blog diagram. The Log will be updated when a new port is added. It will also shows the message traffics for all the ports.
To connect to the instrument, the resource string format is "TCPIP0::localhost::
Picture below shows the virtual instrument responses like a real instrument in Agilent's Interactive IO. Note that the instrument has a dynamic response which is depends on user's settings.
In fact this project is not completed yet. It just shows the concept of the solution. There are things to be improved on:
- Tree View to allow user to create/define scpi node on the fly rather than a txt file.
- better SCPI parser: currently it only accept 1 scpi command at a time. It should be sufficient enough though.
- Error handling: This should be part of the SCPI parser also. For command that is not supported or with wrong format, it should generate an error message in error queue.
- Port Scanning timing: I didnt optimize on the port scan timing for this version. So you might notice sometimes the virtual instrument response is a bit slow.
- Currently it only support localhost. I didnt do much investigation whether we can connect to the virtual instrumetn from different computer.
You can download the project files here. Please do let me know if you upgrade it.
Related Topics:
0 comments:
Post a Comment