Linux Ubuntu PCI How To

Discussion in 'C-Gate Developers' started by gizi, Jan 19, 2015.

  1. gizi

    gizi

    Joined:
    Jan 19, 2015
    Messages:
    2
    Likes Received:
    0
    Location:
    Australia
    Hi All

    After much headache and grabbing bits of information from around the internet, and seeing no real up to date guide on getting this running along with multiple help requests with no definitive answer, here is my guide to using C-Gate under Ubuntu connected to a PCI via a physical serial port (i.e. not a USB to serial adapter).

    Ubuntu

    Fresh install of Ubuntu 14.04 Server AMD64 - in my case this is from the iso onto on a VMware ESXi 5.5.0 virtual machine (VM).

    Update/upgrade Ubuntu to latest

    Code:
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get dist-upgrade
    Set static IP address
    (reference: http://www.sudo-juice.com/how-to-set-a-static-ip-in-ubuntu-the-proper-way/)

    Edit network interfaces:
    Code:
    sudo vi /etc/network/interfaces
    I update the file to be as follows, subsituting your suitable IP addresses as needed to match you network configuration:
    Code:
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    auto eth0
    iface eth0 inet static
    address 192.168.1.230
    gateway 192.168.1.254
    netmask 255.255.255.0
    dns-nameservers 8.8.8.8 8.8.4.4
    Restart networking components:
    Code:
    sudo /etc/init.d/networking restart
    The above command actually failed to update the networking interface, so I rebooted the server with:
    Code:
    sudo shutdown -r now
    Setup SSH
    (reference: https://help.ubuntu.com/10.04/serverguide/openssh-server.html)

    Code:
    sudo apt-get install openssh-server
    From here on I use PUTTY to communicate with the server command line rather than a VM console.

    Install Java (Oracle JDK 8)
    https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get

    Add the repository to apt-get and update:
    Code:
    sudo apt-get install python-software-properties
    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    Install the JDK:
    Code:
    sudo apt-get install oracle-java8-jdk
    Install the RXTX CommAPI library for serial communication in Java:
    Code:
    sudo apt-get install librxtx-java
    Install C-Gate
    (reference: http://www.addictedtopi.com/post/96351714013/installing-c-gate-on-a-raspberry-pi)
    However I did not setup the SER2SOCK option detailed on the page.

    Install C-Gate:
    Visit http://www2.clipsal.com/cis/technical/downloads/c-gate and change the wget command to the address of the most recent C-Gate zip file if you wish to use the latest version

    Code:
    wget http://203.41.170.20/downloads/CGate/cgate-2.10.5_3140.zip
    sudo apt-get install unzip
    unzip cgate-2.10.5_3140.zip
    sudo mv cgate /usr/local/bin 
    Create a startup script for C-Gate:
    Note - here I made some small modifications to the script provided by Addicted to Pi (originally from these forums).
    Most importantly I moved the user the process runs under to a variable "USERID", I used the root user (which is possibly very unsecure - changing this to a more suitably priveliged user highly recommended!)
    Added code to specify the serial ports available "PORTLIST" to the JDK, in my case the PCI was connected to ttyS0 (COM1 in windows speak) - this permits the 'port list' command to work in C-Gate.

    Code:
    sudo vi /etc/init.d/cgate
    Code:
    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides:          cgate
    # Required-Start:    $remote_fs $syslog
    # Required-Stop:     $remote_fs $syslog
    # Should-Start:      $portmap
    # Should-Stop:       $portmap
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Example initscript
    # Description:       This file should be used to construct scripts to be
    #                    placed in /etc/init.d.
    ### END INIT INFO
    
    test -x /usr/local/bin/cgate/cgate.jar || exit 0
    CGATEDIR=/usr/local/bin/cgate
    CGATEJAR=$CGATEDIR/cgate.jar
    CGATEPID=$CGATEDIR/cgate.pid
    JAVARE=/usr/bin/java
    PORTLIST="/dev/ttyS0"
    PARAMS="-Xms32M -Xmx256M -DSERIAL_PORT_LIST=$PORTLIST -Djava.awt.headless=true -jar -noverify $CGATEJAR"
    LOCKFILE="$CGATEDIR/cgate.lock"
    USERID="root"
    
    case "$1" in
    start)
            echo -n "Starting C-Gate server:"
            cd $CGATEDIR
            start-stop-daemon --start \
                    --chuid $USERID \
                    --chdir $CGATEDIR \
                    --make-pidfile --pidfile $CGATEPID \
                    --exec $JAVARE \
                    -- $PARAMS &
            echo "."
            ;;
    stop)
            echo -n "Stopping C-Gate server:"
            start-stop-daemon --stop --quiet \
                    --pidfile $CGATEPID
            if [ -e $CGATEPID ]
                    then rm $CGATEPID
            fi
            echo "."
            ;;
    restart)
            echo -n "Restarting C-Gate server:"
            cd $CGATEDIR
            start-stop-daemon --stop --quiet \
                    --pidfile $CGATEPID
            start-stop-daemon --start \
                    --chuid $USERID \
                    --chdir $CGATEDIR \
                    --make-pidfile --pidfile $CGATEPID \
                    --exec $JAVARE \
                    -- $PARAMS &
            echo "."
            ;;
    *)
            echo "Usage: /etc/init.d/cgate (start|stop|restart)"
            exit 1
            ;;
    esac
    exit 0
    Change the permissions:
    Again here more suitable user and permissions highly recommended.

    Code:
    sudo chown -R root:root /usr/local/bin/cgate
    sudo chmod +x /usr/local/bin/cgate/cgate.jar
    sudo chmod 755 /etc/init.d/cgate
    sudo update-rc.d cgate defaults
    Setup C-Gate access permissions:
    Code:
    sudo vi /usr/local/bin/cgate/config/access.txt
    Add a line using the IP address of your windows computer which will run C-Bus Toolkit:
    In my case I allowed any IP on the network access (255 act as wildcard), here you really should limit this to a single IP - read the C-Gate documentation for further detail.
    remote 192.168.1.255 Program

    Move the libjspLux86_64bit.so into the JDK library path:
    Code:
    sudo cp /usr/local/bin/cgate/libjspLux86_64bit.so /usr/lib/jvm/java-8-oracle/jre/lib/amd64
    sudo chmod +x /usr/lib/jvm/java-8-oracle/jre/lib/amd64/libjspLux86_64bit.so
    Restart/start the C-Gate service:
    Code:
    sudo /etc/init.d/cgate restart
    This should now report that 'C-Gate is running'

    In my case now I needed to shutdown the VM, add the serial port to the VM config and restart the VM.
    Code:
    sudo shutdown now
    In fact a reboot may be required, or at least restarting the Java JDK process to pickup the new libjspLux86_64bit library.


    Connect C-Bus Toolkit to C-Gate

    Keeping a console open to Ubuntu may help with diagnosing any C-Gate errors.

    Launch C-Bus Toolkit
    File->Disconnect C-Gate - to disconnect from the local C-Gate instance
    File->Connect to Remote C-Gate
    Enter a suitable site name and IP address (192.168.1.230 in my case)
    Find C-Bus Networks
    Select Scan COM Ports
    Select /dev/ttyS0 (or other device as set in /etc/init.d/cgate PORTLIST variable)
    Use as Default Interface


    From there you should have a working C-Gate server on an Ubuntu box, I was able to find my project and scan the units etc.

    You may wish to change the configuration files (/usr/local/bin/cgate/config) and copy over your own previous project XML files (/usr/local/bin/cgate/tag).

    You should edit the XML file locate the <interfaceaddress>COMX</interfaceaddress> parameter and modify it to the correct address such as /dev/ttyS0.

    Cheers
    Gizi
     
    Last edited by a moderator: Jan 26, 2015
    gizi, Jan 19, 2015
    #1
    1. Advertisements

  2. gizi

    daniel C-Busser Moderator

    Joined:
    Jul 26, 2004
    Messages:
    761
    Likes Received:
    14
    Location:
    Adelaide
    Great guide! Just one thing. You likely don't need to modify cgate.ini at all.

    The file cgate.ini is only used by cgate.exe on Windows (which is the launcher + service wrapper). It looks like you are installing a System JRE to /usr/bin/java and launching the jar directly which is perfectly OK but in that case cgate.ini has no effect.

    Furthermore you may want to add to PARAMS the same Java heap parameters that cgate.exe passes, specifically "-Xms32M -Xmx256M" (where you see '256' this is the figure normally specified in C-Bus Toolkit under File | Preferences | Advanced | C-Gate Maximum Memory Usage). If you are trying to match a pre-existing Windows installation you can go to that machine and execute "get cgate JavaArguments" at the C-Gate command line and it will tell you the arguments that cgate.exe used.
     
    Last edited by a moderator: Jan 21, 2015
    daniel, Jan 21, 2015
    #2
    1. Advertisements

  3. gizi

    gizi

    Joined:
    Jan 19, 2015
    Messages:
    2
    Likes Received:
    0
    Location:
    Australia
    Thanks,

    Tested the changes and have updated the post to reflect those recommendations.

    Cheers
     
    gizi, Jan 26, 2015
    #3
  4. gizi

    IanCun

    Joined:
    Sep 6, 2012
    Messages:
    71
    Likes Received:
    0
    Location:
    UK
    Thanks for the helpful tutorial! I've now got C-Gate running on a remote Raspi :).

    Is there a way to get this working using the USB ports? I've tried to access /ttyUSB1 but I get an error saying that Java can't find the jspLuxArm library. It seems that cgate comes with x86 and x64, but nothing for Arm. Is there a way around this?

    edit: Got it running using this: http://www.addictedtopi.com/post/96351714013/installing-c-gate-on-a-raspberry-pi
     
    Last edited by a moderator: Mar 1, 2015
    IanCun, Mar 1, 2015
    #4
  5. gizi

    Harto

    Joined:
    Mar 21, 2015
    Messages:
    1
    Likes Received:
    0
    Location:
    Melbourne, Australia
    Thanks for the posts all,

    quick question - does anyone think there should be any issues with the Pi/CGate connecting to the CBus network via a 5500CN Network Interface?

    i.e. not via a direct serial or USB connection?

    I've setup the Pi and can connect to C-Gate via toolkit on my windows PC but dont have a CBus install here to test. Will go to a friends to test in the next few days (who has a 5500CN) but just wanted to know if anyone was aware of any other setup steps that may be needed?

    Thanks,
    Damian
     
    Harto, Mar 21, 2015
    #5
  6. gizi

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    83
    Likes Received:
    0
    Location:
    Sydney, Australia
    that was how I had my setup - sold house so its all packed up for the new place.

    mine was slightly complicated, had a WiPi for the network connection (to my LAN) and was using the Ethernet adaptor of the Pi connected directly to the 5500CN. but if you have all the devices connected via Ethernet, youll have no problems. In your project you need to specify the IP of the 5500CN for C-Gate to know to connect there.
     
    zei20t, Mar 27, 2015
    #6
  7. gizi

    daniel C-Busser Moderator

    Joined:
    Jul 26, 2004
    Messages:
    761
    Likes Received:
    14
    Location:
    Adelaide
    Hi Damian, it is actually easier to talk to a CNI because this works on any platform. It's the USB/serial library for a PCI connection that needs special attention when running C-Gate on other platforms.
     
    daniel, Apr 2, 2015
    #7
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.