Data-Hub Dawson Manual
Data-Hub Dawson Manual
User’s Manual
www.moxa.com/product
The software described in this manual is furnished under a license agreement and may be used only in accordance with
the terms of that agreement.
Copyright Notice
Trademarks
Disclaimer
Information in this document is subject to change without notice and does not represent a commitment on the part of
Moxa.
Moxa provides this document as is, without warranty of any kind, either expressed or implied, including, but not limited
to, its particular purpose. Moxa reserves the right to make improvements and/or changes to this manual, or to the
products and/or the programs described in this manual, at any time.
Information provided in this manual is intended to be accurate and reliable. However, Moxa assumes no responsibility for
its use, or for any infringements on the rights of third parties that may result from its use.
This product might include unintentional technical or typographical errors. Changes are periodically made to the
information herein to correct such errors, and these changes are incorporated into new editions of the publication.
www.moxa.com/support
Moxa Americas Moxa China (Shanghai office)
Toll-free: 1-888-669-2872 Toll-free: 800-820-5036
Tel: +1-714-528-6777 Tel: +86-21-5258-9955
Fax: +1-714-528-6778 Fax: +86-10-6872-3958
Moxa Europe Moxa Asia-Pacific
Tel: +49-89-3 70 03 99-0 Tel: +886-2-8919-1230
Fax: +49-89-3 70 03 99-99 Fax: +886-2-8919-1231
Table of Contents
The UC-8410/8416/8418/8430 embedded computer comes with 8 RS-232/422/485 serial ports, 3 Ethernet
ports, 4 digital input channels, 4 digital output channels, (12 digital input channels and 12 digital output
channels for UC-8418), 8 10/100 Mbps switch ports (UC-8416 only), a CompactFlash socket, and 2 USB 2.0
ports. In addition, the UC-8430 comes with 2 VGA outputs, making it the perfect solution for applications that
require HMI for field site monitoring.
The UC-8410/8416/8418/8430 computer uses the Intel XScale IXP435 533 MHz RISC CPU. This powerful
computing engine supports several useful communication functions, but will not generate too much heat. The
built-in 16 MB NORFlash ROM can be used to store the operating system, and 256 MB SDRAM gives you enough
memory to run your application software directly on the UC-8410/8416/8418/8430. Moreover, the 32 MB
NAND Flash provides the capacity for data storage.
The UC-8410/8416/8418/8430 computer supports RS-232/422/485 serial ports, digital I/O, and has three LAN
ports, making it ideal as a communication platform for industrial applications that require network redundancy.
Pre-installed with the Linux 2.6 platform, the UC-8410/8416/8418/8430 provides an open software operating
system for software program development. Software written for a desktop PC can be easily ported to the
UC-8410/8416/8418/8430 platform by using a GNU cross compiler, without needing to modify the code. This
makes the UC-8410/8416/8418/8430 an optimal solution for your industrial applications with the minimal cost
and effort.
In addition to the standard model, a wide temperature version (-40 to 75°C) of the UC-8410/8416/8418/8430
is also available for use in harsh industrial environments.
Overview
Software Architecture
Journaling Flash File System (JFFS2)
Software Features
UC-8410/8416/8418/8430 Introduction
Overview
The UC-8410/8416/8418/8430 computer, which features a RISC CPU, RAM memory, serial ports for
connecting RS-232/422/485 devices, and 3 10/100 Mbps Ethernet ports, is designed for embedded
applications.
The UC-8410/8416/8418/8430 uses an Intel XScale IXP435 533 Mhz RISC CPU. Unlike the x86 CPU, which
uses a CISC design, the RISC architecture and modern semiconductor technology provide this computer with
a powerful computing engine and communication functions, but without generating a lot of heat. The built-in 16
MB NOR Flash ROM can be used to store the operating system, and 256 MB of SDRAM gives you enough
memory to run your application software directly on the UC-8410/8416/8418/8430. Moreover, the 32 MB
NAND Flash provides the capacity for data storage. In addition, the network capability provided by the 3 LAN
ports built into the RISC CPU combined with the ability to control connected serial devices makes the
UC-8410/8416/8418/8430/8430 an ideal communication platform for data acquisition and industrial control
applications.
The UC-8410/8416/8418/8430’s pre-installed open source Linux operating system can run software written for
desktop PCs, provided the software is ported to the computer with a GNU cross compiler. The process is easy,
straightforward, and your programmer will not need to modify the source code. The OS, device drivers (e.g.,
Ethernet, SRAM, watchdog, and Buzzer control) and your own applications, can all be stored in the NOR Flash
memory.
Software Architecture
The Linux operating system that comes pre-installed on the UC-8410/8416/8418/8430/8430 follows the
standard Linux architecture, making it easy to run programs that follow the POSIX standard. Program porting
is done with the GNU Tool Chain provided by Moxa. In addition to Standard POSIX APIs, device drivers for the
buzzer, SRAM and watchdog controls, and UART are also included in the Linux OS.
The UC-8410/8416/8418/8430’s built-in Flash ROM is divided into Boot Loader, Linux Kernel, Root File
System, and User Root File System partitions.
In order to prevent user applications from crashing the Root File System, the UC-8410/8416/8418/8430/8430
uses a specially designed Root File System with Protected Configuration for emergency use. This Root
File System comes with serial and Ethernet communication capability for users to load the Factory Default
Image file. The user directory saves the user’s settings and application.
To improve system reliability, the UC-8410/8416/8418/8430/8430 has a built-in mechanism that prevents the
system from crashing. When the Linux kernel boots up, the kernel will mount the root file system for read only,
1-2
UC-8410/8416/8418/8430 Introduction
and then enable services and daemons. During this time, the kernel will start searching for system
configuration parameters via rc or inittab.
Normally, the kernel uses the Root File System to boot up the system. The Root File System is protected, and
cannot be changed by the user, providing a “safe” zone.
For more information about memory map and programming, refer to Chapter 5, “Programmer’s Guide.”
The Journaling Flash File System (JFFS2), which was developed by Axis Communications in Sweden, puts a file
system directly on the flash, instead of emulating a block device. It is designed for use on flash-ROM chips and
recognizes the special write requirements of a flash-ROM chip. JFFS2 implements wear-leveling to extend the
life of the flash disk, and stores the flash directory structure in the RAM. A log-structured file system is
maintained at all times. The system is always consistent, even if it encounters crashes or improper
power-downs, and does not require fsck (file system check) on boot-up.
JFFS2 is the newest version of JFFS. It provides improved wear-leveling and garbage-collection performance,
improved RAM footprint and response to system-memory pressure, improved concurrency and support for
suspending flash erases, marking of bad sectors with continued use of the remaining good sectors (which
enhances the write-life of the devices), native data compression inside the file system design, and support for
hard links.
Although JFFS2 is a journaling file system, this does not preclude the loss of data. The file system will remain
in a consistent state after power failures and will always be mountable. However, if the board is powered down
during a write then the incomplete write will be rolled back on the next boot, but writes that have already been
completed will not be affected.
Software Features
Linux
Kernel Version: 2.6.23
Protocol Stack: TCP, UDP, IPv4, SNMP V1, ICMP, ARP, HTTP, CHAP, PAP, SSH 1.0/2.0, SSL, DHCP, NTP, NFS,
Telnet, FTP, PPP, PPPoE, OpenVPN
File System: JFFS2, NFS, Ext2, Ext3
System Utilities: bash, busybox, tinylogin, telnet, ftp, ssh, scp
telnetd: telnet Server daemon
ftpd: FTP server daemon
sshd: secure shell server
Apache: web server daemon, supporting PHP and XML
1-3
UC-8410/8416/8418/8430 Introduction
1-4
2
2. Getting Started
In this chapter, we explain how to connect the UC-8410/8416/8418/8430, turn on the power, and then get
started with programming and using other functions.
Powering on the
Connecting the UC-8410/8416/8418/8430/8430 to a PC
Serial Console
Telnet Console
SSH Console
Configuring the Ethernet Interface
Modifying Network Settings with the Serial Console
Modifying Network Settings over the Network
Test Program─Developing Hello.c
Installing the Tool Chain (Linux)
Checking the Flash Memory Space
Compiling Hello.c
Uploading and Running the “Hello” Program
UC-8410/8416/8418/8430 Getting Started
ATTENTION
After connecting the UC-8410/8416/8418/8430/8430 to the power supply, it will take about 16 seconds for
the operating system to boot up. The green Ready LED will not turn on until the operating system is ready.
Connecting the
UC-8410/8416/8418/8430/8430 to a PC
There are two ways to connect the UC-8410/8416/8418/8430/8430 to a PC: directly through the serial console
port, or by Telnet over the network. For the UC-8430, you can connect the display with the display cable. Once
you turn on the power, you will be able to access the computer and conduct additional configurations.
Serial Console
The serial console port gives users a convenient way of connecting to the UC-8410/8416/8418/8430’s console
utility. This method is particularly useful when using the computer for the first time. The signal is transmitted
over a direct serial connection, so you do not need to know either of its 3 IP addresses in order to connect to
the UC-8410/8416/8418/8430.
Telnet Console
If you know at least one of the IP addresses and netmasks, you can use Telnet to connect to the
UC-8410/8416/8418/8430’s console utility. The default IP address and Netmask for each of the ports are given
below:
*Please note that the LAN1 of the UC-8430 uses DHCP for both IP Address and Netmask.
Use a cross-over Ethernet cable to connect directly from your PC to the UC-8410/8416/8418/8430. You should
first modify your PC’s IP address and netmask so that your PC is on the same subnet as one of the
UC-8410/8416/8418/8430’s LAN ports. For example, if you connect to LAN 1, you can set your PC’s IP address
to 192.168.3.126 and netmask to 255.255.255.0. If you connect to LAN 2, you can set your PC’s IP address to
192.168.4.126 and netmask to 255.255.255.0.
2-2
UC-8410/8416/8418/8430 Getting Started
To connect to a hub or switch connected to your local LAN, use a straight-through Ethernet cable. The default
IP addresses and netmasks are shown above. To log in, type the Login name and password as requested. The
default values are both root:
Login: root
Password: root
You can proceed with configuring network settings of the target computer when you reach the bash command
shell. Configuration instructions are given in the next section.
ATTENTION
Serial Console Reminder
Remember to choose VT100 as the terminal type. Use cable CBL-4PINDB9F-100, which comes with the
UC-8410/8416/8418/8430, to connect to the serial console port.
Telnet Reminder
When connecting to the UC-8410/8416/8418/8430/8430 over a LAN, you must configure your PC’s Ethernet
IP address to be on the same subnet as the UC-8410/8416/8418/8430/8430 you wish to connect to. If you do
not get connected on the first try, re-check the IP settings, and then unplug and re-plug the
UC-8410/8416/8418/8430’s power cord.
SSH Console
The UC-8410/8416/8418/8430/8430 supports an SSH console to provide users with better security options.
Windows Users
2-3
UC-8410/8416/8418/8430 Getting Started
Linux Users
From a Linux machine, use the “ssh” command to access the UC-8410/8416/8418/8430’s Console utility via
SSH.
#ssh 192.168.3.127
NOTE SSH provides better security compared to Telnet for accessing the UC-8410/8416/8418/8430’s console utility
over the network.
Follow the instructions given in a previous section to access the console utility of the target computer via the
serial console port, and then type #cd /etc/network to change directory.
root@Moxa:# cd /etc/network/
root@Moxa:/etc/network/#
Type #vi interfaces to edit the network configuration file with vi editor. You can configure the
UC-8410/8416/8418/8430’s Ethernet ports for static or dynamic (DHCP) IP addresses.
2-4
UC-8410/8416/8418/8430 Getting Started
Static IP addresses:
As shown below, 3 network addresses need to be modified: address, network, netmask, and broadcast.
The default IP addresses are 192.168.3.127 for LAN1, 192.168.4.127 for LAN2, and 192.168.5.127 for LAN3,
with default netmasks of 255.255.255.0.
Dynamic IP Addresses:
By default, the UC-8410/8416/8418/8430 is configured for “static” IP addresses. To configure LAN ports to
request an IP address dynamically, replace static with dhcp and then delete the address, network, netmask,
and broadcast lines.
After the boot settings of the LAN interface have been modified, issue the following command to activate the
LAN settings immediately:
#/etc/init.d/networking restart
ATTENTION
After changing the IP settings, use the networking restart command to activate the new IP address.
2-5
UC-8410/8416/8418/8430 Getting Started
For example, type the command #ifconfig eth0 192.168.1.1 to change the IP address of LAN1 to
192.168.1.1.
#mount /dev/cdrom
/mnt/cdrom#/mnt/cdrom/tool-chain/Linux/arm-linux_3.0_Build_YYMMDDHH.sh
The Tool Chain will be installed automatically on your Linux PC within a few minutes. Before compiling the
program, be sure to set the following path first, since the Tool Chain files, including the compiler, link, library,
and include files, are located in this directory.
PATH=/usr/local/arm-linux/bin:$PATH
PATH=/usr/local/arm-linux-4.4.2/bin:$PATH
Setting the path allows you to run the compiler from any directory.
2-6
UC-8410/8416/8418/8430 Getting Started
ATTENTION
If you have an older version of Linux Tool Chain on your Moxa embedded computer (such as the W300 Series,
IA240/241, and UC-7112-LX Plus) and would like to install the new Linux Tool Chain for the
UC-8410/8416/8418/8430, the old Linux Tool Chain files will be immediately overwritten, and the programs
compiled by this new Tool Chain may not work on your old models. We strongly suggest you rename the
directory of the old Linux Tool Chain before installing the new one if you would like to use the old Linux Tool
Chain for other embedded computers.
/>df –h
root@Moxa:/# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 13.4M 9.8M 3.5M 74% /
/dev/root 13.4M 9.8M 3.5M 74% /
/dev/ram15 1.7M 19.0k 1.6M 1% /dev
/dev/ram0 499.0k 18.0k 456.0k 4% /var
/dev/mtdblock4 32.0M 1.9M 30.1M 6% /tmp
/dev/mtdblock4 32.0M 1.9M 30.1M 6% /home
/dev/mtdblock4 32.0M 1.9M 30.1M 6% /etc
tmpfs 252.5M 0 252.5M 0% /dev/shm
/dev/sdb1 483.4M 57.9M 425.5M 12% /var/sdb
root@Moxa:/#
If there isn’t enough “Available” space for your application, you will need to delete some existing files. To do
this, connect your PC to the UC-8410/8416/8418/8430/8430 with the console cable, and then use the console
utility to delete the files from the UC-8410/8416/8418/8430’s flash memory.
Compiling Hello.c
The CD contains several sample programs. Here we use Hello.c to show you how to compile and run your
applications. Type the following commands from your PC to copy the files used for this example from the CD to
your computer’s hard drive:
# cd /tmp/
# mkdir example
# cp –r /mnt/cdrom/example/* /tmp/example
To compile the program, go to the hello subdirectory and issue the following commands:
#cd example/hello
#make
2-7
UC-8410/8416/8418/8430 Getting Started
Next, execute hello.exe to generate hello-release and hello-debug, which are described below:
hello-release—an IXP platform execution file (created specifically to run on the UC-8410/8416/8418/8430)
hello-debug—an IXP platform GDB debug server execution file (see Chapter 5 for details about the GDB
debug tool).
ATTENTION
Be sure to type the #make command from within the /tmp/example/hello directory, since the
UC-8410/8416/8418/8430’s tool chain puts a specially designed Makefile in that directory. This special
Makefile uses the xscale-linux-gcc compiler to compile the hello.c source code for the Xscale environment. If
you type the #make command from any other directory, Linux will use the x86 compiler (for example, cc or
gcc). Refer to Chapter 5 to see a Make file example.
#ftp 192.168.3.127
Use the bin command to set the transfer mode to binary mode, and then put command to initiate the file
transfer:
ftp> cd /home
ftp> bin
ftp> put hello-release
# chmod +x /home/hello-release
# ./home/hello-release
root@Moxa:~# ./home/hello-release
Hello
2-8
3
3. Managing Embedded Linux
This chapter includes information about version control, deployment, updates, and peripherals.
#kversion
192.168.3.127 – PuTTY
root@Moxa:~# kversion
UC-8410/8416/8418/8430 version 1.0
root@Moxa:~#
root@Moxa:/# kversion -a
UC-8410/8416/8418/8430 version 1.0 Build 08091716
root@Moxa:~#
Firmware Upgrade
ATTENTION
Upgrading the firmware will erase all data on the Flash ROM
If you are using the ramdisk to store code for your applications, beware that updating the firmware will erase
all of the data on the Flash ROM. You should back up your application files and data before updating the
firmware.
Since different Flash disks have different sizes, it’s a good idea to check the size of your Flash disk before
upgrading the firmware, or before using the disk to store your application and data files. Use the #df –h
command to list the size of each memory block, and how much free space is available in each block.
192.168.3.127 – PuTTY
root@Moxa:/# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 13.4M 9.8M 3.5M 74% /
/dev/root 13.4M 9.8M 3.5M 74% /
/dev/ram15 1.7M 19.0k 1.6M 1% /dev
/dev/ram0 499.0k 18.0k 456.0k 4% /var
/dev/mtdblock4 32.0M 1.9M 30.1M 6% /tmp
/dev/mtdblock4 32.0M 1.9M 30.1M 6% /home
/dev/mtdblock4 32.0M 1.9M 30.1M 6% /etc
tmpfs 252.5M 0 252.5M 0% /dev/shm
/dev/sdb1 483.4M 57.9M 425.5M 12% /var/sdb
root@Moxa:/# /dev/s
3-2
UC-8410/8416/8418/8430 Managing Embedded Linux
root@Moxa:/# upramdisk
root@Moxa:/# df -h
Filesystem Size Used Available Use% Mounted on
/dev/mtdblock2 14.0M 11.2M 2.8M 80% /
/dev/ram15 1.7M 18.0k 1.6M 1% /dev
/dev/ram0 499.0k 34.0k 440.0k 7% /var
/dev/mtdblock3 15.8M 2.6M 13.1M 17% /tmp
/dev/mtdblock3 15.8M 2.6M 13.1M 17% /home
/dev/mtdblock3 15.8M 2.6M 13.1M 17% /etc
/dev/ram1 38.7M 13.0k 36.7M 0% /mnt/ramdisk
root@Moxa:/# cd /mnt/ramdisk/
root@Moxa:/mnt/ramdisk#
The following instructions give the steps required to save the firmware file to the UC-8410/8416/8418/8430’s
RAM disk, and then upgrade the firmware.
2. Type the following commands to use the UC-8410/8416/8418/8430’s built-in FTP client to transfer the
firmware file (FWR_uc8400_Va.b.c_Build_YYMMDDHH.hfm ) from the PC to the
UC-8410/8416/8418/8430:
/mnt/ramdisk> ftp <destination PC’s IP>
Login Name: xxxx
Login Password: xxxx
ftp> bin
ftp> get FWR_uc8400_Va.b.c_Build_YYMMDDHH.hfm
192.168.3.127 – PuTTY
root@Moxa:/mnt/ramdisk# ftp 192.168.3.193
Connected to 192.168.3.193 (192.168.3.193).
220 TYPSoft FTP Server 1.10 ready…
Name (192.168.3.193:root): root
331 Password required for root.
Password:
230 User root logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd newsw
250 CWD command successful. “/C:/ftproot/newsw/” is current directory.
ftp> bin
200 Type set to I.
ftp> ls
200 Port command successful.
150 Opening data connection for directory list.
drw-rw-rw- 1 ftp ftp 0 Nov 30 10:03 .
drw-rw-rw- 1 ftp ftp 0 Nov 30 10:03 .
-rw-rw-rw- 1 ftp ftp 12904012 Nov 29 10:24
FWR_uc8400_Va.b.c_Build_YYMMDDHH.hfm
226 Transfer complete.
ftp> get FWR_uc8400_Va.b.c_Build_YYMMDDHH.hfm
local: FWR_uc8400_Va.b.c_Build_YYMMDDHH.hfm remote:
FWR_uc8400_Va.b.c_Build_YYMMDDHH.hfm
200 Port command successful.
3-3
UC-8410/8416/8418/8430 Managing Embedded Linux
3. Next, use the upgradehfm command to upgrade the kernel and root file system:
#upgradehfm FWR_uc8400_Va.b.c_Build_YYMMDDHH.hfm
192.168.3.127 – PuTTY
root@Moxa:/mnt/ramdisk# upgradehfm FWR_uc8400_Va.b.c_Build_YYMMDDHH.hfm
Moxa UC-8400 Upgrade firmware utility version 1.0.
To check source firmware file context.
The source firmware file conext is OK.
This step will upgrade firmware. All the data on flash will be destroyed.
Do you want to continue? (Y/N) :
Now upgrade the file [redboot].
Format MTD device [/dev/mtd0] ...
MTD device [/dev/mtd0] erase 128 Kibyte @ 60000 -- 100% complete.
Wait to write file ...
Completed 100%
Now upgrade the file [kernel].
Format MTD device [/dev/mtd1] ...
MTD device [/dev/mtd1] erase 128 Kibyte @ 1a0000 -- 100% complete.
Wait to write file ...
Completed 100%
Now upgrade the file [root-file-system].
Format MTD device [/dev/mtd2] ...
MTD device [/dev/mtd2] erase 128 Kibyte @ e00000 -- 100% complete.
Wait to write file ...
Completed 100%
Now upgrade the file [directory].
Format MTD device [/dev/mtd5] ...
MTD device [/dev/mtd5] erase 128 Kibyte @ 20000 -- 100% complete.
Wait to write file ...
Completed 100%
Now upgrade the new configuration file.
Upgrade the firmware is OK. Rebooting
3-4
UC-8410/8416/8418/8430 Managing Embedded Linux
ATTENTION
Reset-to-default will erase all data stored in /dev/mtdblock4
If you have stored data in the writable partition, you will need to back up these files before resetting the
system to default. On the UC-8410/8416/8418/8430, the directories /tmp, /etc, /usr/local/bin,
/usr/local/sbin, /usr/local/lib, /usr/local/libexec, and /home are mounted on /dev/mtdblock4. This means
that all of the data stored in these directories will be destroyed after resetting to default.
192.168.3.127 – PuTTY
root@Moxa:~# cd /etc
root@Moxa:/etc# ps
PID USER VSZ STAT COMMAND
1 root 1316 S init [3]
2 root 0 SW< [kthreadd]
3 root 0 SW< [ksoftirqd/0]
4 root 0 SW< [events/0]
5 root 0 SW< [khelper]
30 root 0 SW< [kblockd/0]
33 root 0 SW< [kseriod]
52 root 0 SW [pdflush]
53 root 0 SW [pdflush]
54 root 0 SW< [kswapd0]
55 root 0 SW< [aio/0]
613 root 0 SW< [mtdblockd]
652 root 0 SW< [ixp400_eth time]
655 root 0 SW< [ixp400_eth time]
657 root 0 DW< [EthMac Recovery]
667 root 0 SW< [rpciod/0]
728 root 0 SW< [khubd]
773 root 0 SW< [scsi_eh_0]
774 root 0 SW< [usb-storage]
788 root 0 SWN [jffs2_gcd_mtd4]
814 root 0 SW [ixp400 eth0]
820 root 0 SW [ixp400 eth1]
834 root 1360 S /bin/inetd
858 root 12536 S /usr/bin/httpd -k start -d /etc/apache
861 bin 1300 S /bin/portmap
867 root 2412 S /bin/sh --login
872 root 1360 S /bin/snmpd -c public
878 root 3508 S /bin/sshd -f /etc/ssh/sshd_config
3-5
UC-8410/8416/8418/8430 Managing Embedded Linux
192.168.3.127 – PuTTY
root@Moxa:~# cd /etc/rc.d
root@Moxa:/etc/rc.d# vi rc.local
3. Next, use vi editor to edit your application program. We use the sample program tcps2-release, and set
it to run in the background.
192.168.3.127 – PuTTY
# !/bin/sh
# Add you want to run daemon
/root/tcps2-release &
4. The following daemons will be enabled after you reboot the system.
192.168.3.127 – PuTTY
root@Moxa:~# ps –ef
PID USER VSZ STAT COMMAND
1 root 1316 S init [3]
2 root 0 SW< [kthreadd]
3 root 0 SW< [ksoftirqd/0]
4 root 0 SW< [events/0]
5 root 0 SW< [khelper]
30 root 0 SW< [kblockd/0]
33 root 0 SW< [kseriod]
52 root 0 SW [pdflush]
53 root 0 SW [pdflush]
54 root 0 SW< [kswapd0]
55 root 0 SW [aio/0]
613 root 0 SW [mtdblockd]
652 root 0 SW [ixp400_eth time]
655 root 0 SW [ixp400_eth time]
657 root 0 DW [Ethmac Recovery]
666 root 0 SW [rpciod/0]
727 root 0 SW< [khubd]
772 root 0 SW< [scsi_eh_0]
773 root 0 SW< [usb-storage]
788 root 0 SWN< [jffs2_gcd_mtd4]
809 root 0 SW [ixp400 eth0]
815 root 0 SW [ixp400 eth1]
3-6
UC-8410/8416/8418/8430 Managing Embedded Linux
root@Moxa:~#
192.168.3.127 – PuTTY
root@Moxa:/ect/rc.d/rc3.d# ls
S20snmpd S55ssh S99showreadyled
S25nfs-server S99rmnologin
root@Moxa:/etc/rc.d/rc3.d#
#cd /etc/rc.d/init.d
#cd /etc/rc.d/rc3.d
#ln –s /etc/rc.d/init.d/tcps2 S60tcps2
192.168.3.127 – PuTTY
root@Moxa:/ect/rc.d/rc3.d# ls
S20snmpd S55ssh S99showreadyled
S25nfs-server S99rmnologin
root@Moxa:/ect/rc.d/rc3.d# ln –s /root/tcps2-release S60tcps2
root@Moxa:/ect/rc.d/rc3.d# ls
S20snmpd S55ssh S99showreadyled
S25nfs-server S99rmnologin S60tcps2
root@Moxa:/etc/rc.d/rc3.d#
3-7
UC-8410/8416/8418/8430 Managing Embedded Linux
To remove the daemon, use the following command to remove the run file from /etc/rc.d/rc3.d:
#rm –f /etc/rc.d/rc3.d/S60tcps2
TZ variable
If you would like to use TZ variable, link to the following URL for all configurations and settings.
http://www.mkssoftware.com/docs/man5/timezone.5.asp
/etc/timezone
The local timezone is stored in /etc/localtime and is used by GNU Library for C (glibc) if the TZ environment
variable is not set. This file is either a copy of /usr/share/zoneinfo/ tree or a symbolic link to it.
The UC-8410/8416/8418/8430/8430 does not provide /usr/share/zoneinfo/ files, so you need to copy a time
zone information file to the UC-8410/8416/8418/8430/8430 and write over the original local time file.
1. The /usr/share/zoneinfo folder on a PC that is running standard Linux contains several time zone
information files.
2. Copy the time zone file that you want to use to the UC-8410/8416/8418/8430/8430 to overwrite the
original /etc/localtime file.
3. Type a date to check if the new time zone appears.
MM = Month
DD = Date
hhmm = hour and minute
YYYY = Year
The following figure illustrates how to update the system time and set the RTC time.
3-8
UC-8410/8416/8418/8430 Managing Embedded Linux
192.168.3.127 – PuTTY
root@Moxa:~# date
Fri Jun 23 23:30:31 CST 2000
root@Moxa:~# hwclock
Fri Jun 23 23:30:35 2000 -0.557748 seconds
root@Moxa:~# date 070910002006
Sun Jul 9 10:00:00 CST 2006
root@Moxa:~# hwclock –w
root@Moxa:~# date ; hwclock
Sun Jul 9 10:01:07 CST 2006
Sun Jul 9 10:01:08 2006 -0.933547 seconds
root@Moxa:~#
NTP Client
The UC-8410/8416/8418/8430/8430 has a built-in NTP (Network Time Protocol) client that is used to initialize
a time request to a remote NTP server. Use #ntpdate <NTP server> to update the system time.
#ntpdate time.stdtime.gov.tw
#hwclock –w
Visit http://www.ntp.org for more information about NTP and NTP server addresses.
10.120.53.100 – PuTTY
ATTENTION
Before using the NTP client utility, check your IP and DNS settings to make sure that an Internet connection
is available. Refer to Chapter 2 for instructions on how to configure the Ethernet interface, and see Chapter
4 for DNS setting information.
3-9
UC-8410/8416/8418/8430 Managing Embedded Linux
# /etc/resolv.conf file.
hwclock –w
sleep 100 # Updates every 100 seconds. The min. time is 100 seconds. Change 100
to a larger number to update RTC less often.
Save the shell script using any file name. E.g., fixtime
How to run the shell script automatically when the kernel boots up
Copy the example shell script fixtime to directory /etc/init.d, and then use
chmod 755 fixtime to change the shell script mode. Next, use vi editor to edit the file /etc/inittab. Add the
following line to the bottom of the file:
The Cron daemon will search /etc/cron.d/crontab for crontab files, which are named after accounts in
/etc/passwd.
Cron wakes up every minute, and checks each command to see if it should be run in the current minute.
Modify the file /etc/cron.d/crontab to set up your scheduled applications. Crontab files have the following
format:
The following steps show how to use cron to update the system time and RTC time every day at 8:00.
#!/bin/sh
ntpdate time.nist.gov
hwclock –w
exit 0
#/etc/init.d/cron start
3-10
UC-8410/8416/8418/8430 Managing Embedded Linux
Connecting Peripherals
ATTENTION
Remember to type the #sync command before you disconnect the USB mass storage device. If you don’t
issue the command, you may lose some data.
Remember to exit the mount directory when you disconnect the USB mass storage device. If you stay in
mount directory, the auto un-mount process will fail. If that happens, type #umount mount directory to
un-mount the USB device manually. For example, type #umount /mnt/sdc.
The UC-8410/8416/8418/8430/8430 only supports certain types of flash disk USB Mass Storage devices.
Some USB flash disks and hard disks may not be compatible with the UC-8410/8416/8418/8430. Check
compatibility issues before you purchase a USB device to connect to the UC-8410/8416/8418/8430.
CF Mass Storage
The UC-8410/8416/8418/8430/8430 Embedded Computer does not support CompactFlash hot swap and PnP
(Plug and Play) function. It is necessary to remove power source first before inserting or removing the
CompactFlash card.The UC-8410/8416/8418/8430/8430 CF card doesn’t support PNP. This means that user
need to mount the CF card manually after inserting the CF mass storage.
You can mount the CF card manually with the command below:
You should umount the CF mass storage before you remove the CF card.
3-11
4
4. Managing Communication
In this chapter, we explain how to configure the UC-8410/8416/8418/8430’s various communication functions.
Telnet/FTP
DNS
Web Service—Apache
IPTABLES
NAT
NAT Example
Enabling NAT at Bootup
Dial-up Service—PPP
PPPoE
NFS (Network File System) Client
Setting up the UC-8410/8416/8418/8430/8430 as an NFS Client
Mail
SNMP
OpenVPN
Package Management—ipkg
Audio Playing and Recording
Volume Control
Playing a WAVE File
Recording a WAVE file
UC-8410/8416/8418/8430 Managing Communication
Telnet/FTP
In addition to supporting Telnet client/server and FTP client/server, the UC-8410/8416/8418/8430/8430 also
supports SSH and sftp client/server. To enable or disable the Telnet/ftp server, you first need to edit the file
/etc/inetd.conf.
The following example shows the default content of the file /etc/inetd.conf. The default is to enable the
Telnet/ftp server:
Disable the daemon by typing ‘#’ in front of the first character of the row to comment out the line.
DNS
The UC-8410/8416/8418/8430/8430 supports DNS client (but not DNS server). To set up DNS client, you need
to edit three configuration files: /etc/hosts, /etc/resolv.conf, and /etc/nsswitch.conf.
/etc/hosts
This is the first file that the Linux system reads to resolve the host name and IP address.
/etc/resolv.conf
This is the most important file that you need to edit when using DNS for the other programs. For example,
before using #ntpdate time.nist.gov to update the system time, you will need to add the DNS server address
to the file. Ask your network administrator which DNS server address you should use. The DNS server’s IP
address is specified with the “nameserver” command. For example, add the following line to /etc/resolv.conf if
the DNS server’s IP address is 168.95.1.1:
nameserver 168.95.1.1
192.168.3.127 – PuTTY
/etc/nsswitch.conf
This file defines the sequence to resolve the IP address by using /etc/hosts file or /etc/resolv.conf.
4-2
UC-8410/8416/8418/8430 Managing Communication
Web Service—Apache
The Apache web server’s main configuration file is /etc/apache/conf/httpd.conf, with the default
homepage located at /home/httpd/htdocs/index.html. Save your own homepage to the following
directory:
/home/httpd/htdocs/
/home/httpd/cgi-bin/
Before you modify the homepage, use a browser (such as Microsoft Internet Explorer or Mozilla Firefox) from
your PC to test if the Apache Web Server is working. Type the LAN1 IP address in the browser’s address box to
open the homepage. E.g., if the default IP address is still active, type http://host-ip-address in address box.
To open the default CGI page, type http://host-ip-address/cgi-bin/xxx.cgi (xxx is your cgi page) in
your browser’s address box.
To open the default CGI test script report page, type http://host-ip-address/cgi-bin/test-cgi in your
browser’s address box.
4-3
UC-8410/8416/8418/8430 Managing Communication
ATTENTION
When you develop your own CGI application, make sure your CGI file is executable.
192.168.3.127 – PuTTY
root@Moxa:/usr/www/cgi-bin# ls –al
drwxr—xr-x 2 root root 0 Aug 24 1999
drwxr—xr-x 5 root root 0 Nov 5 16:16
-rwxr—xr-x 1 root root 268 Dec 19 2002 printenv
-rwxr—xr-x 1 root root 757 Aug 24 1999 test-cgi
root@Moxa:/usr/www/cgi-bin#
IPTABLES
IPTABLES is an administrative tool for setting up, maintaining, and inspecting the Linux kernel’s IP packet filter
rule tables. Several different tables are defined, with each table containing built-in chains and user-defined
chains.
Each chain is a list of rules that apply to a certain type of packet. Each rule specifies what to do with a matching
packet. A rule (such as a jump to a user-defined chain in the same table) is called a “target.”
The UC-8410/8416/8418/8430/8430 supports 3 types of IPTABLES table: Filter tables, NAT tables, and Mangle
tables:
4-4
UC-8410/8416/8418/8430 Managing Communication
Incoming
Packets
Mangle Table
PREROUTING Chain
NAT Table
PREROUTING Chain
Mangle Table
OUTPUT Chain
NAT Table
OUTPUT Chain
Filter Table
OUTPUT Chain
NAT Table
POSTROUTING Chain
Outgoing
Packets
4-5
UC-8410/8416/8418/8430 Managing Communication
The UC-8410/8416/8418/8430/8430 supports the following sub-modules. Be sure to use the module that
matches your application.
ipt_TOS
ipt_LOG ipt_ULOG ipt_owner
#lsmod
#modprobe ip_tables
#modprobe iptable_filter
Use lsmod to check if the ip_tables module has already been loaded in the UC-8410/8416/8418/8430. Use
modprobe to insert and enable the module.
Use the following command to load the modules (iptable_filter, iptable_mangle, iptable_nat):
#modprobe iptable_filter
NOTE IPTABLES plays the role of packet filtering or NAT. Take care when setting up the IPTABLES rules. If the rules
are not correct, remote hosts that connect via a LAN or PPP may be denied access. We recommend using the
serial console to set up the IPTABLES.
http://www.linuxguruz.com/iptables/
http://www.netfilter.org/documentation/HOWTO//packet-filtering-HOWTO.html
Since the IPTABLES command is very complex, to illustrate the IPTABLES syntax we have divided our
discussion of the various rules into three categories: Observe and erase chain rules, Define policy rules,
and Append or delete rules.
Usage:
4-6
UC-8410/8416/8418/8430 Managing Communication
-F: Flush the selected chain (all the chains in the table if none is listed).
-X: Delete the specified user-defined chain.
-Z: Set the packet and byte counters in all chains to zero.
Examples:
# iptables -L -n
In this example, since we do not use the -t parameter, the system uses the default ‘filter’ table. Three chains
are included: INPUT, OUTPUT, and FORWARD. INPUT chains are accepted automatically, and all connections
are accepted without being filtered.
#iptables –F
#iptables –X
#iptables -Z
Usage:
# iptables [-t tables] [-P] [INPUT, OUTPUT, FORWARD, PREROUTING, OUTPUT, POSTROUTING]
[ACCEPT, DROP]
-P: Set the policy for the chain to the given target.
INPUT: For packets coming into the UC-8410/8416/8418/8430.
OUTPUT: For locally-generated packets.
FORWARD: For packets routed out through the UC-8410/8416/8418/8430.
PREROUTING: To alter packets as soon as they come in.
POSTROUTING: To alter packets as they are about to be sent out.
Examples:
In this example, the policy accepts outgoing packets and denies incoming packets.
Usage:
# iptables [-t table] [-AI] [INPUT, OUTPUT, FORWARD] [-io interface] [-p tcp, udp,
icmp, all] [-s IP/network] [--sport ports] [-d IP/network] [--dport ports] –j [ACCEPT.
DROP]
-A: Append one or more rules to the end of the selected chain.
-I: Insert one or more rules in the selected chain as the given rule number.
-i: Name of an interface via which a packet is going to be received.
-o: Name of an interface via which a packet is going to be sent.
-p: The protocol of the rule or of the packet to check.
-s: Source address (network name, host name, network IP address, or plain IP
address).
--sport: Source port number.
-d: Destination address.
4-7
UC-8410/8416/8418/8430 Managing Communication
Examples:
Example 6: Accept TCP packets from 192.168.0.24 to LAN1 port 137, 138, 139
# iptables –A INPUT –i eth0 –p tcp –s 192.168.0.24 --dport 137:139 –j ACCEPT
Example 7: Log TCP packets that visit the LAN1 port 25.
# iptables –A INPUT –i eth0 –p tcp --dport 25 –j LOG
NOTE: In Example 8, remember to issue the command #modprobe ipt_mac first to load the module xt_mac
NAT
NAT (Network Address Translation) protocol translates IP addresses used on one network to different IP
addresses used on another network. One network is designated the inside network and the other is the outside
network. Typically, the UC-8410/8416/8418/8430/8430 connects several devices on a network and maps local
inside network addresses to one or more global outside IP addresses, and un-maps the global IP addresses on
incoming packets back into local IP addresses.
NOTE Click the following link for more information about iptables and NAT:
http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO.html
4-8
UC-8410/8416/8418/8430 Managing Communication
NAT Example
The IP address of LAN1 is changed to 192.168.3.127 (you will need to load the module ipt_MASQUERADE):
#!/bin/bash
# If you put this shell script in the /home/nat.sh
# Remember to chmod 744 /home/nat.sh
# Edit the rc.local file to make this shell startup automatically.
# vi /etc/rc.d/rc.local
# Add a line in the end of rc.local /home/nat.sh
EXIF=‘eth0’ #This is an external interface for setting up a valid IP address.
EXNET=‘192.168.4.0/24’ #This is an internal network address.
# Step 1. Insert modules.
# Here 2> /dev/null means the standard error messages will be dump to null device.
modprobe ip_tables 2> /dev/null
modprobe iptable_filter 2> /dev/null
modprobe iptable_nat 2> /dev/null
modprobe ip_conntrack 2> /dev/null
modprobe ip_conntrack_ftp 2> /dev/null
modprobe iptable_nat
modprobe ip_nat_ftp 2> /dev/null
# Step 2. Define variables, enable routing and erase default rules.
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
4-9
UC-8410/8416/8418/8430 Managing Communication
export PATH
echo “1” > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -Z
/sbin/iptables -F -t nat
/sbin/iptables -X -t nat
/sbin/iptables -Z -t nat
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables -t nat -P PREROUTING ACCEPT
/sbin/iptables -t nat -P POSTROUTING ACCEPT
/sbin/iptables -t nat -P OUTPUT ACCEPT
# Step 3. Enable IP masquerade.
Dial-up Service—PPP
PPP (Point to Point Protocol) is used to run IP (Internet Protocol) and other network protocols over a serial link.
PPP can be used for direct serial connections (using a null-modem cable) over a Telnet link, and links
established using a modem over a telephone line.
NOTE Click on the following links for more information about ppp:
http://tldp.org/HOWTO/PPP-HOWTO/index.html
http://axion.physics.ubc.ca/ppp-linux.html
The pppd daemon is used to connect to a PPP server from a Linux system. For detailed information about pppd
see the man page.
connection
The following command is used to connect to a PPP server by modem. Use this command for old ppp servers
that prompt for a login name (replace username with the correct name) and password (replace password with
the correct password). Note that debug and defaultroute 192.1.1.17 are optional.
If the PPP server does not prompt for the username and password, the command should be entered as follows.
Replace username with the correct username and replace password with the correct password.
4-10
UC-8410/8416/8418/8430 Managing Communication
-v
verbose mode; log what we do to syslog
“ “
Double quotes—don’t wait for a prompt, but instead do (note that you must include a space after the second
quotation mark)
ATDT5551212
Dial the modem, and then ...
CONNECT
Wait for an answer.
“ “
Send a return (null text followed by the usual return)
Refer to the chat man page, chat.8, for more information about the chat utility.
/dev/
Specify the callout serial port.
115200
The baudrate.
Debug
Log status in syslog.
Crtscts
Use hardware flow control between the computer and modem (at 115200 this is a must).
Modem
Indicates that this is a modem device; pppd will hang up the phone before and after making the call.
Defaultroute
Once the PPP link is established, make it the default route; if you have a PPP link to the Internet, this is probably
what you want.
192.1.1.17
This is a degenerate case of a general option of the form x.x.x.x:y.y.y.y. Here x.x.x.x is the local IP address and
y.y.y.y is the IP address of the remote end of the PPP connection. If this option is not specified, or if just one
side is specified, then x.x.x.x defaults to the IP address associated with the local machine’s hostname (located
in /etc/hosts), and y.y.y.y is determined by the remote machine.
If a username and password are not required, use the following command (note that noipdefault is optional):
If a username and password is required, use the following command (note that noipdefault is optional, and root
is both the username and password):
4-11
UC-8410/8416/8418/8430 Managing Communication
Once you’ve set up a PPP connection, there are some steps you can take to test the connection. First, type:
/sbin/ifconfig
(The folder ifconfig may be located elsewhere, depending on your distribution.) You should be able to see all
of the network interfaces that are UP. ppp0 should be one of them, and you should recognize the first IP
address as your own In addition, the “P-t-P address” (or point-to-point address) is the address of your server.
Here’s what it looks like on one machine:
Now, type:
ping z.z.z.z
where z.z.z.z is the address of your name server. This should work. Here’s what the response could look like:
Try typing:
netstat -nr
If your output looks similar, but does not have the destination 0.0.0.0 line (which refers to the default route
used for connections), you may have run pppd without the ‘defaultroute’ option. At this point you can try using
Telnet, ftp, or finger, bearing in mind that you will need to use numeric IP addresses unless you’ve set up
/etc/resolv.conf correctly.
4-12
UC-8410/8416/8418/8430 Managing Communication
This first example applies to using a modem, and requires authorization with a username and password.
You should also add the following line to the file /etc/ppp/pap-secrets:
* * ““ *
The first star (*) lets everyone login. The second star (*) lets every host connect. The pair of double quotation
marks (““) is to use the file /etc/passwd to check the password. The last star (*) is to let any IP connect.
The following example does not check the username and password:
PPPoE
1. Connect the UC-8410/8416/8418/8430’s LAN port to an ADSL modem with a cross-over cable, HUB, or
switch.
# PPPOE example, if you want to use it, you need to unmark it and modify it
“username@hinet.net” * “password” *
“username@hinet.net” is the username obtained from the ISP to log in to the ISP account.
“password” is the corresponding password for the account.
# OUTBOUND connections
# ATTENTION: The definitions here can allow users to login without a
# package already provides this option; make sure you don’t change that.
# INBOUND connections
# Every regular user can use PPP and has to use passwords from /etc/passwd
* hostname ““ *
“username@hinet.net” * “password” *
# PPPOE user example, if you want to use it, you need to unmark it and modify it
#”username@hinet.net” * “password” *
# UserIDs that cannot use PPP at all. Check your /etc/passwd and add any
4-13
UC-8410/8416/8418/8430 Managing Communication
“username@hinet.net” is the username obtained from the ISP to log in to the ISP account. “password”
is the corresponding password for the account.
# Wait for up n milliseconds after the connect script finishes for a valid
# PPP packet from the peer. At the end of this time, or when a valid PPP
# packet is received from the peer, pppd will commence negotiation by
# sending its first LCP packet. The default value is 1000 (1 second).
# This wait period only applies if the connect or pty option is used.
#connect-delay <n>
# ---<End of File>---
6. Add one of two files: /etc/ppp/options.eth0 or /etc/ppp/options.eth1. The choice depends on which
LAN is connected to the ADSL modem. If you use LAN1 to connect to the ADSL modem, then add
/etc/ppp/options.eth0. If you use LAN2 to connect to the ADSL modem, then add
/etc/ppp/options.eth1. The file context is shown below:
192.168.3.127 – PuTTY
name username@hinet.net
mtu 1492
mru 1492
defaultroute
noipdefault
Type your username (the one you set in the /etc/ppp/pap-secrets and /etc/ppp/chap-secrets files)
after the “name” option. You may add other options as desired.
7. Set up DNS.
If you are using DNS servers supplied by your ISP, edit the file
/etc/resolv.conf by adding the following lines of code:
nameserver ip_addr_of_first_dns_server
nameserver ip_addr_of_second_dns_server
For example:
nameserver 168.95.1.1
nameserver 139.175.10.20
4-14
UC-8410/8416/8418/8430 Managing Communication
The eth0 is what is connected to the ADSL modem LAN port. The example above uses LAN1. To use LAN2,
type:
pppd eth1
9. Type ifconfig ppp0 to check if the connection is OK or has failed. If the connection is OK, you will see
information about the ppp0 setting for the IP address. Use ping to test the IP.
10. If you want to disconnect it, use the kill command to kill the pppd process.
NOTE Click on the following links for more information about NFS:
http://www.tldp.org/HOWTO/NFS-HOWTO/index.html
http://nfs.sourceforge.net/nfs-howto/client.html
http://nfs.sourceforge.net/nfs-howto/server.html
Steps 1:
#mkdir –p /home/nfs/public
Step 2:
#mount –t nfs NFS_Server(IP):/directory /mount/point
Example
: #mount –t nfs 192.168.3.100/home/public /home/nfs/public
Mail
smtpclient is a minimal SMTP client that takes an email message body and passes it on to an SMTP server. It
is suitable for applications that use email to send alert messages or important logs to a specific user.
NOTE Click on the following link for more information about smtpclient:
http://www.engelschall.com/sw/smtpclient/
To send an email message, use the ‘smtpclient’ utility, which uses SMTP protocol. Type #smtpclient--help to
see the help message.
4-15
UC-8410/8416/8418/8430 Managing Communication
Example:
SNMP
The UC-8410/8416/8418/8430/8430 has the SNMP V1 (Simple Network Management Protocol) agent software
built in. It supports RFC1317 RS-232 like groups and RFC 1213 MIB-II.
The following simple example allows you to use an SNMP browser on the host site to query the
UC-8410/8416/8418/8430, which is the SNMP agent. The UC-8410/8416/8418/8430/8430 will respond.
SNMPv2-MIB::sysDescr.0 = STRING: Linux version 2.6.23.1 (root@UC8400) (gcc version 4.2.1) #1137 Wed
Sep 17 16:17:45 EDT 2008
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.8691.12.8410/8416/8418
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (239600) 0:39:56.00
SNMPv2-MIB::sysContact.0 = STRING: Moxa Systems Co., LDT.
SNMPv2-MIB::sysName.0 = STRING: (none)
SNMPv2-MIB::sysLocation.0 = STRING: Unknown
SNMPv2-MIB::sysServices.0 = INTEGER: 6
IF-MIB::ifNumber.0 = INTEGER: 11
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifIndex.3 = INTEGER: 3
IF-MIB::ifIndex.4 = INTEGER: 4
IF-MIB::ifIndex.5 = INTEGER: 5
IF-MIB::ifIndex.6 = INTEGER: 6
IF-MIB::ifIndex.7 = INTEGER: 7
IF-MIB::ifIndex.8 = INTEGER: 8
IF-MIB::ifIndex.9 = INTEGER: 9
IF-MIB::ifIndex.10 = INTEGER: 10
IF-MIB::ifIndex.11 = INTEGER: 11
IF-MIB::ifDescr.1 = STRING: eth0
IF-MIB::ifDescr.2 = STRING: eth1
IF-MIB::ifDescr.3 = STRING: eth2***** SNMP QUERY FINISHED *****
NOTE Click on the following links for more information about MIB II and RS-232 like groups:
http://www.faqs.org/rfcs/rfc1213.html
http://www.faqs.org/rfcs/rfc1317.html
4-16
UC-8410/8416/8418/8430 Managing Communication
OpenVPN
OpenVPN provides two types of tunnels for users to implement VPNS: Routed IP Tunnels and Bridged
Ethernet Tunnels. To begin with, check to make sure that the system has a virtual device /dev/net/tun. If
not, issue the following command:
An Ethernet bridge is used to connect different Ethernet networks together. The Ethernets are bundled into one
bigger, “logical” Ethernet. Each Ethernet corresponds to one physical interface (or port) that is connected to the
bridge.
On each OpenVPN machine, you should generate a working directory, such as /etc/openvpn, where script
files and key files reside. Once established, all operations will be performed in that directory.
Host A (B) represents one of the machines that belongs to OpenVPN A (B). The two remote subnets are
configured for a different range of IP addresses. When this setup is moved to a public network, the external
interfaces of the OpenVPN machines should be configured for static IPs, or connect to another device (such
as a firewall or DSL box) first.
# openvpn --genkey --secret secrouter.key
2. The openvpn-bridge script file located at “/etc/openvpn/” reconfigures the interface “eth1” as IP-less,
creates logical bridge(s) and TAP interfaces, loads modules, and enables IP forwarding.
#---------------------------------Start-----------------------------
#!/bin/sh
iface=eth1 # defines the internal interface
maxtap=`expr 1` # defines the number of tap devices. I.e., # of tunnels
IPADDR=
NETMASK=
BROADCAST=
# it is not a great idea but this system doesn’t support
# /etc/sysconfig/network-scripts/ifcfg-eth1
ifcfg_vpn()
4-17
UC-8410/8416/8418/8430 Managing Communication
{
while read f1 f2 f3 f4 r3
do
if [ “$f1” = “iface” -a “$f2” = “$iface” -a “$f3” = “inet” -a “$f4” =
“static” ];then
i=`expr 0`
while :
do
if [ $i -gt 5 ]; then
break
fi
i=`expr $i + 1`
read f1 f2
case “$f1” in
address ) IPADDR=$f2
;;
netmask ) NETMASK=$f2
;;
broadcast ) BROADCAST=$f2
;;
esac
done
break
fi
done < /etc/network/interfaces
}
# get the ip address of the specified interface
mname=
module_up()
{
oIFS=$IFS
IFS=‘
‘
FOUND=“no”
for LINE in `lsmod`
do
TOK=`echo $LINE | cut -d’ ‘ -f1`
if [ “$TOK” = “$mname” ]; then
FOUND=“yes”;
break;
fi
done
IFS=$oIFS
4-18
UC-8410/8416/8418/8430 Managing Communication
if [ ! \( -r “/dev/net/tun” \) ]; then
# create a device file if there is none
mknod /dev/net/tun c 10 200
fi
# load modules “tun” and “bridge”
mname=tun
module_up
mname=bridge
module_up
# create an ethernet bridge to connect tap devices, internal interface
brctl addbr br0
brctl addif br0 $iface
# the bridge receives data from any port and forwards it to other ports.
i=`expr 0`
while :
do
# generate a tap0 interface on tun
openvpn --mktun --dev tap${i}
# connect tap device to the bridge
brctl addif br0 tap${i}
i=`expr $i + 1`
if [ $i -ge $maxtap ]; then
break
fi
done
# enable bridge ip
ifconfig br0 $IPADDR netmask $NETMASK broadcast $BROADCAST
ipf=/proc/sys/net/ipv4/ip_forward
# enable IP forwarding
echo 1 > $ipf
echo “ip forwarding enabled to”
cat $ipf
}
stop() {
echo “shutdown openvpn bridge.”
ifcfg_vpn
i=`expr 0`
while :
do
# disconnect tap device from the bridge
brctl delif br0 tap${i}
openvpn --rmtun --dev tap${i}
i=`expr $i + 1`
if [ $i -ge $maxtap ]; then
4-19
UC-8410/8416/8418/8430 Managing Communication
break
fi
done
brctl delif br0 $iface
brctl delbr br0
ifconfig br0 down
ifconfig $iface $IPADDR netmask $NETMASK broadcast $BROADCAST
killall -TERM openvpn
}
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo “Usage: $0 [start|stop|restart]”
exit 1
esac
exit 0
#---------------------------------- end -----------------------------
# /etc/openvpn/tap0-br.conf
# point to the peer
remote 192.168.8.174
dev tap0
secret /etc/openvpn/secrouter.key
cipher DES-EDE3-CBC
auth MD5
tun-mtu 1500
tun-mtu-extra 64
ping 40
up /etc/openvpn/tap0-br.sh
Next, modify the routing table in the /etc/openvpn/tap0-br.sh script file.
#----------------------------------Start------------------------------
#!/bin/sh
# /etc/openvpn/tap0-br.sh
# value after “-net” is the subnet behind the remote peer
route add -net 192.168.4.0 netmask 255.255.255.0 dev br0
#---------------------------------- end ------------------------------
On machine OpenVPN B, modify the remote address in the configuration file,
/etc/openvpn/tap0-br.conf.
# /etc/openvpn/tap0-br.conf
# point to the peer
remote 192.168.8.173
dev tap0
4-20
UC-8410/8416/8418/8430 Managing Communication
secret /etc/openvpn/secrouter.key
cipher DES-EDE3-CBC
auth MD5
tun-mtu 1500
tun-mtu-extra 64
ping 40
up /etc/openvpn/tap0-br.sh
Next, modify the routing table in the /etc/openvpn/tap0-br.sh script file.
#---------------------------------- Start----------------------------
#!/bin/sh
# /etc/openvpn/tap0-br.sh
# value after “-net” is the subnet behind the remote peer
route add -net 192.168.2.0 netmask 255.255.255.0 dev br0
#---------------------------------- end -----------------------------
Note: Select cipher and authentication algorithms by specifying “cipher” and “auth”. To see with algorithms
are available, type:
# openvpn --show-ciphers
# openvpn --show—auths
4. After configuring the remote peer, we can load the bridge into kernel, reconfigure eth1, and enable IP
forwarding on both OpenVPN machine.
# /etc/openvpn/openvpn-bridge start
If you see the line “Peer Connection Initiated with 192.168.8.173:5000” on each machine, the connection
between OpenVPN machines has been established successfully on UDP port 5000.
Note: You can create link symbols to enable the /etc/openvpn/openvpn-bridge script at boot time:
# ln -s /etc/openvpn/openvpn-bridge /etc/rc.d/rc3.d/S32vpn-br
# ln -s /etc/openvpn/openvpn-bridge /etc/rc.d/rc6.d/K32vpn-br
5. On each OpenVPN machine, check the routing table by typing the command:
# route
Destination Gateway Genmsk Flags Metric Ref Use Iface
192.168.4.0 * 255.255.255.0 U 0 0 0 br0
192.168.2.0 * 255.255.255.0 U 0 0 0 br0
192.168.8.0 * 255.255.255.0 U 0 0 0 eth0
Interface eth1 is connected to the bridging interface br0, to which device tap0 also connects, whereas the
virtual device tun sits on top of tap0. This ensures that all traffic from internal networks connected to
interface eth1 that come to this bridge write to the TAP/TUN device that the OpenVPN program monitors.
Once the OpenVPN program detects traffic on the virtual device, it sends the traffic to its peer.
6. To create an indirect connection to Host B from Host A, add the following routing item:
route add –net 192.168.4.0 netmask 255.255.255.0 dev eth0
To create an indirect connection to Host A from Host B, add the following routing item:
route add –net 192.168.2.0 netmask 255.255.255.0 dev eth0
Now ping Host B from Host A by typing:
ping 192.168.4.174
4-21
UC-8410/8416/8418/8430 Managing Communication
A successful ping indicates that you have created a VPN system that only allows authorized users from one
internal network to access users at the remote site. For this system, all data is transmitted by UDP packets
on port 5000 between OpenVPN peers.
2. The configuration procedure is almost the same as for the previous example. The only difference is that you
will need to comment out the parameter “up” in “/etc/openvpn/tap0-br.conf” and
“/etc/openvpn/tap0-br.conf”.
Setup 3: Routed IP
4-22
UC-8410/8416/8418/8430 Managing Communication
2. On machine OpenVPN A, modify the remote address in the configuration file, /etc/openvpn/tun.conf.
#--------------------------------- Start-----------------------------
#!/bin/sh
# value after “-net” is the subnet behind the remote peer
route add -net 192.168.4.0 netmask 255.255.255.0 gw $5
#--------------------------------- end ------------------------------
On machine OpenVPN B, modify the remote address in the configuration file, /etc/openvpn/tun.conf.
remote 192.168.8.173
dev tun
secret /etc/openvpn/secrouter.key
cipher DES-EDE3-CBC
auth MD5
tun-mtu 1500
tun-mtu-extra 64
ping 40
ifconfig 192.168.4.174 192.168.2.173
up /etc/openvpn/tun.sh
#--------------------------------- Start----------------------------
#!/bin/sh
# value after “-net” is the subnet behind the remote peer
route add -net 192.168.2.0 netmask 255.255.255.0 gw $5
#--------------------------------- end -----------------------------
Note that the parameter “ifconfig” defines the first argument as the local internal interface and the second
argument as the internal interface at the remote peer.
Note that $5 is the argument that the OpenVPN program passes to the script file. Its value is the second
argument of ifconfig in the configuration file.
3. Check the routing table after you run the OpenVPN programs, by typing the command:
# route
4-23
UC-8410/8416/8418/8430 Managing Communication
Package Management—ipkg
ipkg is a very lightweight package management system. It also allows for dynamic installation/removal of
packages on a running system. Because the disk space is limited, we provide the software as extension
packages. You can use ipkg-cl to install or remove .ipk packages on the UC-8410/8416/8418/8430-LX.
192.168.3.127 – Putty
192.168.3.127 – Putty
192.168.3.127 – Putty
Remove a package
192.168.3.127 – Putty
Volume Control
mixer:
Use the following commands to control the input and output volume. The volume range is from 0 to 100.
Device File on Linux: /dev/mixer
Eample:
Example:
Use the following commands to set the left/right channel volume at 70/80.
4-24
UC-8410/8416/8418/8430 Managing Communication
vplay can be used for playing a wave file. It supports playing mono or stereo wave files at a 11025, 22050, or
44100 HZ sampling rate, with 8 or 16 bits.
vrec can be used to record a wave file. It supports playing mono wave files at a 11025, 22050, or 44100 HZ
sampling rate, and with 8 or 16 bits.
NOTE The vrec does not support record the stereo format music.
4-25
5
5. Programmer's Guide
NOTE 1. The default Moxa file system only enables the network. It lets users recover the user file system when
it fails.
2. The user file system is a complete file system. Users can create and delete directories and files (including
source code and executable files) as needed.
3. Users can create the user file system on the PC host or target platform, and then copy it to the
UC-8410/8416/8418/8430.
The host tool chain that comes with the UC-8410/8416/8418/8430/8430 contains a suite of cross compilers
and other tools, as well as the libraries and headers that are necessary to compile applications for the
UC-8410/8416/8418/8430. The host environment must be running Linux to install the
UC-8410/8416/8418/8430/8430 GNU Tool Chain. We have confirmed that the following Linux distributions can
be used to install the tool chain:
The Tool Chain will need about 836 MB of hard disk space on your PC. The UC-8410/8416/8418/8430/8430
Tool Chain is located on the UC-8410/8416/8418/8430/8430 CD. To install the Tool Chain, insert the CD into
your PC and then issue the following commands:
Wait for a few minutes while the Tool Chain is installed automatically on your Linux PC. Once the host
environment has been installed, add the directory /opt/montavista/pro/devkit/arm/xscale_be/bin/ to your
path and the directory /opt/montavista/pro/devkit/arm/xscale_be/man/ to your manual path. You can do this
temporarily for the current login session by issuing the following commands:
#export PATH=“/usr/local/arm-linux/bin:$PATH”
#export MANPATH=“/usr/local/arm-linux/man:$MANPATH”
5-2
UC-8410/8416/8418/8430 Programmer's Guide
#export PATH=“/usr/local/arm-linux-4.4.2/bin:$PATH”
#export MANPATH=“/usr/local/arm-linux-4.4.2/man:$MANPATH”
Alternatively, you can add the same commands to $HOME/.bash_profile to cause it to take effect for all login
sessions initiated by this user.
Obtaining help
Use the Linux man utility to obtain help on many of the utilities provided by the tool chain. For example to get
help on the arm-linux-gcc compiler, issue the command:
#man arm-linux-gcc
To compile a simple C application, just use the cross compiler instead of the regular compiler:
Most of the cross compiler tools are the same as their native compiler counterparts, but with an additional
prefix that specifies the target system. In the case of x86 environments, the prefix is i386-linux- and in the
case of the UC-8410/8416/8418/8430/8430 XScale boards, it is xscale-linux-.
For example, the native C compiler is gcc and the cross C compiler for XScale in the
UC-8410/8416/8418/8430/8430 is xscale-linux-gcc.
5-3
UC-8410/8416/8418/8430 Programmer's Guide
This is where 2000 is the network port number on which the server waits for a connection from the client.
This can be any available port number on the target. Following this are the name of the program to be
debugged (hello-debug), plus that program’s arguments. Output similar to the following will be sent to the
console:
2. Use the following command on the host to change to the directory that contains hello-debug:
cd /my_work_directory/myfilesystem/testprograms
The command produces another line of output on the target console, similar to the following:
192.168.4.99 is the machine’s IP address, and 2000 is the port number. You can now begin debugging in
the host environment using the interface provided by DDD.
5. Set a breakpoint on main by double clicking, or entering b main on the command line.
6. Click the cont button
Device API
The UC-8410/8416/8418/8430/8430 supports control devices with the ioctl system API. You will need to
include <moxadevice.h>, and use the following ioctl function.
#man ioctl
1. Function: RTC_RD_TIME
2. Function: RTC_SET_TIME
5-4
UC-8410/8416/8418/8430 Programmer's Guide
Buzzer
The device node is located at /dev/console. The UC-8410/8416/8418/8430/8430 supports Linux standard
buzzer control, with the UC-8410/8416/8418/8430’s buzzer running at a fixed frequency of 100 Hz. You must
include <sys/kd.h>.
1. Function: KDMKTONE
Kernel boot
…..
….
all:
xscale-linux-gcc –o xxxx xxxx.c -lmoxalib
int swtd_open(void)
Description
If you would like to activate Watchdog for the AP, you must call this function.
Input
None
Output
The return value is file handle. If there is an error, it will return a negative value.
Description
Enable the application sWatchDog. You must do an ack after this process.
Input
int fd - the file handle, from the swtd_open() return value.
5-5
UC-8410/8416/8418/8430 Programmer's Guide
unsigned long time - The time you wish to ack sWatchDog periodically. You must ack the
sWatchDog before timeout. If you do not ack, the system will reboot automatically. The minimum time is
50 msec, and the maximum time is 60 seconds. The time unit is msec.
Output
If you receive 0 (zero), it means the function is working. If you receive any other number, then there is
something wrong with this function.
Description:
Call this function if you would like the AP to stop using the Watchdog.
Input :
int fd - the file handle from swtd_open() return value.
Output:
If you receive 0 (zero), it means the function is working. If you receive any other number, then there is
something wrong with this function.
Description:
Get current setting values.
mode –
1 for user application enable sWatchDog: need to do ack.
0 for user application disable sWatchdog: does not need to do ack.
time – The time period to ack sWatchDog.
Input:
int fd - the file handle from swtd_open() return value.
int *mode - the function will return the status: enable or disable.
unsigned long *time – the function will return the current time period.
Output:
If you receive 0 (zero), it means the function is working. If you receive any other number, then there is
something wrong with this function.
Description:
Acknowledge sWatchDog. When the user application enable sWatchDog, it need to call this function
periodically with user predefined time in the application program.
Input:
int fd - the file handle from swtd_open() return value.
Output:
If you receive 0 (zero), it means the function is working. If you receive any other number, then there is
something wrong with this function.
Description:
Close the file handle.
Input:
int fd - the file handle from swtd_open() return value.
Output:
If you receive 0 (zero), it means the function is working. If you receive any other number, then there is
something wrong with this function.
4. Special Note
5-6
UC-8410/8416/8418/8430 Programmer's Guide
When you “kill the application with -9” or “kill without option” or “Ctrl+c” the kernel will change to auto ack
the sWatchDog.
When your application enables the sWatchDog and does not ack, your application may have a logical error,
or your application has made a core dump. The kernel will not change to auto ack. This can cause a serious
problem, causing your system to reboot again and again.
Example 1:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <moxadevice.h>
int main(int argc, char *argv[])
{
int fd;
fd = swtd_open();
if ( fd < 0 ) {
printf(“Open sWatchDog device fail !\n”);
exit(1);
}
swtd_enable(fd, 5000); // enable it and set it 5 seconds
while ( 1 ) {
// do user application want to do
…..
….
swtd_ack(fd);
…..
….
}
swtd_close(fd);
exit(0);
}
The makefile is shown below:
all:
xscale-linux-gcc –o xxxx xxxx.c –lmoxalib
Example 2:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <moxadevice.h>
static void mydelay(unsigned long msec)
{
struct timeval time;
time.tv_sec = msec / 1000;
time.tv_usec = (msec % 1000) * 1000;
select(1, NULL, NULL, NULL, &time);
}
static int swtdfd;
static int stopflag=0;
5-7
UC-8410/8416/8418/8430 Programmer's Guide
all:
xscale-linux-gcc –o xxxx xxxx.c –lmoxalib
Digital I/O
Digital Output channels can be set to high or low. The channels are controlled by the function call
set_dout_state( ). The Digital Input channels can be used to detect the state change of the digital input
signal. The DI channels can also be used to detect whether or not the state of a digital signal changes during
a fixed period of time. This can be done with the function call set_din_event( ). Moxa provides 5 function calls
to handle digital I/O state changes and event handling.
5-8
UC-8410/8416/8418/8430 Programmer's Guide
#define DIO_HIGH 1
#define DIO_LOW 0
int set_dout_state(int doport, int state)
Input: int doport - which DOUT port you want to set. Port starts from 0 to 3.
int state - to set high or low state; DIO_HIGH (1) for high, DIO_LOW (0) for low.
Output: none.
Return: reference the error code.
Input: int diport - get the current state of which DIN port. Port numbering is from 0 to 3.
int *state - save the current state.
Output: state - DIO_HIGH (1) for high, DIO_LOW (0) for low.
Return: reference the error code.
Description: Set the event for DIN when the state is changed from high to low or from low to high.
Input: int diport - the port that will be used to detect the DIN event.
Port numbering is from 0 to 3.
void (*func) (int diport) - Not NULL
> Returns the call back function. When the event occurs, the call back function will be invoked.
NULL > Clears this event
5-9
UC-8410/8416/8418/8430 Programmer's Guide
Special Note
Do not forget to link to the library libmoxalib.a for DI/DO programming, and also include the header file
moxadevice.h. The DI/DO library only can be used by one program at a time.
Examples
Example 1
Description: The program indicates to connect DO1 to DI1, change the digital output state to high or low by
manual input, and then detect and count the state changed events from DI1.
#include <stdio.h>
#include <stdlib.h>
#include <moxadevice.h>
#include <fcntl.h>
#ifdef DEBUG
#define dbg_printf(x...) printf(x)
#else
#define dbg_printf(x...)
#endif
#define MIN_DURATION 40
static char *DataString[2]={“Low “, “High “};
static void hightolowevent(int diport)
{
printf(“\nDIN port %d high to low.\n”, diport);
}
static void lowtohighevent(int diport)
{
printf(“\nDIN port %d low to high.\n”, diport);
}
int main(int argc, char * argv[])
{
int i, j, state, retval;
unsigned long duration;
while( 1 ) {
5-10
UC-8410/8416/8418/8430 Programmer's Guide
5-11
UC-8410/8416/8418/8430 Programmer's Guide
5-12
UC-8410/8416/8418/8430 Programmer's Guide
Note: For the UC-8418, 8 additional digital input channels and 8 additional digital output channels
are provided. The port numbers for these go from 4 to 11.
UART
The normal tty device node is located at /dev/ttyM0 … ttyM7, and the modem tty device node is located at
/dev/cum0 … cum7.
The UC-8410/8416/8418/8430/8430 supports Linux standard termios control. The Moxa UART Device API
allows you to configure ttyM0 to ttyM7 as RS-232, RS-422, 4-wire RS-485, or 2-wire RS-485. The
UC-8410/8416/8418/8430/8430 supports RS-232, RS-422, 2-wire RS-485, and 4-wire RS485.
#define RS232_MODE 0
#define RS485_2WIRE_MODE 1
#define RS422_MODE 2
#define RS485_4WIRE_MODE 3
1. Function: MOXA_SET_OP_MODE
Description
Set the interface mode. Argument 3 mode will pass to the UART device driver and change it.
2. Function: MOXA_GET_OP_MODE
Description
Get the interface mode. Argument 3 mode will return the interface mode.
There are two Moxa private ioctl commands for setting up special baudrates.
Function: MOXA_SET_SPECIAL_BAUD_RATE
Function: MOXA_GET_SPECIAL_BAUD_RATE
If you use this ioctl to set a special baudrate, the termios cflag will be B4000000, in which case the B4000000
definition will be different. If the baudrate you get from termios (or from calling tcgetattr()) is B4000000, you
must call ioctl with MOXA_GET_SPECIAL_BAUD_RATE to get the actual baudrate.
Setinterface
The Serial Port Expansion Module has 8 serial ports, labeled ttyM0 to ttyM7. The ports support RS-232, RS-422,
and RS-485 2-wire and 4-wire operation modes with baudrate settings up to 921600 bps.
The default operation mode is set to RS-232. You can use the setinterface command to change the serial port
operation mode.
5-13
UC-8410/8416/8418/8430 Programmer's Guide
2 RS-422
3 RS-485 4-wire
Baudrate inaccuracy
NOTE: The Inaccuracy should less than 2% for the device to work reliably.
Special Note
1. If the target baudrate is not a special baudrate (e.g., 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800,
2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600), the termios cflag will be set
to the same flag.
5-14
UC-8410/8416/8418/8430 Programmer's Guide
2. If you use stty to get the serial information, you will get a speed equal to 0.
SRAM
1. Introduction
The UC-8410/8416/8418/8430/8430 provides 256 KB of embedded SRAM. As there is a system battery
inside the computer, the SRAM can work and be used to keep data even when the system is crashed. This
means that the data stored on the SRAM will not be lost after the UC-8410/8416/8418/8430/8430 is
powered off.
/**************************************************************
History :
Versoin Author Date Comment
1.0 Jared Wu. 09-11-2008 Write a pattern to SRAM.
**************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <linux/kd.h>
#define SRAM_SIZE 0x00040000 // 256 Kbytes
static char sram_buf1[SRAM_SIZE], sram_buf2[SRAM_SIZE];
int main(int argc, char * argv[])
{
int fd, len;
unsigned long ms=0;
char pattern=‘9’;
if ( argc > 2 ) {
printf(“Usage: %s [pattern]\n”);
exit(0);
}
if ( argc == 2 ) {
pattern=argv[1][0];
printf(“pattern:%c\n”, pattern);
}
fd = open(“/dev/sram”, O_RDWR);
if( fd < 0 ) {
printf(“Open /dev/sram fail”);
exit(0);
}
// Write the sram with patern
memset(sram_buf1, pattern, sizeof(sram_buf1));
len=write(fd, sram_buf1, sizeof(sram_buf1));
if( len < 0 ) {
printf(“Write /dev/sram fail”);
exit(0);
}
printf(“The content is written\n”);
close(fd);
5-15
UC-8410/8416/8418/8430 Programmer's Guide
}
/**************************************************************
History :
Versoin Author Date Comment
1.0 Jared Wu. 09-11-2008 Read from the SRAM and compare with some pattern.
**************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <linux/kd.h>
#define SRAM_SIZE 0x00040000 // 256 Kbytes
static char sram_buf1[SRAM_SIZE], sram_buf2[SRAM_SIZE];
int main(int argc, char * argv[])
{
int fd, len;
unsigned long ms=0;
char pattern=‘9’;
if ( argc > 2 ) {
printf(“Usage: %s [pattern]\n”);
exit(0);
}
if ( argc == 2 ) {
pattern=argv[1][0];
printf(“pattern:%c\n”, pattern);
}
fd = open(“/dev/sram”, O_RDWR);
if( fd < 0 ) {
printf(“Open /dev/sram fail”);
exit(0);
}
// Write the sram with pattern
memset(sram_buf1, pattern, sizeof(sram_buf1));
// Read from sram and compare with pattern
len=read(fd, sram_buf2, sizeof(sram_buf2));
if( len < 0 ) {
printf(“Read from /dev/sram fail\n”);
exit(0);
}
if ( memcmp(sram_buf1, sram_buf2, SRAM_SIZE) != 0 ) {
printf(“Memory compared fail\n”);
exit(0);
}
printf(“The content is identical\n”);
close(fd);
}
CC = xscale-linux-gcc
5-16
UC-8410/8416/8418/8430 Programmer's Guide
CPP = xscale-linux-gcc
SOURCES = hello.c
OBJS = $(SOURCES:.c=.o)
all: hello
hello: $(OBJS)
$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
clean:
rm -f $(OBJS) hello core *.gdb
Introduction
CAN is a broadcast serial bus standard for connecting electronic control units (ECUs).
Each node is able to send and receive messages, but not simultaneously: a message (consisting primarily of an
ID—usually chosen to identify the message-type/sender—and up to eight message bytes) is transmitted
serially onto the bus, one bit after another. This signal-pattern codes the message (in NRZ) and is sensed by
all nodes.
Moxa embedded computers provide the CAN bus interface for industrial CAN communication. Users can use the
file control interface to read, write or control the CAN interface as a file for easy CAN programming.
Programming Guide
The CAN data format looks like this:
moxacan_ioctl.h
#ifndef _MOXACAN_IOCTL_H
#define _MOXACAN_IOCTL_H
#ifndef BIT
#define BIT(x) (1<<(x))
#endif // BIT
#define MAX_CAN_DATA_LENGTH 8
typedef union __attribute__ ((packed)) can_data_union {
unsigned char array[MAX_CAN_DATA_LENGTH];
struct byte_struct {
unsigned char byte1;
unsigned char byte2;
5-17
UC-8410/8416/8418/8430 Programmer's Guide
We can open /dev/can[n] to use the CAN device. Then read(), write() or ioctl() the device files. If you complete
the using, you should close() this file to release this device.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include “moxacan_ioctl.h”
#define PORT1_NAME “/dev/can0
#define PORT2_NAME “/dev/can1
int main(int argc, char *argv[])
{ int fd1, fd2, i, baudrate;
user_frame_t txframe, rxframe;
fd1 = open(PORT1_NAME, O_RDWR);
if ( fd1 < 0 ) {
printf(“Open %s fail !\n”, PORT1_NAME);
return -1;
}
fd2 = open(PORT2_NAME, O_RDWR);
if ( fd2 < 0 ) {
printf(“Open %s fail !\n”, PORT2_NAME);
return -1;
}
baudrate = 100000;
ioctl(fd1, MOXACAN_IOCTL_SET_BAUD_RATE, &baudrate);
ioctl(fd2, MOXACAN_IOCTL_SET_BAUD_RATE, &baudrate);
memset(&txframe, 0, sizeof(txframe));
memset(&txframe, 0, sizeof(rxframe));
txframe.id = 12;
txframe.data_length = MAX_CAN_DATA_LENGTH;
txframe.info |= USER_EXTEND_ID;
for ( i=0; i<MAX_CAN_DATA_LENGTH; i++ )
txframe.data.array[i] = 0x30+i;
5-18
UC-8410/8416/8418/8430 Programmer's Guide
Software Lock
“Software Lock” is an innovative technology developed by the Moxa engineering team, and can be used by a
system integrator or developer to protect applications from being copied. An application is compiled into a
binary format bound to the embedded computer, and the operating system that the application runs on. As
long as it is obtained from the computer, it can be installed on the same hardware and under the same
operating system, resulting in a loss of the add-on value created by the developer.
Users can deploy this data encryption method to develop the software for the applications. The binary file
associated with each of your applications needs to undergo an additional encryption process after you have
developed it. The process requires you to install an encryption key in the target computer.
1. Choose an encryption key (e.g.,”ABigKey”) and install it in the target computer by a pre-utility program
called ‘setkey’.
#setkey ABigKey
5-19
UC-8410/8416/8418/8430 Programmer's Guide
NOTE: Use the following command to clear the encryption key on the target computer.
#setkey ““
3. On the development PC, run the utility program ‘binencryptor’ to encrypt your program with an encryption
key.
4. Upload the encrypted program file to the target computer by FTP or NFS and test the program.
The encryption key is a computer-wise key. This means that the computer has only one key installed.
Running the program ‘setkey’ multiple times overrides the existing key.
To prove the effectiveness of this software protection mechanism, prepare a target computer on which an
encryption key has not been installed, or install a key different from that used to encrypt your program. In
either case, the encrypted program fails immediately.
This mechanism also allows computers with an encryption key installed to bypass programs that are not
encrypted. This is handy in the development phase since you can develop your programs and test them
cleanly on the target computer.
Qt-embedded
The UC-8430 offers the QT library which helps programmers design the UI framework. See the following for
details.
1. QT Programming
3. Cross-compiling
#include <QtGui>
#include <QApplication>
Write the QT program to run the in thetarget environment. A basic QT program is shown below.
#include <QtGui>
#include <QApplication>
#include <QLabel>
5-20
UC-8410/8416/8418/8430 Programmer's Guide
3. Compile
Make
4. Execute
./hello
Set up Qt development
The qt-libraries have been included in arm-linux_2.3_YYMMDDHH.sh/arm-linux_3.x_YYMMDDHH.sh. You can
launch the auto-installed script to install the libraries. The setup the QTDIR and PATH for cross-compiling:
5-21
UC-8410/8416/8418/8430 Programmer's Guide
To cross compile:
Debian:~# make
You can also run the second Qt application on another VGA output:
NOTE Refer to the Qt-embedded Web site, http://qt.nokia.com/doc/4.6/index.html, for more details on Qt
programming ,
5-22
A
A. Firmware Upgrade Procedure
Moxa provides a boot loader utility for firmware upgrade or recovery. You will need the following items to use
this utility.
If you are familiar with Moxa embedded computers and the firmware upgrade procedure, you may skip to Step
C. However, we suggest that you go through all three steps to ensure the firmware upgrades properly.
1. Unscrew the cover on the back of the UC-8410 series embedded computer.
2. Connect the console port with a console port cable to your PC.
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
3. Connect your embedded computer to the power source. The power input is located on the rear panel.
4. Launch a serial communication tool to access your embedded computer. We suggest that you use
HyperTerminal, which is built into Windows XP. Click Start Programs Accessories
Communications and then select HyperTerminal.
5. After HyperTerminal launches, enter UC-8410 or another name for the connection.
A-2
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
8. You can change the COM port number in the Properties window. Click Configure for additional
configuration options.
Click OK to continue.
A-3
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
10. Click the Settings tab and then select VT100 (for Emulation). Click OK to complete the configuration.
1. You will need to download a free TFTP server package to upgrade the firmware for the boot loader utility.
Link to the following URL to download:
ftp://papa.indstate.edu/
2. When you have finished downloading, extract the files to your PC.
A-4
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
1. Connect to Moxa’s website at http://www.moxa.com, and then select Software from the Support
drop-down menu.
2. Under Search for Software, select the product line and then choose the specific product model. Click on
Search to continue.
A-5
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
3. In the software list, select the firmware for your model. Choose the appropriate OS and then click the
download icon to start downloading the new firmware. Note: Check the filename, it may differ from
the filename shown below.
4. Put the latest firmware icon in the same directory as the TFTP files.
5. Next, connect LAN1 of the embedded computer to your PC using a cross-over Ethernet cable. The LAN1
port is located on the rear panel of the embedded computer.
A-6
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
6. Press and hold down the DEL key on your PC and power on the embedded computer at the same time. You
will be guided to the boot loader utility menu, as show below.
1. In the boot loader utility, select [0] Network Configuration, and then [0] Change IP Setting to
configure IP addresses.
A-7
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
2. You will need to enter the IP address of the embedded computer and your PC. Follow the below to configure
the IP addresses.
a. From Start Settings, select Network Connections.
A-8
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
c. Click the General tab and select Internet Protocol (TCP/IP), and then click on Properties.
d. Next, select Use the following IP address and enter the IP address and Subnet mask.
For example:
IP address: 192.168.1.1 (This IP address is only an example; you may assign any IP address of your
choice as long as it’s on the same LAN as your PC.)
A-9
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
3. Go back to the boot load utility menu and assign the local IP address, and then enter the server IP address.
The local IP address is the IP address of the embedded computer. Note that the local IP address must
be on the same LAN as the server IP address. For example, if the server IP address is 192.168.1.1, you
can choose a local IP address between 192.168.1.2 to 192.168.1.254.
4. Select [z] Quit to command line to exit the IP setting option. Next, select [2] Firmware Upgrade, and
then [0] Load from LAN to continue.
A-10
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
5. To start the TFPF server, double-click on the tftpd32 icon to launch the TFTP server.
6. When the TFTP server has been launched, the following screen will appear.
A-11
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
7. Go back to the boot loader utility menu and enter the file name of the firmware image.
9. It will take several minutes for the firmware files to be written to your embedded computer. Do not power
off your computer!
A-12
UC-8410/8416/8418/8430 Firmware Upgrade Procedure
10. When you see Update OK, the firmware upgrade is finished. At this point, you may reboot the embedded
computer to complete the firmware upgrade or recovery from the boot loader utility.
11. If you cannot reboot your embedded computer (after following all the steps above), contact Moxa’s
technical support staff for further assistance.
A-13
B
B. System Commands
File Manager
cp copy file
ls list file
ln make symbolic link file
mount mount and check file system
rm delete file
chmod change file owner & group & user
chown change file owner
chgrp change file group
chroot runs a command with a specified root directory.
sync sync file system; save system file buffer to hardware
mv move file
pwd display active file directly
df list active file system space
mkdir make new directory
rmdir delete directory
find search for files in a directory hierarchy
head output the first part of files
mkfifo creates a FIFO, special character file, or special block file with the specified name
mknod creates a FIFO, special character file, or special block file with the specified name
touch change file timestamps
which Locate a program file in the user’s path.
Editor
vi text editor
cat dump file context
grep Search string on file
egrep search string on file of Extended regular expressions
fgrep Search file(s) for lines that match a fixed string
cut Get string on file
find Find file where are there
more dump file by one page
test test if file exists or not
sleep Sleep (seconds)
usleep suspend execution for microsecond intervals
echo echo string
sed Steam editor
UC-8410/8416/8418/8430 System Commands
Network
arp manipulate the system ARP cache
ping ping to test network
route routing table manager
netstat display network status
ifconfig set network IP address
tftp IPV4 Trivial File Transfer Protocol client
telnet Connects the local host with a remote host, using the Telnet interface.
ftp file transfer protocol
ifdown, ifup bring a network interface up, or take a network interface down
ip show / manipulate routing, devices, policy routing and tunnels
tcpsvd TCP/IP service daemon
wget The non-interactive network downloader.
Process
kill kill process
ps display now running process
fuser identify processes using files or sockets
killall sends a signal to all processes running any of the specified commands
nice, renice run a program with modified scheduling priority / alter priority of running processes
pidof find the process ID of a running program
run-parts run scripts or programs in a directory
start-stop-deamon start and stop system daemon programs
top display Linux tasks
Modules
insmod insert a module into the kernel
lsmod shows which kernel modules are currently loaded
modprobe intelligently adds or removes a module from the Linux kernel
rmmod remove module from kernel
Other
dmesg dump kernel log message
zcat Dump .gz file context
free display system memory usage
date print or set the system date and time
env run a program in a modified environment
clear clear the terminal screen
reboot reboot or power off/on the server
B-2
UC-8410/8416/8418/8430 System Commands
B-3