All posts by mellis

MTConnect FANUC Adapter for Windows

In this tutorial we install the MTConnect FANUC Adapter in Windows and connect to a FANUC FS0iD control.  The source code is downloaded and compiled before some settings are made to establish a connection to the machine.

1.  Download the MTConnect Adapter source code from:

2.  Extract the source code to your PC

3.  Copy the appropriate  Fwlib32.h file from FANUC FOCAS cd into the /adapter/fanuc/ directory for the control we are connecting to.

4.  Copy all of the .dll and library files from the FANUC FOCAS cd into the /adapter/fanuc/ directory on your PC.

4.5  Copy the Fwlib32.dll file from the FOCAS cd to C:\Windows\System32\

5.  Open the /fanuc/fanuc.sln solution file in Microsoft Visual C++ 2010.

6.  Right click on the project and open the properties dialog from the context menu.

7.  Select Linker->Input from the left menu.

c++ properties dialog

8.  Change the Configuration drop down box to Release 0iD

9.  Remove the /fwlib/ from the additional dependencies so they properly point to the libraries.

10.  Close the properties dialog.

11.  Change the build drop down to Release 0iD

Visual c++ configuration

12.  Press F7 to build the solution.

13.  Copy /adapter/fanuc/adapter.cfg to /adapter/fanuc/Release0iD/adapter.cfg

14.  Open the adapter.cfg file with a text editor and change the IP Address to match the machine we are connecting to.

15.  From the command prompt, run the compiled binary with the option debug.

c:\adapter\fanuc\release0id\fanuc_0id debug

adapter dos run

16.  Test by having your agent connect to this adapter!  Once the adapter is tested it can be installed into windows by running:

c:\adapter\fanuc\release0id\fanuc_0id install

Good Luck!


Confirm FOCAS is installed

FOCAS is an optional function.  If it is installed, the setting screen will be available.  The screen is located under the system hard key; followed by the continuous menu soft key several times.


continuous menu softkey

Keep scrolling through the available softkeys until the [Embed Port] soft key is displayed.  All of the available ethernet interfaces will be shown.

ethernet softkeys

Of the three listed here, [Ether Board] is the best choice.   It is an add on hardware board for Ethernet communication.  Press the [Ether Board] soft key.  If the [FOCAS2] softkey is now displayed, FOCAS is installed !!!  Plug your Ethernet cable into the add on boards RJ45 plug.

focas2 softkey

If you didn’t find the [FOCAS2] softkey, then check to see if it exists under the [Embed Port] softkey.  If it does, then connect your Ethernet cable into the RJ45 plug directly on the mainboard of the FS0iD contol.   Setting FOCAS2 In order to set the FOCAS settings, we first need to be in MDI mode.  Parameter Write Enable (PWE) is then enabled under the <OFS/SET> hard key [SETTING] softkey.

set PWE

Once PWE is set the IP Address of the control is set by <SYSTEM>, [Ethe Board], [COMMON].  The IP address will be a fixed address assigned by the network administrator.

IPAddress Setting

Finally the TCP Port number is set under the [FOCAS2] settings.  This port is typically 8193, however, any valid TCP port number can be used.

TCPPort setting


If everything is set correctly the FANUC FS0iD CNC should be reachable from any computer on the same network.  In Microsoft Windows, start a new command prompt and ping the CNC.


You are now ready to use FANUC FOCAS to read and write information to the CNC.  Although the FOCAS drivers and libraries is a programming interface for C/C++ or Visual Basic, there are many available options that don’t require programming such as MTConnect and OPC converters to FOCAS.

Good Luck!

MTConnect Agent on Ubuntu Linux


Before MTConnect can be installed some prerequisites must be in place.  A clean install of Ubuntu 14.04 LTS will not have many of the packages required.  Install these packages using the apt-get command.

$ sudo apt-get install libxml2 libxml2-dev cmake git libcppunit-dev build-essential screen ruby

After all the required packages are in place, the MTConnect source code needs to be downloaded from GutHub.  The source code should compile without any modifcation using cmake and make.

