In order to run software communicating with TwinCAT one needs actual runtime. If you can get a hold of actual PLC that’s great! In other cases you’ll need to setup it on your computer, in this post we’ll focus on setting in up on VM. VirtualBox to be precise.

Development environment

I think it’s safe to assume that today’s development machines consist mostly of x64 OS, thus our final setup will be:

  • x64 Windows host
  • x32 Windows VM
  • TwinCat 2

Note, that it’s not possible  to run TwinCAT 2 runtime on x64 host, we’ll need TwinCAT engineering for that. I assume you’re familiar with basic VirtualBox VM setup.

Downloading TwinCAT

Go to beckhoff download page and download TwinCAT 2.11 R3 and TwinCAT 2.11 x64 Engineering. After installation TwinCAT 2.11 R3 works for 30 days, but later on you can reinstall. For our purposes we’ll go with installation as Next-clicking until it’s finished. Remember TwinCAT 2.11 R3 is for VM and TwinCAT 2.11 x64 Engineering is for host.

Configuring network

For your VM select Host-only adapter.

Adding route

After installing TwinCAT and configuring network you should setup route between host and VM TwinCAT instalations. To do so:

  • click on TwinCAT tray icon
  • then “System Manager”
  • “Choose target”
  • “Search (Ethernet)…”
  • “Broadcast Search”
  • wait till search finishes, you should see 2 runtimes available, host and VM
  • Choose “IP Address” radio button for “Address info:”
  • click “Add route”
  • popup will appear, you should provide credentials for VM user with administrative privileges and confirm by clicking OK.
  • close “Add route dialog”
  • on a treeview select VM and click OK

After doing so you should be able to put VM TwinCAT in run mode, and upload program from TwinCAT PLC Control (TwinCAT tray icon –> “PLC Control”)

Adding route manually

if you’d want to add route manually, for whatever may your reason be:

  • click on TwinCAT tray icon and select properties
  • go to AMS Router tab
  • click Add
  • provide remote Machine name, Ams Net Id, and IP address  or click browse and search through your local network (note: that your probably won’t be able to read remote machine Ams Net Id via “Browse” due to 0x80070005 Access Denied exception)
  • repeat for both host and VM

Reading Ams Net Id of remote machine via Browse

In order to read remote machine AmsNetId, you’ll need to do some more configuration, at least that was my case, though you’ll probably won’t need read it anyway.

  1. make sure user accounts on VM and host have same login and password
  2. enable DCOM access rights (VM + host)
  3. enable WMI namespace access rights (VM + host)
  4. verify WMI service is running (VM + host)
  5. enable local security policy (VM + host)
DCOM access rights
  1. run dcomcnfg from Start –> Run
  2. enter “Component Services” –> “Computers”
  3. right click on “My Computer” and select “Properties”
  4. go to “Com Security” tab
  5. for both “Edit Limits” and “Edit Default” under “Access Permissions”
    1. click “Add”
    2. find user you’ll be connecting
    3. check “Local Address” and “Remote Address” boxes
    4. “Apply”
  6. click “OK”
WMI namespace access rights
  1. run wmimgmt.msc from Start –> Run
  2. right click “WMI Control” and select “Properties”
  3. go to “Security” tab
  4. click “Security” and then “Advanced”
  5. find user you’ll be connecting and lick “Edit”
  6. check “Execute Methods”, “Enable Account” and “Remote Enable”
  7. click “Apply” and then “OK”
verify WMI service is running
  1. run services.msc from Start –> Run
  2. scroll to “Windows Management Instrumentation”
  3. right click on it and verify if started and set to “Automatic”
enable local security policy
  1. run secpol.msc from Start –> Run
  2. select “Local Policies” –> “Security Options”
  3. scroll to “Network access: Sharing and security model for local accounts”
  4. right click and select “Properties”
  5. select “Classic – local users authenticate as themselves”
  6. confirm with “OK”
  7. restart

Running TwinCAT program

You can pickup sample program from #DSP project or write your own, whichever you choose, to run it:

  • Online –> Choose Run-Time System
  • Select available port from VM and click OK
  • Online –> Login (F11) to login with program
  • Online –> Run (F5) to run it