EM-1240-LX User’s Manual Fourth Edition, September 2008 www.moxa.com/product © 2008 Moxa Inc., All rights reserved. Reproduction without permision is prohibited.
EM-1240-LX User’s Manual 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 Copyright © 2008 Moxa Inc. All rights reserved. Reproduction without permission is prohibited. Trademarks MOXA is a registered trademark of Moxa Inc. All other trademarks or registered marks in this manual belong to their respective manufacturers.
Table of Contents Chapter 1 Introduction ..................................................................................................1-1 Overview.................................................................................................................................. 1-2 Package Checklist .................................................................................................................... 1-2 Product Features .....................................................................
Enabling NAT at Bootup .............................................................................................. 4-7 Configuring Dial-in/Dial-out Service ...................................................................................... 4-8 Dial-out Service............................................................................................................ 4-8 Dial-in Service..............................................................................................................
1 Chapter 1 Introduction The Moxa EM-1240-LX Series of Mini RISC-based Ready-to-Run Embedded Computer features dual 10/100 Mbps Ethernet ports and four RS-232/422/485 serial ports in a built-in µClinux ARM9 module. In addition, the EM-1240-LX supports an SD memory card for storage expansion, offers high performance communication and unlimited storage in a super compact, palm-sized module.
EM-1240-LX User’s Manual Introduction Overview The EM-1240-LX Series of mini RISC-based communication platforms are ideal for your embedded applications. The EM-1240-LX comes with 4 RS-232/422/485 serial ports and dual 10/100 Mbps Ethernet LAN ports to provide users with a versatile communication platform. The EM-1240-LX uses the Moxa ART ARM9 RISC CPU.
EM-1240-LX User’s Manual Introduction Product Specifications Hardware Specifications Model CPU RAM Flash LAN LAN Protection Serial Ports Serial Console Storage Expansion GPIO Real-time Clock Watchdog Timer Buzzer Signals LED Signals Reset Signal Power Input Dimensions (W × L) Operating temperature Storage temperature Module Interface EM-1240 Embedded Module Moxa ART ARM9 32-bit 192 MHz processor 16 MB 8 MB Auto-sensing 10/100 Mbps × 2 Built-in 1.
EM-1240-LX User’s Manual Introduction Software Specifications Kernel Protocol Stack File System Msh pppd PPPoE snmpd busybox Tinylogin Telnetd telnet inetd ftpd ftp boa ntpdate Linux Tool Chain Windows Tool Chain UC Finder µClinux Kernel 2.6.
EM-1240-LX User’s Manual Introduction Hardware Block Diagram Ethernet Power Circuit RTC LAN 1 LAN 2 PHY PHY MAC MAC 16 MB SDRAM 8 MB Flash MOXA ART CPU 32-bit ARM9 192 MHz Watchdog SD/GPIO Function UART UART UART UART UART Serial Port 1 Serial Port 2 Serial Console Port 4 Port Serial Port 3 RS-232 RS-232/422/485 Appearance EM-1240 Embedded Module + Development Kit 1-5
EM-1240-LX User’s Manual Introduction EM-1240 Embedded Module EM-1240 Development Kit 1-6
EM-1240-LX User’s Manual Introduction Dimensions EM-1240 Embedded Module EM-1240 Development Kit Installing the EM-1240-LX If you would like to use the EM-1240 Embedded Module and the EM-1240 Development Kit, insert the EM-1240 Embedded Module vertically onto the Development Kit.
EM-1240-LX User’s Manual Introduction LED Indicators The following table explains the function of the five LED indicators located on the EM-1240-LX’s top panel. LED Name Ready P1/P2 (Tx) P1/P2 (Rx) LED Color Green Green LED Function Power is on and functioning normally. Serial port 1 or 2 is transmitting data. Off Serial port 1 or 2 is not transmitting data. Yellow Serial port 1 or 2 is receiving data. Off Serial port 1 or 2 is not receiving data.
EM-1240-LX User’s Manual Introduction Connecting the Power Connect the “live-wire” end of the 12-48 VDC power adaptor to the EM-1240-LX’s terminal block. If the power is properly supplied, the “Ready” LED will glow a solid green after a 25 to 30 second delay. Grounding the EM-1240-LX Grounding and wire routing help limit the effects of noise due to electromagnetic interference (EMI). Run the ground wire from the ground screw to the grounding surface prior to connecting devices.
EM-1240-LX User’s Manual Introduction The 10/100 Mbps Ethernet LAN 1 and LAN 2 ports use 8-pin RJ45 connectors. Pinouts for these ports are given in the following diagram. 8-pin RJ45 10 Mbps indicator 100 Mbps indicator 1 Pin 1 2 3 4 5 6 7 8 8 Signal ETx+ ETxERx+ ----ERx----- Connecting to a Serial Device Connect the serial cable between the EM-1240-LX and the serial device(s). Serial ports P1 and P2 use male DB9 connectors, and can be configured for RS-232/422/485 by software.
EM-1240-LX User’s Manual Introduction Internal SD Socket The EM-1240-LX provides an internal SD socket for storage expansion. It allows users to plug in a Secure Digital (SD) memory card compliant with the SD 1.0 standard for up to 1 GB of additional memory space. To install an additional SD card, you must first remove the EM-1240-LX’s outer cover to access the slot.
EM-1240-LX User’s Manual Introduction Real-time Clock The EM-1240-LX’s real time clock is powered by a lithium battery. We strongly recommend that you do not replace the lithium battery without the help of Moxa’s support team. If the battery needs to be changed, contact the Moxa RMA service team for RMA service. ATTENTION The battery may explode if replaced by an incorrect type. To avoid this potential danger, always be sure to use the correct type of battery.
2 Chapter 2 Getting Started In this chapter, we explain the basic procedure for getting the EM-1240-LX connected and ready for your needs. In this chapter we cover the following topics: Powering on the EM-1240-LX Connecting the EM-1240-LX to a PC ¾ Console Port ¾ Telnet Configuring the Ethernet Interface Installing a Secure Digital (SD) Memory Card Developing Your Applications ¾ Installing the EM-1240-LX Tool Chain ¾ Compiling Hello.
EM-1240-LX User’s Manual Getting Started Powering on the EM-1240-LX Connect the SG wire to the Shielded Contact located on the upper left corner of the EM-1240-LX, and then power on the EM-1240-LX by connecting the power adaptor. It takes about 16 seconds for the system to boot up. Once the system is ready, the Ready LED will light up. ATTENTION After connecting the EM-1240-LX to the power supply, it will take about 16 seconds for the operating system to boot up.
EM-1240-LX User’s Manual Getting Started Telnet If you know at least one of the two IP addresses and netmasks, then you can use Telnet to connect to the EM-1240-LX’s console. Default IP Address Default Netmask LAN 1 192.168.3.127 255.255.255.0 LAN 2 192.168.4.127 255.255.255.0 Telnet can be used locally by using a crossover Ethernet cable to connect your computer to the EM-1240-LX, or over a LAN or the Internet. The default IP addresses and netmasks are shown above.
EM-1240-LX User’s Manual Getting Started Configuring the Ethernet Interface In this section, we use the serial console to explain how to modify the EM-1240-LX’s network settings. 1. Change directories by issuing the command cd /etc. 2. Type the command vi rc to use the VI Editor to edit the configuration file. The IP addresses for the EM-1240-LX’s LAN1 and LAN2 are given as ifconfig eth0 192.168.3.127 ifconfig eth1 192.168.4.127 as shown in the following figure.
EM-1240-LX User’s Manual 3. Getting Started You may also configure the EM-1240-LX to request IP addresses from a DHCP server. In this case, use the sharp sign (#) to comment out one or both “ifconfig” lines, and then add the setting about the “dhcpcd” into the rc file as below. dhcpcd -p -a eth0 & dhcpcd -p -a eth1 & Note that the EM-1240-LX will send out DHCP broadcast packets, and then get the IP addresses from the first DHCP server that responds. 4.
EM-1240-LX User’s Manual Getting Started Installing a Secure Digital (SD) Memory Card The EM-1240-LX provides an internal SD socket for storage expansion. To access this socket, perform the following steps to install the SD memory card. Step 1: Find the exact location of the SD socket. Step 2: Insert the SD card into the socket. Make sure the card is situated correctly. Step 3: Push the SD card inward.
EM-1240-LX User’s Manual Getting Started Installing the EM-1240-LX Tool Chain Linux The PC must have the Linux Operating System pre-installed to install the EM-1240-LX Linux GNU Tool Chain. Debian 3.0R-Woody, Redhat 7.3/8.0 and compatible versions are recommended. The Tool Chain requires about 100 MB of hard disk space (on your PC). The EM-1240-LX Tool Chain can be found on the EM-1240-LX Document & Software CD.
EM-1240-LX User’s Manual Getting Started Uploading “Hello” to the EM-1240-LX To use FTP to upload hello to the EM-1240-LX, issue the following commands on the PC: #ftp 192.168.3.127 ftp> cd /home ftp> bin ftp> put ./hello ftp> quit #telnet 192.168.3.
EM-1240-LX User’s Manual Getting Started Running “Hello” on the EM-1240-LX To run the Hello program issue the following commands on the EM-1240-LX: # chmod 755 hello #./hello The words “hello world” are printed on the screen. ATTENTION Be sure to calculate the amount of Flash Memory used by the User File System in the Flash ROM.
EM-1240-LX User’s Manual Getting Started Make File Example Code The following Make File example codes are copied from the Hello example on the EM-1240-LX’s CD-ROM. srcdir = . LDFLAGS = -Wl,-elf2flt LIBS = CFLAGS = # Change these if necessary CC = arm-elf-gcc CPP = arm-elf-gcc -E all: hello hello: $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(LIBS) $@.c clean: rm -f $(OBJS) hello core *.
3 Chapter 3 Software Package This chapter includes information about the software that is used with EM-1240-LX Series products.
EM-1240-LX User’s Manual Software Package EM-1240-LX Software Architecture The pre-installed µClinux Operating System used by the EM-1240-LX follows the standard µClinux architecture. This means that programs following the POSIX standard are easily ported to the EM-1240-LX with the GNU Tool Chain provided by www.uClinux.org. In addition to the Standard POSIX API, device drivers for the buzzer and UART for the serial ports are also included.
EM-1240-LX User’s Manual Software Package Flash Context Flash Address Size Access control Boot loader 0 – 0x3ffff 256 K Read ONLY Kernet & Root File System 0x40000– 0x3fffff 4M Read ONLY JFFS2 User Directory 0x400000 – 0x7fffff 4 M – 256 K Read / Write JFFS2 Developers should store their own programs only to partitions /etc, /home, /tmp, and /usr/bin. In addition, executable files should be stored in /usr/bin, as doing so will allow developers to use hotkeys.
EM-1240-LX User’s Manual Software Package EM-1240-LX Software Package bin upkernel passwd -> tinylogin login -> tinylogin tinylogin telnetd snmpd mail sh routed netstat arp chat pppd portmap ntpdate necid eraseall kversion init expand inetd hwclock ftpd ftp mke2fs e2fsck discard dhcpcd cpu busybox boa bf backupfs downramdisk upramdisk dev mtdblock1 mtdr1 mtd1 mtdblock0 mtdr0 mtd0 cum1 cum0 ttyM1 ttyM0 urandom random zero ttypf ttype ttypd ttypc ttypb ttypa ttyp9 ttyp8 ttyp7 ttyp6 ttyp5 ttyp4 ttyp3 ttyp2
EM-1240-LX User’s Manual bin Software Package dev ptyp0 ppp pio rtc ram1 ram0 null kmem mem cua0 console tty 3-5
4 Chapter 4 Configuring the EM-1240-LX In this chapter, we describe how to configure the EM-1240-LX Series products.
EM-1240-LX User’s Manual Configuring the EM-1240-LX Enabling and Disabling Daemons The following daemons are enabled when the EM-1240-LX boots up for the first time. y y y y y SNMP Agent daemon: Telnet Server / Client daemon: Internet Daemons: FTP Server / Client daemon: WWW Server daemon: snmpd telnetd inetd ftpd boa ATTENTION How to enable/disable telnet/ftp server a. b. Edit the file ‘/etc/inetd.
EM-1240-LX User’s Manual Configuring the EM-1240-LX Adding a Web Page Default Home Page address: /home/httpd/index.html You may change the default home page directory by editing the web server’s configuration file, located at: /etc/boa.conf Type the following command to edit the boa.conf file: /etc>vi boa.
EM-1240-LX User’s Manual Configuring the EM-1240-LX Source NAT (SNAT)—changes the first source packet IP address Destination NAT (DNAT)—changes the first destination packet IP address MASQUERADE—a special form for SNAT. If one host can connect to the Internet, then other computers that connect to this host can connect to the Internet when the computer does not have an actual IP address. REDIRECT—a special form of DNAT that re-sends packets to a local host independent of the destination IP address. C.
EM-1240-LX User’s Manual Configuring the EM-1240-LX The EM-1240-LX supports the following sub-modules. Be sure to use the module that matches your application. You must load a module before you can use it. Use the insmod command to load a module.
EM-1240-LX User’s Manual Configuring the EM-1240-LX 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.
EM-1240-LX User’s Manual Configuring the EM-1240-LX Example 5: Drop TCP packets addressed for port 21. # iptables –A INPUT –i eth0 –p tcp --dport 21 –j DROP Example 6: Accept TCP packets from 192.168.0.24 to the EM-1240-LX’s 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 EM-1240-LX’s port 25.
EM-1240-LX User’s Manual Configuring the EM-1240-LX Configuring Dial-in/Dial-out Service Dial-out Service Direct cable connection: y Without username and password, use: />pppd connect ‘chat –v’ /dev/ttyM0 38400 crtscts& y With username and password, use: />pppd connect ‘chat –v’ user xxxxx password xxxxx /dev/ttyM0 38400 crtscts& Connect Using a Modem: y Use: />pppd connect ‘chat –v ATDT CONNECT’ user xxxxx password xxxxx /dev/ttyM0 38400 crtscts& ATTENTION If dial out fails, the pppd con
EM-1240-LX User’s Manual Configuring the EM-1240-LX : Ethernet card connected to ADSL modem, for example, eth0 : User account, for example, moxa@adsl.net : Password for user account To check if PPPOE is successfully connected, use the command: y />ifconfig ppp0 How to Mount a Remote NFS Server Currently, the EM-1240-LX only supports NFS (Network File System) clients. Users can open NFS service on a Linux PC to enable the EM-1240-LX to push data to it.
EM-1240-LX User’s Manual Configuring the EM-1240-LX Upgrading the Kernel The EM-1240-LX kernel is em1240-1.x..bin, which can be downloaded from www.moxa.com. You must first download this file to your PC, and then use Console Terminal or Telnet Console to copy the file to the EM-1240-LX. You can save this file to the EM-1240-LX’s RAM disk, and then upgrade the kernel. The following is a step-by-step example.
EM-1240-LX User’s Manual Configuring the EM-1240-LX Upgrading the Root File System & User Directory The EM-1240-LX uses JFFS2 for the root file system and user directory. By default, the root file system is pre-set to READ only. The EM-1240-LX provides a read/write user’s directory in the JFFS2 file system. By using this user’s directory, the system configuration file and user’s program can be stored on this disk.
EM-1240-LX User’s Manual Configuring the EM-1240-LX User Directory Backup—EM-1240-LX to PC To enable the RAM disk, use the following commands: />upramdisk />cd ramdisk Use the backupfs command to back up the file system. /ramdisk>backupfs /ramdisk/usrdisk-backup The file system will be backed up. Use ftp commands to transfer the usrdisk-backup to the FTP server on the PC. Loading Factory Defaults The easiest way to “Load Factory Defaults” is with the “Upgrade User directory” operation.
EM-1240-LX User’s Manual Configuring the EM-1240-LX Mirroring the Application Program and Configuration For some applications, you may need to “Mirror” (or sometimes “Ghost”) one EM-1240-LX’s user directory, and duplicate it to other EM-1240-LX units. To do this, use the following recommended procedure: 1. Back up the user directory to a PC. (Refer to the previous topic User Directory Backup—EM-1240-LX to a PC.) Hint: /ramdisk>backupfs /ramdisk/ 2.
5 Chapter 5 EM-1240-LX Device API In this chapter, we discuss the Device API for the EM-1240-LX Series.
EM-1240-LX User’s Manual EM-1240-LX Device API RTC (Real-time Clock) The device node is located at /dev/rtc. The EM-1240-LX supports µClinux standard simple RTC control. You must include to use these functions. 1. Function: RTC_RD_TIME int ioctl(fd, RTC_RD_TIME, struct rtc_time *time); Description: Reads time information from RTC. 2. Function: RTC_SET_TIME int ioctl(fd, RTC_SET_TIME, struct rtc_time *time); Description: Sets RTC time. Buzzer The device node is located at /dev/console.
EM-1240-LX User’s Manual EM-1240-LX Device API GPIO GPIO stands for General Purpose I/O. GPIOs are user-programmable, and can be used for either digital input or digital output, since the signals are all in TTL format. Moxa GPIO API Moxa provides an API library with static link for customers using the EM-1220 or EM-1240 (note that dynamic link is not supported). Users can use source code provided by Moxa so that the ioctl() command can be used by the operating system to communicate with drivers.
EM-1240-LX User’s Manual EM-1240-LX Device API int set_gpio_mode(unsigned int pio, int mode) --to configure GPIO ports to be DI ports or DO ports. Input: unsigned int pio - GPIO port number Each GPIO point will be regarded as a port. We support from Port 0 to Port 9 for the EM-1240, and from Port 0 to Port 7 for the EM-1220. int mode 1 represents DI. 0 represents DO. Output: 1 represents high. 0 represents low. Return: < 0 is wrong. = 0 is correct.
EM-1240-LX User’s Manual EM-1240-LX Device API Limits 1. Both the SD card and GPIO share the same signals. To enable the GPIO, the SD card must be disabled, and vice versa. Drivers will not automatically check if the signal is from the SD or GPIO; users must determine where the signal comes from before using the signal. 2. Both moxadevice.h and libmoxalib.a are supported in Tool Chain v1.6 and newer versions. GPIO Library Source Code /* * History: * Date Author * 12-06-2005 Victor Yu. */ #include
EM-1240-LX User’s Manual EM-1240-LX Device API typedef struct gpio_set_struct { int io_number; int mode_data; } gpio_t; /* * To get the GPIO mode now. * Input: unsigned int pio - the GPIO number, from 0 to MAX_GPIO-1 * Output: < 0 - some error * 1 - input * 0 - ouput */ int get_gpio_mode(unsigned int gpio_no) { int fd; gpio_t pset; CHECK_GPIO_NO(gpio_no); fd = open(GPIO_DEVICE_NODE, O_RDWR); if ( fd < 0 ) return GPIO_NODE_ERROR; pset.
EM-1240-LX User’s Manual EM-1240-LX Device API close(fd); return GPIO_ERROR; } close(fd); return pset.mode_data; } /* * To set the GPIO now mode.
EM-1240-LX User’s Manual EM-1240-LX Device API CHECK_GPIO_NO(gpio_no); CHECK_GPIO_DATA(data); fd = open(GPIO_DEVICE_NODE, O_RDWR); if ( fd < 0 ) return GPIO_NODE_ERROR; pset.io_number = gpio_no; pset.
A Appendix A System Commands busybox: µClinux normal command utility collection File manager cp ls ln mount rm chmod chown chgrp sync mv pwd df du mkdir rmdir head tail touch copy file list file make symbolic link file mount and check file system delete file change file owner & group & user change file owner change file group sync file system; save system file buffer to hardware move file display active file directly list active file system space estimate file space usage make new directory delete direc
EM-1240-LX User’s Manual System Commands Network ping route netstat ifconfig tftp telnet ftp iptables-restore iptables iptables-save ping to test network routing table manager display network status set network IP address tftp protocol user interface to TELNET protocol file transfer protocol restore iptables configuration file to network iptables command save recent iptables configuration to file kill killall ps sleep kill process kill process by name report process status suspend command on time dmes
B Appendix B SNMP Agent with MIB II & RS-232 Like Group The EM-1240-LX has a built-in SNMP (Simple Network Management Protocol) agent that supports RFC1317 RS-232 like group and RFC 1213 MIB-II. The following table lists the variable implementation for the EM-1240-LX. The full SNMP object ID of EM-1240-LX is .iso.3.6.1.4.1.8691.12.7112 and .iso.3.6.1.4.1.8691.12.1240. Note: The EM-1240-LX does not support SNMP trap.
EM-1240-LX User’s Manual ip MIB ipForwarding ipDefaultTTL ipInReceives ipInHdrErrors ipInAddrErrors ipForwDatagrams ipInUnknownProtos ipInDiscards ipInDelivers ipOutRequests ipOutDiscards ipOutNoRoutes ipReasmTimeout ipReasmReqds ipReasmFails ipFragOKs ipFragFails ipFragCreates ipAddrTable ipAdEntAddr ipAdEntIfIndex ipAdEntNetMask ipAdEntBcastAddr ipAdEntReasmMaxSize ipRouteTable ipRouteDest ipRouteIfIndex ipRouteMetric1 ipRouteMetric2 ipRouteMetric3 ipRouteMetric4 ipRouteNextHop ipRouteType ipRouteProto ip
EM-1240-LX User’s Manual SNMP Agent with MIB II & RS-232 Like Group snmp MIB snmpInPkts snmpOutPkts snmpInBadVersions snmpInBadCommunityNames snmpInBadCommunityUses snmpInASNParseErrs snmpInTooBigs snmpInNoSuchNames snmpInBadValues snmpInReadOnlys snmpInGenErrs snmpInTotalReqVars snmpInTotalSetVars snmpInGetRequests snmpInGetNexts snmpInSetRequests snmpInGetResponses snmpInTraps snmpOutTooBigs snmpOutNoSuchNames snmpOutBadValues snmpOutGenErrs snmpOutGetRequests snmpOutGetNexts snmpOutSetRequests snmpOutT
C Appendix C EM-1240-LX FAQ FAQ 1 Why can I only use vfork( ),and am not able to use fork( )? Answer 1 μClinux only supports vfork( ). It does not support fork( ). Note that when using vfork( ), the parent process will hang until the child process calls an exec group API, or exits.