W406-LX User’s Manual Second Edition, November 2009 www.moxa.com/product © 2009 Moxa Inc. All rights reserved. Reproduction without permission is prohibited.
W406-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 © 2009 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 Software Architecture .............................................................................................................. 1-2 Journaling Flash File System (JFFS2)....................................................
Chapter 4 Managing Communications ........................................................................4-1 Telnet / FTP ............................................................................................................................. 4-2 DNS ......................................................................................................................................... 4-2 Web Service—Apache .............................................................................................
1 Chapter 1 Introduction The W406-LX is an embedded computer that features 2 software selectable RS-232/422/485 ports, 1 Ethernet port, and quad-band GSM/GPRS/EDGE 900/1800/850/1900 MHz for cellular communication.
W406-LX User’s Manual Introduction Overview The W406-LX embedded computers, which are designed for industrial automation applications, feature 2 RS-232/422/485 serial ports, 1 Ethernet port, 4 digital input channels, 4 digital output channels, 1 USB 2.0 host and SD socket. The DIN-Rail vertical form factor makes it easy to install the W406 embedded computers in small cabinets.
W406-LX User’s Manual Introduction The W406-LX’s built-in Flash ROM is partitioned into Boot Loader, Linux Kernel, Root File System, and User directory partitions. In order to prevent user applications from crashing the Root File System, the W406-LX 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.
W406-LX User’s Manual Introduction Although JFFS2 is a journaling file system, this does not preclude the loss of data. The file system will remain in a consistent state across 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. Additional information about JFFS2 is available at: http://sources.redhat.com/jffs2/jffs2.
2 Chapter 2 Getting Started In this chapter, we explain how to connect the W406-LX, how to turn on the power, how to get started programming, and how to use the W406-LX’s other functions.
W406-LX User’s Manual Getting Started Powering on the W406-LX Connect the SG wire to the shielded contact located in the upper left corner of the W406-LX, and then power on the computer by connecting it to the power adaptor. It takes about 60 seconds for the system to boot up. Once the system is ready, the Ready LED will light up. NOTE After connecting the W406-LX to the power supply, it will take about 60 seconds for the operating system to boot up.
W406-LX User’s Manual Getting Started Once the connection is established, the following window will open. Acquiring the IP Address of the W406-LX As the W406-LX uses the DHCP server to acquire the IP address for network connection, please make sure you have the DHCP server ready. When connecting to the W406-LX with serial console port, use ifconfig eth0 to know the IP address of the W406-LX.
W406-LX User’s Manual Getting Started Please note that when you turn on a computer that is not connected to the local network or there is no DHCP server available, it will take about 60 seconds for the system to perform the booting procedure. Telnet Console When you know the IP address and netmask, then you can use Telnet to connect to the W406-LX’s console utility. To connect to a hub or switch connected to your local LAN, use a straight-through Ethernet cable.
W406-LX User’s Manual Getting Started SSH Console The W406-LX supports an SSH Console to provide users with better security options. Windows Users Click on the link http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html to download PuTTY (free software) to set up an SSH console for the W406-LX in a Windows environment. The following figure shows a simple example of the configuration that is required.
W406-LX User’s Manual NOTE Getting Started SSH provides better security compared to Telnet for accessing the W406-LX’s console utility over the network. Configuring the Ethernet Interface The network settings of the W406-LX can be modified with the Debug Port, or online over the network. Modifying Network Settings with the Serial Console Port In this section, we use the serial console to configure the network settings of the target computer. 1.
W406-LX User’s Manual NOTE Getting Started After changing the IP settings, use the networking restart command to activate the new IP address. Modifying Network Settings by Command IP settings can be activated over the command, but the new settings will not be saved to the flash ROM without modifying the file /etc/network/interfaces. For example, type the command #ifconfig eth0 192.168.1.1 to change the IP address of LAN to 192.168.1.1. USB Port for Expansion The W406 has 1 USB 2.
W406-LX User’s Manual Getting Started Setting Up the Wireless Module Before using the W406, make sure the SIM card is properly installed and the antenna is connected. (Refer to the W406 Hardware User’s Manual for details.) Please note that the SIM card must be installed when the embedded computer is powered off. The LED indicators on the front panel can be used to check the signal strength. A background process “egprsagent” is responsible for this task.
W406-LX User’s Manual Getting Started Verifying the SIM Card Status Use the sim_get_pin_status command to check the SIM card status. Four possible responses may appear: Ready: Your W406 wireless module is ready to work. No SIM card: You need to insert SIM card into the W406, or your SIM card may not be inserted correctly. Need PIN code: You need to enter the correct PIN code. See Entering the PIN code in this section.
W406-LX User’s Manual Getting Started To disable PIN code authentication, use sim_enable_pin-d –p command.
W406-LX User’s Manual Getting Started Changing the PIN Code Use sim_change_pin -o old PIN code –n new PIN code command to change the PIN code. For example, enter sim_input_pin –o 0000 –n 1111 to replace an old PIN code, 0000, with a new one, 1111.
W406-LX User’s Manual Getting Started Unlocking the SIM Card When your SIM has been locked, you will need to enter the PUK code to unlock your SIM card. Use the sim_unlock –p PUK code –n new PIN code command to unluck your card. Please note that when you enter the PUK code, you also need to provide a new PIN code. For example, type sim_unlock –p 80364944 –n 0000. In this case, 80364944 is the PUK code, while 0000 is the new PIN code. Use this new PIN code the next time the W406 starts.
W406-LX User’s Manual Getting Started Connecting to the Internet To create a connection, use the gprs_connect command. For more detailed command syntax, type gprs_connect –h. While connected, you can use the gprs_connection_status command to check the connection status.
W406-LX User’s Manual Getting Started Reconnecting to the Internet When an internet connection has been broken, use the gprs_reconnect –t second command to reconnect to the Internet. For example, enter gprs_reconnect –t 120 to direct the W406 to attempt to reconnect to the Internet every 120 seconds. If you do not provide the time interval, the default value will be 60 seconds. Use the gprs_reconnect –h command for more details.
W406-LX User’s Manual Getting Started Detecting an Internet Connection Error To diagnose a connection problem, use the gprs_diagnose command. This utility will execute a series of steps to check whether or not the configuration is correct. Most connection problems can be indentified with this command.
W406-LX User’s Manual Getting Started Sending and Reading an SMS Message To send an SMS message, use the sms_send_text_msg command. For example, enter sms_send_text_msg –n 0988713219 –t “hello! This is an SMS test.” to send the message “hello! This is an SMS test.” to the phone number 0988693141. To read an SMS message, use the sms_read_text_msg –i command. For example, sms_read_text_msg –i 1, will display the first SMS message.
W406-LX User’s Manual Getting Started Deleting an SMS Message To delete an SMS message, use the sms_remove_msg command. For example, the sms_remove_msg –i 1 command will delete the first SMS message. Test Program—Developing Hello.c In this section, we use the standard “Hello” programming example to illustrate how to develop a program for the W406-LX. In general, program development involves the following seven steps. Step 1: Connect the W406-LX to a Linux PC.
W406-LX User’s Manual Getting Started Installing the Tool Chain (Linux) The Linux Operating System must be pre-installed in the PC before installing the W406-LX GNU Tool Chain. Fedora core or compatible versions are recommended. The Tool Chain requires approximately 1 GB of hard disk space on your PC. The W406-LX Tool Chain software is located on the W406-LX CD.
W406-LX User’s Manual Getting Started Compiling Hello.c The package CD contains several example programs. Here we use hello.c as an example to show you how to compile and run your applications.
3 Chapter 3 Managing Embedded Linux This chapter includes information about version control, deployment, updates, and peripherals. The information in this chapter will be particularly useful when you need to run the same application on several W406-LX units.
W406-LX User’s Manual Managing Embedded Linux System Version Information To determine the hardware capability of your W406-LX, and what kind of software functions are supported, check the version numbers of your W406-LX’s kernel, and user file system. Contact Moxa to determine the hardware version. You will need the Production S/N (Serial Number), which is located on the W406-LX’s bottom label. To check the kernel version, type: #kversion 192.168.3.127 – PuTTY root@Moxa:~# kversion W406-LX version 1.
W406-LX User’s Manual Managing Embedded Linux 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 Rootfs 8.6M 7.8M /dev/root 8.6M 7.8M /dev/ram3 1003.0k 9.0k /dev/ram0 499.0k 18.
W406-LX User’s Manual Managing Embedded Linux 150 Opening data connection for W406-x.x.x.hfm 226 Transfer complete. 13167772 bytes received in 2.17 secs (5925.8 kB/s) ftp> 3. Next, use the upgradehfm command to upgrade the kernel and root file system: #upgradehfm W406-x.x.x.hfm 192.168.3.127 – PuTTY root@Moxa:/mnt/ramdisk# upgradehfm W406-x.x.x.hfm Moxa W406 upgrade firmware utility version 1.0. To check source firmware file context. The source firmware file context is OK.
W406-LX User’s Manual Managing Embedded Linux Type the command “ps” to list all processes currently running. 192.168.3.
W406-LX User’s Manual Managing Embedded Linux The enabled daemons will be available after you reboot the system. 192.168.3.
W406-LX User’s Manual Managing Embedded Linux 192.168.3.127 – PuTTY root@Moxa:/ect/rc.d/rc3.d# ls S19nfs-common S25nfs-user-server S99showreadyled S20snmpd S55ssh S24pcmcia S99rmnologin root@Moxa:/ect/rc.d/rc3.d# ln –s /root/tcps2-release S60tcps2 root@Moxa:/ect/rc.d/rc3.d# ls S19nfs-common S25nfs-user-server S99rmnologin S20snmpd S55ssh S99showreadyled S24pcmcia S60tcps2 root@Moxa:/etc/rc.d/rc3.d# KxxRUNFILE stands for K: start the run file while linux shuts down or halts. xx: a number between 00-99.
W406-LX User’s Manual Managing Embedded Linux The following figure illustrates how to update the system time and set the RTC time. 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 120910002004 Thu Dec 9 10:00:00 CST 2004 root@Moxa:~# hwclock –w root@Moxa:~# date ; hwclock Thu Dec 9 10:01:07 CST 2004 Thu Dec 9 10:01:08 2004 -0.
W406-LX User’s Manual Managing Embedded Linux Updating the Time Automatically In this subsection, we show how to use a shell script to update the time automatically. Example shell script to update the system time periodically #!/bin/sh ntpdate time.nist.gov # You can use the time server’s ip address or domain # name directly. If you use domain name, you must # enable the domain client on the system by updating # /etc/resolv.conf file. hwclock --systohc sleep 100 # Updates every 100 seconds. The min.
W406-LX User’s Manual Managing Embedded Linux STEP5: Enable cron when the system boots up. Add the following line in the file /etc/rc.d/rc.local /etc/init.
4 Chapter 4 Managing Communications In this chapter, we explain how to configure the W406-LX’s various communication functions.
W406-LX User’s Manual Managing Communications Telnet / FTP In addition to supporting Telnet client/server and FTP client/server, the W406-LX 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. Enabling the Telnet/ftp server The following example shows the default content of the file /etc/inetd.conf.
W406-LX User’s Manual Managing Communications 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.
W406-LX User’s Manual Managing Communications To open the default CGI page, type http://192.168.13.23/cgi-bin/test-cgi in your browser’s address box. NOTE The CGI function is enabled by default. If you want to disable the function, modify the file /etc/apache/conf/httpd.conf. When you develop your own CGI application, make sure your CGI file is executable. 192.168.3.127 – PuTTY root@Moxa:/home/httpd/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 ..
W406-LX User’s Manual Managing Communications Install PHP for Apache Web Server This embedded computer supports the PHP option. However, since the PHP file is 3 MB, it is not installed by default. To install it yourself, first make sure there is enough free space (at least 3 MB) on your embedded flash ROM). Step 1: Type ‘upramdisk’ to get the free space ram disk to save the package. Check that you have enough free space. 192.168.3.
W406-LX User’s Manual Managing Communications 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.
W406-LX User’s Manual Managing Communications The following figure shows the IPTABLES hierarchy.
W406-LX User’s Manual Managing Communications The W406-LX supports the following sub-modules. Be sure to use the module that matches your application. ip_queue ip_tables ipt_CLUSTERIP ipt_ECN ipt_LOG ipt_MASQUERADE ipt_NETMAP NOTE ipt_REDIRECT ipt_REJECT ipt_SAME ipt_TOS ipt_TTL ipt_ULOG ipt_addrtype ipt_ah ipt_ecn ipt_iprange ipt_owner ipt_recent ipt_tos ipt_ttl iptable_filter iptable_mangle iptable_nat iptable_raw The W406-LX does NOT support IPv6 and ipchains.
W406-LX User’s Manual Managing Communications 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. Observe and erase chain rules Usage: # iptables [-t tables] [-L] [-n] -t tables: Table to manipulate (default: ‘filter’); example: nat or filter. -L [chain]: ListList all rules in selected chains.
W406-LX User’s Manual Managing Communications Append or delete rules: 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.
W406-LX User’s Manual Managing Communications NAT Example The IP address of LAN1 is changed to 192.168.3.127 (you will need to load the module ipt_MASQUERADE): IP/Netmask: 192.168.3.100/24 Gateway: 192.168.3.127 PC1 (Linux or Windows) LAN1 LAN1: 192.168.3.127/24 Embedded Computer LAN2: 192.168.4.127/24 LAN2 PC2 (Linux or Windows) IP/Netmask: 192.168.4.100/24 Gateway: 192.168.4.127 NAT Area / Private IP 1. 2. 3. 4. 5. 6. 7. 8.
W406-LX User’s Manual Managing Communications echo “1” > /proc/sys/net/ipv4/ip_forward /bin/iptables -F /bin/iptables -X /bin/iptables -Z /bin/iptables -F -t nat /bin/iptables -X -t nat /bin/iptables -Z -t nat /bin/iptables -P INPUT ACCEPT /bin/iptables -P OUTPUT ACCEPT /bin/iptables -P FORWARD ACCEPT /bin/iptables -t nat -P PREROUTING ACCEPT /bin/iptables -t nat -P POSTROUTING ACCEPT /bin/iptables -t nat -P OUTPUT ACCEPT # Step 3. Enable IP masquerade.
W406-LX User’s Manual Managing Communications Double quotes—don’t wait for a prompt, but proceed with the following instead (note that you must include a space before the second quotation mark). ATDT5551212 Dial the modem, and proceed with the following. CONNECT Wait for an answer. “ “ Send a return (null text followed by the usual return) ogin: username word: password Log in with username and password. Refer to the chat man page, chat.8, for more information about the chat utility.
W406-LX User’s Manual Managing Communications How to check the connection Once you’ve set up a PPP connection, there are some steps you can take to test the connection. First, type: /sbin/ifconfig (The file ifconfig may be located elsewhere, depending on your distribution.) You should be able to see all the network interfaces that are UP. ppp0 should be one of them, and you should recognize the first IP address as your own, and the “P-t-P address” (or point-to-point address) the address of your server.
W406-LX User’s Manual Managing Communications Setting up a Machine for Incoming PPP Connections This first example applies to using a modem, and requiring authorization with a username and password. pppd/dev/ttyM0 115200 crtscts modem 192.168.16.1:192.168.16.2 login auth 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.
W406-LX User’s Manual 4. Managing Communications Edit the file /etc/ppp/pap-secrets and add the following: “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. 5.
W406-LX User’s Manual Managing Communications 6. Add the following files: /etc/ppp/options.eth0. The file context is shown below: 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 8. Use the following command to create a pppoe connection: pppd eth0 9.
W406-LX User’s Manual Managing Communications NFS (Network File System) The Network File System (NFS) is used to mount a disk partition on a remote machine, as if it were on a local hard drive, allowing fast, seamless sharing of files across a network. NFS allows users to develop applications for the W406-LX, without worrying about the amount of disk space that will be available. The W406-LX supports NFS protocol for client. NOTE Click on the following links for more information about NFS: http://www.
W406-LX User’s Manual Managing Communications SNMP The W406-LX has built-in SNMP V1 (Simple Network Management Protocol) agent software. It supports RFC1317 RS-232 like group and RFC 1213 MIB-II. 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 Æ W406-LX does NOT support SNMP trap. Package Management—ipkg ipkg is a very lightweight package management system.
W406-LX User’s Manual Managing Communications 192.168.3.120 – Putty Installing libmysqlclient5 (5.1.23) to root... Stopping web server: apache. ipkg: extract_archive: /CONTROL/: Read-only file system ipkg: /CONTROL/postinst: No such file or directory ipkg: /CONTROL/postrm: No such file or directory ipkg: /CONTROL/prerm: No such file or directory ipkg: /CONTROL/preinst: No such file or directory ipkg: /CONTROL/control: No such file or directory Configuring libmysqlclient5 Starting web server: apache.
W406-LX User’s Manual Managing Communications Setup 1: Ethernet Bridging for Private Networks on Different Subnets 1. Set up four machines, as shown in the following diagram. Host A local net OpenVPN A LAN1: 192.168.2.173 LAN1: 192.168.2.171 Internet LAN2: 192.168.8.173 LAN1: 192.168.8.174 LAN1: 192.168.4.172 LAN2: 192.168.4.174 Host B local net OpenVPN B Host A (B) represents one of the machines that belongs to OpenVPN A (B).
W406-LX User’s Manual Managing Communications 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 if [ “$FOUND” = “no” ]; then modprobe $mname fi } start() { ifcfg_vpn if [ ! \( -d “/dev/net” \) ]; then mkdir
W406-LX User’s Manual Managing Communications ifconfig tap${i} 0.0.0.0 promisc up i=`expr $i + 1` if [ $i -ge $maxtap ]; then break fi done # null ip address of internal interface ifconfig $iface 0.0.0.0 promisc up # 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.
W406-LX User’s Manual 3. Managing Communications Create a configuration file named A-tap0-br.conf and an executable script file named A-tap0-br.sh on OpenVPN A. # 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/A-tap0-br.sh #----------------------------------Start-----------------------------#!/bin/sh # value after “-net” is the subnet behind the remote peer route add -net 192.168.4.
W406-LX User’s Manual Managing Communications 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.
W406-LX User’s Manual Managing Communications Setup 3: Routed IP 1. Set up the four machines as shown in the following diagram: Host A local net OpenVPN A LAN1: 192.168.2.173 LAN1: 192.168.2.171 Internet LAN2: 192.168.8.173 LAN1: 192.168.8.174 LAN1: 192.168.4.172 LAN2: 192.168.4.174 Host B 2. OpenVPN B local net Create a configuration file named “A-tun.conf” and an executable script file named “A-tun.sh”. # point to the peer remote 192.168.8.174 dev tun secret /etc/openvpn/secrouter.
W406-LX User’s Manual Managing Communications 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 Destination Gateway Genmsk 192.168.4.174 * 255.255.
5 Chapter 5 Development Tool Chains This chapter describes how to install a tool chain in the host computer that you use to develop your applications. In addition, the process of performing cross-platform development and debugging are also introduced. For clarity, the W406-LX embedded computer is called a target computer.
W406-LX Linux User’s Manual Development Tool Chains Linux Tool Chain The Linux tool chain contains a suite of cross compilers and other tools, as well as the libraries and header files that are necessary to compile your applications. These tool chain components must be installed in your host computer (PC) running Linux. We have confirmed that the following Linux distributions can be used to install the tool chain.
W406-LX Linux User’s Manual Development Tool Chains The following cross compiler tools are provided with a prefix “arm-linux-“.
6 Chapter 6 Programmer’s Guide This chapter includes important information for programmers.
W406-LX Linux User’s Manual Programmer’s Guide Flash Memory Map Partition sizes are hard coded into the kernel binary. To change the partition sizes, you will need to rebuild the kernel. The flash memory map is shown in the following table. Address 0x00000000 – 0x00060000 0x00060000 – 0x00260000 0x00260000 – 0x00b00000 0x00b00000 – 0x01000000 Size 384 KB 2 MB 8.
W406-LX Linux User’s Manual Programmer’s Guide Buzzer The device node is located at /dev/console. The W406-LX supports Linux standard buzzer control, with the W406-LX’s buzzer running at a fixed frequency of 100 Hz. You must include . Function: KDMKTONE ioctl(fd, KDMKTONE, unsigned int arg); Description: The buzzer’s behavior is determined by the argument arg. The “high word” part of the argument gives the length of time the buzzer will sound, and the “low word” part gives the frequency.
W406-LX Linux User’s Manual Programmer’s Guide Example to set the baudrate #include #include struct termios term; int fd, speed; fd = open(“/dev/ttyM0”, O_RDWR); tcgetattr(fd, &term); term.c_cflag &= ~(CBAUD | CBAUDEX); term.c_cflag |= B4000000; tcsetattr(fd, TCSANOW, &term); speed = 500000; ioctl(fd, MOXA_SET_SPECIAL_BAUD_RATE, &speed); Example to get the baudrate #include #include
W406-LX Linux User’s Manual Programmer’s Guide 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 by the function call, set_din_event( ).
W406-LX Linux User’s Manual Programmer’s Guide int set_din_event(int diport, void (*func)(int diport), int mode, long int duration) 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.
W406-LX Linux User’s Manual Programmer’s Guide (1): from high to low DIN_EVENT_LOW_TO_HIGH(0): from low to high DIN_EVENT_CLEAR(-1): clear this event duration The value of duration should be 0 or 40 <= duration <= 3600000 milliseconds. Return: reference the error code. Special Note Don’t forget to link the library libmoxalib 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.
W406-LX Linux User’s Manual Programmer’s Guide 2. get now data. \n\ 3. set low to high event \n\ 4. clear event \n\ 5. set high data. \n\ 6. set low data. \n\ 7. quit \n\ 8.
W406-LX Linux User’s Manual Programmer’s Guide scanf("%d", &i); retval=set_dout_state(i, 1); } else if ( i == 6 ) { // set low data printf("Please keyin the DOUT number : "); scanf("%d", &i); retval=set_dout_state(i, 0); } else if ( i == 7 ) { // quit break; } else if ( i == 8 ) { // show event and duration printf("Event:\n"); for ( j=0; j
W406-LX Linux User’s Manual Programmer’s Guide case DIO_ERROR_DURATION: printf("DIO error duratoin\n"); case DIO_ERROR_DURATION_20MS: printf("DIO error! The duratoin is not a multiple of 20 ms\n"); break; } } return 0; } DIO Program Make File Example FNAME=tdio CC=arm-linux-gcc STRIP=arm-linux-strip release: $(CC) -o $(FNAME) $(FNAME).c -lmoxalib -lpthread $(STRIP) -s $(FNAME) debug: $(CC) -DDEBUG -o $(FNAME)-dbg $(FNAME).cxx -lmoxalib -lpthread clean: /bin/rm -f $(FNAME) $(FNAME)-dbg *.
W406-LX Linux User’s Manual Programmer’s Guide Closes a cellular modem handle. void cellular_modem_close(unsigned int fd); Inputs: the handle Return Values: None Remark: You must release the cellular modem handle resource if you don’t need to use cellular modem APIs later. Sends an AT command to a cellular modem and waits for a reply.
W406-LX Linux User’s Manual Programmer’s Guide Aborts a GPRS connection. int cellular_modem_gprs_abort_connection(unsigned int fd); Inputs: the cellular modem Return Values: 0 on success, otherwise, the function fails Remark: Checks the status of a GPRS connection. int cellular_modem_gprs_check_connection_status(unsigned int fd); Inputs: the cellular modem Return Values: 0 indictes the connection is on.
W406-LX Linux User’s Manual Programmer’s Guide Gets the storage base of SIM messages. int cellular_modem_sms_get_storage_base(unsigned int fd); Inputs: the cellular modem Return Values: 0: on SIM card, 1: on modem module, 2: on both, otherwise, the function fails Remark: Gets the number of stored messages allowed out of the maximum space.
W406-LX Linux User’s Manual Programmer’s Guide Receives an indexed SMS message.
W406-LX Linux User’s Manual Programmer’s Guide When the SIM card status is set to PIN (2), this function retrieves the available PIN code attempt count. If the SIM card status is set to PUK (3), this function gets the available PUK code attempt count. int cellular_modem_sim_get_pin_attempt_count(unsigned int fd); Inputs: the cellular modem Return Values: The attempted count left of PIN/PUK code authentication.
W406-LX Linux User’s Manual Programmer’s Guide When the SIM card status is ready (0) and the PIN code is enabled, this function assigns a PIN code to the SIM card.
W406-LX Linux User’s Manual Programmer’s Guide Sets the UART interface. BOOL uart_setmode(int port, int mode); Inputs: the serial port number. the interface parameter. 0 : RS-232 1 : RS485-2W 2 : RS422 3 : RS485-4W Return Values: TRUE indicates success, FALSE indicates failed. Remark: For example, user uart_getmode(2) to retrieve the interface of COM2: DIO Opens a DIO handle for later use. HANDLE mxdio_init(void); Inputs: none Return Values: pointer to a DIO handle. Return 0 on failure.
W406-LX Linux User’s Manual Programmer’s Guide Gets one of the DIN inputs. int mxdio_get_din(HANDLE hDIO, unsigned int port); Inputs: the DIO handle the port index, from 0 to 3 mapping to DI0~DI3 Return Values: 1 indicates HIGH, 0 indicates LOW Remark: Gets one of DOUT outputs.
W406-LX Linux User’s Manual Programmer’s Guide Buzzer Turns on the buzzer. void mxbeep_on(void); Inputs: None Return Values: None Remark: Turns off the buzzer. void mxbeep_off(void); Inputs: None Return Values: None Remark: A. Installing the “libsms” library To use this library, you must have the toolchain installed. The library will be installed during the toolchain installation process. Refer to the Installing the Tool Chain (Linux) section. B.
7 Chapter 7 Software Lock “Software Lock” is an innovative technology developed by the Moxa engineering force. It can be adopted by a system integrator or developer to protect his applications from being copied. An applicaion is compiled into a binary format bound to the embedded computer and the operating system (OS) that the application runs on. As long as one obtains it from the computer, he/she can install it into the same hardware and the same operating system.
A Appendix A System Commands Linux normal command utility collection File manager 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.
W406-LX Linux User’s Manual System Commands Process 1. 2. kill ps kill process display now running process 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.