W&T connects
Interfaces for TCP/IP, Ethernet, RS-232, RS-485, USB, 20mA, glass and plastic fiber optic cable, http, SNMP, OPC, Modbus TCP, I/O digital, I/O analog, ISA, PCI

First steps for software developers:

Golang on Windows for ARM-Linux systems

The Golang gopher

This manual is intended to serve as an introduction to the development of individual communication and automation solutions based on ARM-Linux systems in Go.

This language developed by Google is fast and easy to learn, but in contrast to script languages it is also very powerful and high-performance. It comes with a cross-compiler for ARM-Linux systems and offers a very simple workflow for programming the pure.box, the versatile communication and automation server from Wiesemann & Theis.

After installing and configuring a work environment, this tutorial shows you how to work with the Gotool using the command line with the example of a simple Hello-World program for the pure.box.

Step 1: Install Go

Go is free software and can be downloaded from the project page. After installing, a few environment variables must be set and adjusted:

  • PATH
    The environment variable PATH must have the sub-directory bin added in the GO directory so that Go can be run system-wide.

    The environment variable GOROOT contains the path to the directory of the Go installation. This variable is only set if Go was installed in a different directory than the standard directory C:\Go under Windows.

    The environment variable GOPATH contains the path to the working director of the user. This directory will later contain the sub-directories src for sources, lib for pre-compiled libraries, and bin for executable files.

Setting the environment variables

Click in the Control Panel on System, then on Advanced system settings. Here you will find the button Environment variables.

MQTT basic settings on the Web-IO

In the upper area you will find the environment variables for the current user 1. In the lower area you will find the system-wide environment variables 2. Create the user variable GOPATH and assign it the path to your working directory. If necessary, create the variable GOROOT for the system variables. Now expand the system variable PATH by adding the directory bin in your GOROOT, for example C:\Go\bin.

Install Git

To install language extensions and packages from third parties without great effort, Go uses Git, the software developed by Linus Torvalds for distributed version management. This can be downloaded from www.git-scm.com.

Check installation

The go tool is the Swiss army knife for Go development. To check whether the installation was successful, you can use it now to display the Go environment.

Open the command prompt and enter the following command:

					go env

An overview of all environment variables relevant to Go is now output:

						C:\Users\Gopher\go>go env
						set GOARCH=amd64
						set GOBIN=
						set GOEXE=.exe
						set GOHOSTARCH=amd64
						set GOHOSTOS=windows
						set GOOS=windows
						set GOPATH=c:\users\Gopher\go\
						set GORACE=
						set GOROOT=C:\Go
						set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
						set CC=gcc
						set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Gopher\
						AppData\Local\Temp\go-build015282382=/tmp/go-build -gno-record-gcc-switches
						set CXX=g++
						set CGO_ENABLED=1

If an error message is displayed, the bin directory in GOROOT is probably not in the search path. Check the environment variable PATH using the command echo %PATH%. Then check whether GOPATH matches your working directory.

Step 2: Hello, World

Go programs are developed within the GOPATH in the directory src. Create here the directory hello and in it the file hello.go.

						package main

						import "fmt"

						func main() {
							fmt.Println("Hello, world!")

  • Line 1:
    If you want to create an executable file in Go, work in the package main.

  • Line 3:
    The package fmt provides functions for in- and output.

  • Line 5:
    The function main() is the entry point to the program.

  • Line 6:
    fmt.PrintIn() outputs a string followed by a newline character.

To compile the program, enter the following command:

go install hello

If you have not received an error message, the translation was successful. The executable file hello.exe can now be found in the bin directory of its Go-Path.

					./hello Hello World!

Step 3: Hello pure.box - Cross-compilation for ARM-Linux

Go makes it very simple to compile applications for other target platforms. To translate the Hello World example for the pure.box, you must simply set a few temporary environment variables:

    The environment variable GOARCH sets the target architecture. For the pure.box this is arm.

  • GOOS
    This is the operating system of the target platform. For the pure.box this variable must be set to linux.

    GOARM tells the compiler how it should handle floating point operations. The value for the pure.box is 5.

Enter the following in the input prompt:

						set GOOS=linux
						set GOARCH=arm
						set GOARM=5

Start the cross-platform translation by changing to the source code directory and there running go build:

						go build

						Volume in Laufwerk C: hat keine Bezeichnung.
						Volumeseriennummer: DADE-DEDA

						Verzeichnis von C:\Users\gopher\go\src\hello

						05.04.2017  10:51    <DIR>    .
						05.04.2017  10:51    <DIR>    ..
						09.12.2016  12:54    78 hello.go
						05.04.2017  10:51    1.706.496 purebox

												2 Datei(en),      1.706.574 Bytes
												2 Verzeichnis(se), 61.440.692.224 Bytes frei

As you can see, the working directory not contains the executable file hello. Cross-compilation with Go is just this easy!

Step 4: Run on the pure.box

There are various ways to transfer the binary to the box: In addition to access via FTP, the box can be directly incorporated into your Windows network via SMB.

Since the simplest way to try out a change is to manually run it in a terminal session, SSH should be enabled on the box. This makes data transmission via SCP obvious.

If you have not yet installed an SSH client, download for example Putty. For SCP you need the following parameters: The user name is "admin", the password is the administratorpassword you set. As host name specify host name or the IP address of your pure.box.

Copy file:
pscp hello admin@hostname:/data/userfiles

Run program:

Connect to the pure.box with Putty or using the ssh-command.

						ssh admin@hostname

Then run the file hello in the directory /data/userfiles.

						Hello pure.box

Still have questions? Just call us!

Do you still have questions about this guide? Our support group will be glad to help you!