$ cd ~
$ git clone
$ cd cppagent
$ cmake .
$ make

MTConnect Agent Installation

Now that binaries are compiled from the MTConnect source, they just need to be put into appropriate directories.   The agent binary and the configuration file are first.

$ sudo mkdir /etc/mtconnect
$ sudo cp ~/cppagent/agent/agent.cfg /etc/mtconnect/
$ sudo cp ~/cppagent/agent/agent /bin/agent

The source from GitHub contains a script to run MTConnect as a daemon.  I instead opted to write a BASH script that suited my needs a little better.  The script is available at the end of blog.  The blog downloads it from this server.  After it is downloaded it is given permission to execute and added to the startup scripts.

$ cd ~
$ wget
$ sudo mv ~/ /etc/init.d/agent
$ sudo chmod +x /etc/init.d/agent
$ sudo update-rc.d agent defaults

The script requires the user ‘mtconnect’.  So we need to add that user.  Pick a password that is appropriate for you.  For security reasons, you probably should pick a different username and change it in the script, however, this blog uses the default.

$ sudo adduser mtconnect

MTConnect Simulator Installation

The default configuration file that was downloaded with the source code defines a simulator.  For the MTConnect agent to start, it needs to connect to all devices listed in its configuration file.  So now we setup the simulator device.

$ sudo mkdir /etc/mtconnect/simulator
$ sudo rsync -avr ~/cppagent/simulator/ /etc/mtconnect/simulator/

The default configuration file expects the simulator adapter to be one directory above where we placed it.  To correct this, edit the agent.cfg file and point to the correct path for the simulator.

$ sudo nano /etc/mtconnect/agent.cfg

Original Path::  “Devices = ../simulator/VMC-3Axis.xml”

New Path:: “Devices = ./simulator/VMC-3Axis.xml”

Finally, the simulator is started up in a fresh screen.  The simulator blocks the process so just detach the screen using control A, D, after it is up and running.

$ screen -S simulator
$ cd /etc/mtconnect/simulator
$ ruby -v run_scenario.rb -l VMC-3Axis-Log.txt

<cntrl><a> followed by <d>


Testing the MTConnect agent is very simple.  First the agent is started using the script we created, if the script completes successfully we can make sure it is listening for incoming connections.

$ sudo service agent start
$ netstat - tcp -l

Active Internet connections (only servers)
tcp 0 0 *:7878 *:* LISTEN
tcp 0 0 *:5000 *:* LISTEN

With the default configuration the agent is listening on port 5000 and the simulator is listening on port 7878.  If these are listed in the netstat, then everything is good.   For the final confirmation, any browser can be used as client. or



Please let me know any mistakes, omissions or improvements in the code.  It took a great deal of patience to get this up and running, so feel free to ask any questions in the comments.


###### #######

 # /etc/init.d/agent
 # version 0.0.1 2014-05-09 (YYYY-MM-DD)
 # Provides: agent
 # Required-Start: $local_fs $remote_fs
 # Required-Stop: $local_fs $remote_fs
 # Should-Start: $network
 # Should-Stop: $network
 # Default-Start: 2 3 4 5
 # Default-Stop: 0 1 6
 # Short-Description: MtConnect server
 # Description: Starts the MTConnect Agent server

