Opto 22

From Chemical Engineering @ UP wiki
Revision as of 11:45, 25 October 2012 by 137.215.116.24 (Talk) (Opto Setup)

Jump to: navigation, search
Quick Links

Opto

OpTo is how we send/receive information from the rigs.

In the PM&C laboratory, all analog to digital conversion is handled by the OPTO22 units in the central box in the laboratory. The control units for each group of AD modules is known as a Brain, and is connected to the network so that all the computers on the local network (and maybe even the Internet in the future) are able to access the values of the readings and write outputs to the rigs.

Opto Setup

To start using the Opto, follow the following procedure:

1) Switch on transmitters. There are electrical plugs at the rigs that need to be switched on. Be careful not to switch on a pump by accident!

2) Switch on power supply units in the Opto JB.

3) Check LEDs on the Opto brain to see if there are any errors. LED meanings are described in SNAP Ethernet Brain Users Guide. If you do come up with an issue and manage to fix it please document it here.

4) Check that your SNAP modules are snaped into the system. Idealy they should be connected and configured but they are most probably not.

5) Check connectivity with the Brain by opening the command promt (Start->run->cmd) and pinging the brain (e.g. "ping OPTO2"). If you can't ping the brain, check that you are on the same subnet (see Finding your IP address) by verifyng that the first three bytes of the IP Address of lab computer you use to interact with the opto brains are the same as the Opto ones. Your brains IP addresses should be 137.215.116.xxx. If this doesn't work contact your Network Administrator (IT Help Service) on the extention numbers 3051 or 4845.

6) Configure the SNAP modules. Run Start->All Programs->Opto 22->SNAP Ethernet IO Configurator. see one of the existing configuration files as an example. I have found that the configuration fails in some cases if you don't configure all the attached SNAP modules, the workaround here is to pull out everyone else's SNAP modules. Ideally all the SNAPs should be connected and there should be one master configuration file for each Opto brain and then you are only responsible for setting up the scaling in the file. I cannot figure out how the scaling works, if you figure it out please document it here. I used default scaling and converted the mA signal to engineering units in my application.

Opto provides a C API to code your own Opto interface applications. Included with this is an example application (\\freki\C$:\Opto22\OptoENET-IO\DriverToolkit\Examples\C++\VC6\Eiocon\Release\eiocon.exe) that you can use to easily test communication with the brain and easily writing manual data to the rig. Run the application from the command prompt with the Opto brain's ip as an argument (Start->run->cmd)

cd C:\Opto22\OptoENET-IO\DriverToolkit\Examples\C++\VC6\Eiocon\Release
eiocon.exe 137.215.116.238

Type help to see a list of available commands. Consult this for information regarding the point numbers.

Matlab

A Simulink example shows how to access a rig through Matlab. Basically you need an opto22.m file in the appropriate Matlab directory refering to the point number on the opto. Before your PC will communicate through the LAN you need to run the opto22 service. Start by coping the .dll from here (right click and save as...) to c:\windows\system32. Then run cmd and start the service with

regsvr32 MatLabOpto

You will get a success message.

See the Matlab OPTO page for more detailed information.


Real Time vs Simulation Time

You also need the rtclock.dll and rtc.mdl files to keep everything synchronised. Make sure that you also have rtclock.c. If you have trouble with this procedure, follow any one of the three methods below to synchronize real time with simulation time.

Matlab has a separate product called "Real-Time Workshop" to synchronize real time with simulation time. The Real-Time Workshop can create stand-alone executable files which will run in real-time when under a Real-Time Operating System/embedded system. For more on this product, please see:

http://www.mathworks.com/products/rtw/. 

It is also possible to turn you own PC into a Real-Time Operating System, with the Real-Time Windows Target. For more information about this product, please have a look at the following URL:

http://www.mathworks.com/products/rtwt/.



If you are only interested in slowing your model down within Simulink to view results, please see the following:



There are three example folders in the attached zip file.

Example 1

An example of a MATLAB function which goes into a "busy wait" loop which kills time to slow down the simulation until the real-time clock catches up to the Simulink clock:

  • Open the folder example1

.
  • Run the model rtc.mdl.

Example 2

An example of a C-MEX S-function that compares simulation time with the system clock time to slow down the simulation speed:



  • Open the folder example2

.
  • Execute the command:

MEX sfun_time.c

 (In the MATLAB command-line).
  • Run the model rtc_C.

Example 3


A MEX-file which syncs a simulation to the PC internal clock or the UNIX system clock. This is an older example the was created for Simulink 1.3c:

  • Open the folder example 3.
  • Execute the command
:
CMEX rtclock.c (
in MATLAB 4.x) (In the MATLAB command-line).

MEX rtclock.c (
in MATLAB 5.x and above)
 (In the MATLAB command-line).
  • Run the M-File rtc.m to create a new model with a "Real-time clock" block created from the C-file above.



In all of these examples the sine function acts as "simulation". The other simulation can just be dragged into the system where you want to synchronize.

Please note that all of the above examples will allow the system will run approximately Real-Time, but not exactly. If you need the simulation to run in exact Real-Time, please look at the Real-Time Workshop along with a Real-Time Operating System.