top of page

How to set up OPC Server on B&R Simulator?

 

When I was preparing my bachelor's thesis, I found in situation when I needed to check my control algorithm, but I didn't have an access to PLC. I hit on an idea that I could use B&R Simulator and tried to connected it to simulated plant in Matlab via OPC. In few words, I would like to show you how I did it - set up OPC Server on B&R Simulator using Automation Studio 3.8 and then to connect it with OPC Toolbox in Matlab.

 

 

WINDOWS SETUP

 

  1. Activate DCOM - read HowToActivateDCOM.pdf (look here).

 

B&R AUTOMATION STUDIO

 

  1. Open B&R Automation Studio, create new project

  2. Add global variables

  3. Add program that controls these variables

  4. Configuration of OPC:

  • 1. Open Physical View → click right mouse button on PLC1 (name of PLC) → Properties... → OPC → Build Windows OPC configuration MUST BE CHECKED!

  • Create .opct:

a. In LogicalView: Click RMB → Add Object → OPC → New OPC Tag Declaration → NewOpcTag.opct

b. Open it

c. Exapand by + Global.var and drag global variables directly to open window of NewOpcTag.opct

  • Create .opcm

a. In ConfigurationView: Click RMB on PLC1 → Add Object → OPC → New OPC Windows Server Mapping → NewWinOpcMap.opcm

b. Open it

c. Click on Logical view and drag NewOpcTag.opct to open window of NewWinOpcMap.opcm

d. In NewWinOpcMap.opcm view see Communication path:

I. In COM: COM1 select Tcpip

II. Should be: Tcpip: Tcpip

III. Write down as Destination IP Address: 127.0.0.1

  • Save everything (by Build) and Transfer project to PLC Simulator

  • Sometimes it is necessary to Stop → Start OPC Monitor and then you lose communication with ARSim, therefore just close the project and reopen it again.  (if this doesn't work check in Task Manager  if any ARxxx process still works, then kill then and  click Tools → ARSim)

 

 5. Next part of configuration:

  • Find in folder MyProject\ScadaProject\Temp\Objects\Simulation\PLC1 file with .opcs type e.g.: NewWinOpcMap.opcs and copy it into folder: C:\Program Files\BrAutomation\PVI\V3.00.02\Bin

  • In the same folder (C:\Program Files\BrAutomation\PVI\V3.00.02\Bin) find file file BR.OPC.Server.ini make a backup copy of this file and change these lines:

CfgFile0 = B R.OPC.Server_CoffeeMachine.opcs

to:

CfgFile0 = NewWinOpcMap.opcs

 6. Check whether everything is all right:

  • In folder C:\Program Files\BrAutomation\OpcMonitor click on BR.OPC.Monitor

  • In BR.OPC.Monitor click on the Server → Add

  • Check "local" and push Search

  • Select BR.OPC.Server_3.0_V1.14.9 and push Connect

  • Check in Item if there are your variables

 

MATLAB OPC TOOLBOX 

 

  1. Open Matlab and Simulink, create new Model

  2. From OPC Toolbox choose OPC Configuration and OPC Read

  3. Open OPC Config:

  • Click on COnfigure OPC Clients... 

  • Click Add...

  • As Host: should be localhost, then push Select...

  • There should appear new popup with BR.OPC.Server.xxx., click OK.

  • Enlarge Timeout to 100 seconds (sometimes it need a little bit more time)

  • Click Close (there should appear: localhost/BR.OPC.Server... [Timeout = 100, CONNECTED] (if not connceted try Connect...)

  • Click OK

 

 4. Save changes

 5. Click on OPC Read

  • As client select localhost/BR.OPC.Server.xxx

  • Click Add items...

  • There should appear your variables, select them by >> and click OK

  • Uncheck: Show quality and Show timestamps (not necessary)

  • Click Apply and OK

 6. Add to Simulink model essentials submodels (REMBER THAT OPC READ REQUIRES DEMUX!!!)

 7. Click Run

GOOD ADVICES

 

1. Every time that you change something with configuration of OPC variables (type, add new, remove, etc.) remember to copy .opcs file

to C:\Program Files\BrAutomation\PVI\V3.00.02\Binm- also close Simulink Model and reopen it (you should do that every time!).

 

COMMON PROBLEMS

 

If any problems occurs:

  1. Click Rebuild Configurartion and Transfer to PLC

  2. Check what OPC Monitor says!

  3. Check if everything with DCOM is OK.

  4. Sometimes open and reopen/restart helps:)

 

VNC PANEL

 

  1. Additionally, I did VNC Panel, use/develop it if you want:)

  2. To see it open VNC Viewer (shortcut on the desktop)

  3. Write in Menu:

  • VNC Server: 127.0.0.1

  • Encrytpion: Prefer Off

  • Click Continue...

  • Password: c (full control) v ( only view)

 4. Run Matlab\Simulink and check whether the values are changing when you change them in VNC Viewer

 

ALL HELPFUL FILES YOU CAN FIND HERE: LINK

bottom of page