as_user() {
if [ "$USERNAME" != "$ME" ]; then
  su - $USERNAME -c "$1"
  bash -c "$1"

mc_start() {
if netstat - tcp -l | grep -q 5000
  echo "$SERVICE is already running!"
  echo "Starting $SERVICE..."
  as_user "cd $CONFIGPATH && screen -dmS agent $INVOCATION"
  sleep 10
  if netstat - tcp -l | grep -q 5000
    echo "$SERVICE is now running."
    echo "Error! Could not start $SERVICE!"

mc_stop() {
if netstat - tcp -l | grep -q 5000
  echo "Stopping $SERVICE"
  as_user "screen -p 0 -S agent -X stuff \"^C\""
  sleep 10
  echo "$SERVICE was not running."
if netstat - tcp -l | grep -q 5000
  echo "Error! $SERVICE could not be stopped."
  echo "$SERVICE is stopped."

#Start-Stop here
case "$1" in
if netstat - tcp -l | grep -q 5000
  echo "$SERVICE is running."
  echo "$SERVICE is not running."
echo "Usage: $0 {start|stop|status|restart}"
exit 1
exit 0


Installing WordPress in Ubuntu 14.04 LTS

Installing WordPress

Assuming your LAMP is up and running we start with downloading WordPress to the home directory.  It is unzipped, modified before being moved to our /www/html/ site.

$ cd ~$ wget
$ tar -xzvf latest.tar.gz

From the mysql shell we will create a structure WordPress can use.

$ mysql -u root –p
> CREATE DATABASE wordpress;> CREATE USER wordpress@localhost;

> SET PASSWORD FOR wordpress@localhost= PASSWORD(“password”);

> GRANT ALL PRIVILEGES ONwordpress.* TOwordpress@localhost IDENTIFIED BY 'password';


> exit;

Now that the MySQL database is ready for the WordPress installer, a few items need to be set so WordPress knows how to reach the database.  This is done in the wp-config.php file.  Make sure to set the username, password, database and security salts.

$ cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php 
$ sudo nano ~/wordpress/wp-config.php

Lets copy all the WordPress files so they are served by Apache.

$ sudo rsync –avP ~/wordpress /var/www/html/
$ cd /var/www/html$ sudo chown www-data:www-data * -R 
$ sudo usermod -a -G www-datausername

Finally, open your browser and setup WordPress!



How To Install WordPress on Debian 7



Setting up an Ubuntu 14.04 LTS Server

This blog is a reference for my current Ubuntu 14.04 setup.  I struggled to find correct information on-line especially with mysql setup.  This ensures its available in the future.  Digital Ocean servered as a great resource for the setup.


Setup a User

Add a user account for yourself. This is easy with the adduser command. Just follow the prompts to update set a password and any other information.

# adduser someuser

Since this is your account, you need to give all sudo privileges to the new account. Open up the list of sudoers with the visudo command and add your username below root with all privileges.

# visudo
   # User privilege specification
   root  ALL=(ALL:ALL) ALL
   someuser ALL=(ALL:ALL) ALL

Final switch from the root user to the sudo account you’ve created.

# su someuser


Updating packages

Several packages will be out of date and need to be updated. This is done with two commands. The update command retrieves a list of all packages and dependencies for updating purposes. Finally the

$ sudo apt-get update
$ sudo apt-get dist-upgrade


Add a Swapfile

How about adding a swapfile to decrease any chance of a memory overflow error. Use the fallocate command. The 2G is the size, 2 gigabytes. Finally check its OK using ls to confirm the size is 2GB.

$ sudo fallocate –l 2G /swapfile
$ ls –lh /swapfile

Enable the swapfile

$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile

The swapfile is now up and running, however, to have it permanently on the fstab file has to be edited. The swapfile is put at the bottom of the file.

$ sudo nano /etc/fstab
     /swapfile   none   swap   defaults   0   0


Install Apache Web Server

Next up the webserver apache2 is installed. After the server is installed the ServerName will need to be set to eliminate the “Could not reliably determine the server’s fully qualified domain name” nag. Finally restart apache2 to confirm the setting is correct.

$ sudo apt-get install apache2
$ sudo nano /etc/apache2/apache2.conf
      # Default ServerName
$ sudo service apache2 restart


Install MYSQL Server

Time to setup MYSQL. Install the package and then secure it by running my_sql_install_db

$ sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql php5-gd
$ sudo mysql_install_db


Install PHP5 for Apache

Finally we need PHP in our LAMP. Once the packages are downloaded and installed, the extension .php has to be moved up the default order of extensions apache will search for when an extension is omitted. This is done by editing the dir.conf file.

$ sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
$ sudo nano /etc/apache2/mods-enabled/dir.conf
$ sudo service apache2 restart

How To Install Linux, Apache, MySQL, PHP (LAMP)stack on Ubuntu

How To Add Swap on Ubuntu 14.04