element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog SCPI on a Linux Board - Part 4c: TCP/IP SCPI and Instrument Service - Run as a Daemon
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 15 Apr 2020 1:55 PM Date Created
  • Views 2680 views
  • Likes 4 likes
  • Comments 5 comments
Related
Recommended
  • piface_digital
  • raspberry_pi
  • labview
  • scpi
  • systemd
  • raspbian
  • diytestinstruch
  • piface

SCPI on a Linux Board - Part 4c: TCP/IP SCPI and Instrument Service - Run as a Daemon

Jan Cumps
Jan Cumps
15 Apr 2020

I'm building a SCPI electronics lab instrument for Linux.

In this post I'm creating a service wrapper and install the Linux service.

It will start at Pi startup, and can be stopped / started as you'd expect from a service.

image

 

Prerequisites

 

You should have built the two binaries for this project, as documented in post 4a and 4b. If you didn't, the binaries are available as archive attached to post 4b.

linux_scpi_socket

linux_piface_digital_service_cpp

These binaries should be placed in /home/pi/bin, and made executable (chmod +x <binary_name>).

If you're using a recent raspbian (I use buster lite) there are no other dependencies.

 

Start and Stop Shell Scripts

 

I've created a startup and a shutdown shell script in that same /home/pi/bin directory, and made them executable (again using chmod +x <shell_script_name>).

 

scpi_face_start.sh

 

#!/bin/bash
echo "start piface. Wait 5 seconds to complete ..."
/home/pi/bin/linux_piface_digital_service_cpp 2223 &
sleep 5
echo "start scpi."
/home/pi/bin/linux_scpi_socket 2222 2223 &
echo "start sequence completed"

 

scpi_face_stop.sh

 

#!/bin/bash
killall -9 "/home/pi/bin/linux_scpi_socket"
killall -9 "/home/pi/bin/linux_piface_digital_service_cpp"

 

These scripts take care that the right order is used to start and terminate both executables.

There's a 5 second sleep to allow the piface binary to start its socket listening thread.

 

Both scripts will be invoked by the service handler to start and stop the daemon.

 

Service Script

 

Now the core of this post: creating that Linux service that starts up at boot, and can be restarted by the user.

I've used the raspbian networking.service as inspiration, and this website for the instructions: https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/

 

Create a new service wrapper in /lib/systemd/system, called scpi_piface.service.

 

sudo nano /lib/systemd/system/scpi_piface.service

 

Then enter this content:

 

[Unit]
Description=PiFace SCPI Service
DefaultDependencies=no
Requires=ifupdown-pre.service
Wants=network.target
After=local-fs.target network-pre.target apparmor.service systemd-sysctl.service systemd-modules-load.service ifupdown-pre.service network.target
Before=shutdown.target
Conflicts=shutdown.target
[Install]
WantedBy=multi-user.target
WantedBy=network-online.target
[Service]
Type=oneshot
#EnvironmentFile=-/etc/default/networking
ExecStart=/home/pi/bin/scpi_face_start.sh
ExecStop=/home/pi/bin/scpi_face_stop.sh
RemainAfterExit=true
TimeoutStartSec=5min
#User=pi

 

I've chosen to wait for the full network stack being up.

You have to mod the file attributes:

 

sudo chmod  644 /lib/systemd/system/scpi_piface.service

 

Then, tell systemd that there's a new configuration and tell it to enable the service:

 

sudo systemctl daemon-reload
sudo systemctl enable scpi_piface.service

 

If you reboot, the raspberry will start with the PiFace SCPI Service running.

 

Check:

 

image

 

Managing the Service

 

You can use the usual systemd commands to verify, stop and start the daemon.

 

sudo systemctl status scpi_piface.service
sudo systemctl stop scpi_piface.service
sudo systemctl start scpi_piface.service
sudo systemctl restart scpi_piface.service

image

 

 

related blog
SCPI on a Linux Board - Letter of Intent

SCPI on a Linux Board - Part 1: Proof of Concept

SCPI on a Linux Board - Part 2a: PiFace Digital C programming

SCPI on a Linux Board - Part 2b: PiFace Digital C++ programming
SCPI on a Linux Board - Part 3: TCP/IP Socket C++ programming
SCPI on a Linux Board - Part 4: TCP/IP SCPI and Instrument Service
SCPI on a Linux Board - Part 4b: TCP/IP SCPI and Instrument Service 100% Working
SCPI on a Linux Board - Part 4c: TCP/IP SCPI and Instrument Service - Run as a Daemon
SCPI on a Linux Board - Part 5a: LabVIEW Driver for LAB Switch: Open, Close and Switch functions
  • Sign in to reply
  • vinc_bob
    vinc_bob over 2 years ago in reply to Jan Cumps

    Many thanks for the useful hints.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 2 years ago in reply to Jan Cumps

    edit: also, the complete sources and binaries are in blog 4b:  SCPI on a Linux Board - Part 4b: TCP/IP SCPI and Instrument Service 100% Working 

    For the SCPI service, I found the include files back, in the linux_scpi_socket\inc\scpi folder, 

    and the executables in linux_scpi_socket\Debug

    If I recall well, you should be able to import the 2 archives of post 4b as project in Eclipse.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 2 years ago in reply to vinc_bob

    I believe that they are in a zip file attached to the first blog in the series:  SCPI on a Linux Board - Part 1: Proof of Concept 

    linux_scpi_socket.zip

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vinc_bob
    vinc_bob over 2 years ago

    Hi Jan,

    I'm trying to get your scpi project run on a Rock4 SBC (laking an RPi currently) and I have some basic questions. I tried to find the binaries on the post you mention (4b) but can only retrieve the source files on the archive. Then trying to build it on the Rock4 (gcc) it seems that I am missing some files (e.g. scpi.h). Any help would be really appreciated. Many thanks in advance. V

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 5 years ago

    Wonderful ditty about creating a service under linux.  Thanks Jan Cumps for the write up.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube