IA260/IA261/IA262/EM-2260 Linux User’s Manual First Edition, January 2009 www.moxa.com/product © 2009 Moxa Inc. All rights reserved. Reproduction without permission is prohibited.
IA260/IA261/IA262/EM-2260 Linux 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)....................................................
SNMP .................................................................................................................................... 4-19 OpenVPN............................................................................................................................... 4-19 Chapter 5 Development Tool Chains ...........................................................................5-1 Linux Tool Chain .................................................................................................
1 Chapter 1 Introduction The Moxa IA260/IA261/IA262/EM-2260 computers are RISC-based ready-to-run embedded computers. Available features include two or four RS-232/422/485 serial ports, two 10/100 Mbps Ethernet port, CF socket for storage expansion, VGA output, two CAN bus ports (IA262 only) and USB host making the IA260/IA261/IA262/EM-2260 ideal for your embedded applications.
IA260-261-262 EM-2260 LX User’s Manual Introduction Overview The IA260/IA261/IA262/EM-2260 embedded computers, which are designed for industrial automation applications, feature 2 or 4 RS-232/422/485 serial ports, 2 CAN bus ports (only for the IA262), dual Ethernet ports, 8 digital input channels, 8 digital output channels, VGA output and CF socket. The computers come in a compact, IP30 protected, industrial-strength rugged chassis.
IA260-261-262 EM-2260 LX User’s Manual Introduction The IA260/IA261/IA262/EM-2260’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 IA260/IA261/IA262/EM-2260 uses a specially designed Root File System with Protected Configuration for emergency use.
IA260-261-262 EM-2260 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.
2 Chapter 2 Getting Started In this chapter, we explain how to connect the IA260/IA261/IA262/EM-2260, how to turn on the power, how to get started programming, and how to use the IA260/IA261/IA262/EM-2260’s other functions.
IA260-261-262 EM-2260 LX User’s Manual Getting Started Powering on the IA260/IA261/IA262/EM-2260 Connect the SG wire to the shielded contact located in the upper left corner of the IA260/IA261/IA262/EM-2260, 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.
IA260-261-262 EM-2260 LX User’s Manual Getting Started Once the connection is established, the following window will open. Telnet Console If you know at least one of the two IP addresses and netmasks, then you can use Telnet to connect to the IA260/IA261/IA262/EM-2260’s console utility. The default IP address and Netmask for each of the two ports are given below: LAN 1 LAN 2 Default IP Address 192.168.3.127 192.168.4.127 Netmask 255.255.255.0 255.255.255.
IA260-261-262 EM-2260 LX User’s Manual Getting Started You can proceed with configuring the network settings of the target computer when you reach the bash command shell. Configuration instructions are given in the next section. ATTENTION Debug Port Reminder Remember to choose VT100 as the terminal type. Use the cable CBL-4PINDB9F-100, which comes with the IA260/IA261/IA262/EM-2260, to connect to the serial console port.
IA260-261-262 EM-2260 LX User’s Manual Getting Started Linux Users From a Linux machine, use the “ssh” command to access the IA260/IA261/IA262/EM-2260’s console utility via SSH. #ssh 192.168.3.127 Select yes to complete the connection. [root@bee_notebook root]# ssh 192.168.3.127 The authenticity of host ‘192.168.3.127 (192.168.3.127)’ can’t be established. RSA key fingerprint is 8b:ee:ff:84:41:25:fc:cd:2a:f2:92:8f:cb:1f:6b:2f.
IA260-261-262 EM-2260 LX User’s Manual Getting Started VGA Console You can connect VGA port to a LCD monitor with VGA interface. Then you connect a keyboard with USB interface to USB port. You will see a login request on the LCD monitor. To log in, type the Login name and password as requested.
IA260-261-262 EM-2260 LX User’s Manual 3. Getting Started 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 NOTE After changing the IP settings, use the networking restart command to activate the new IP address.
IA260-261-262 EM-2260 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 IA260/IA261/IA262/EM-2260 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 IA260/IA261/IA262/EM-2260 Tool Chain software is located on the IA260/IA261/IA262/EM-2260 CD.
IA260-261-262 EM-2260 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 IA260/IA261/IA262/EM-2260 units.
IA260-261-262 EM-2260 LX User’s Manual Managing Embedded Linux System Version Information To determine the hardware capability of your IA260/IA261/IA262/EM-2260, and what kind of software functions are supported, check the version numbers of your IA260/IA261/IA262/EM-2260’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 IA260/IA261/IA262/EM-2260’s bottom label.
IA260-261-262 EM-2260 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 Available Use% /dev/mtdblock2 8.0M 6.0M 2.0M /dev/ram0 499.0k 16.
IA260-261-262 EM-2260 LX User’s Manual Managing Embedded Linux 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.
IA260-261-262 EM-2260 LX User’s Manual Managing Embedded Linux Loading Factory Defaults To load the factory default settings, you must press the reset-to-default button for more than 5 seconds. All files in the /home & /etc directories will be deleted. Note that while pressing the reset-to-default button, the Ready LED will blink three times, and then turn off. It takes about one minute for the factory defaults to fully load.
IA260-261-262 EM-2260 LX User’s Manual Managing Embedded Linux To run a private daemon, you can edit the file rc.local, as follows: #cd /etc/rc.d #vi rc.local 192.168.3.127 – PuTTY root@Moxa:~# cd /etc/rc.d root@Moxa:/etc/rc.d# vi rc.local Next, use vi to open your application script. We use the example program tcps2-release, and put it to run in the background. 192.168.3.
IA260-261-262 EM-2260 LX User’s Manual Managing Embedded Linux Setting the Run-Level In this section, we outline the steps you should take to set the Linux run-level and execute requests. Use the following command to enable or disable settings: 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:/etc/rc.d/rc3.d# #cd /etc/rc.d/init.
IA260-261-262 EM-2260 LX User’s Manual Managing Embedded Linux Adjusting the System Time Setting the Time Manually The IA260/IA261/IA262/EM-2260 has two time settings. One is the system time, and the other is the RTC (Real Time Clock) time kept by the IA260/IA261/IA262/EM-2260’s hardware. Use the #date command to query the current system time or set a new system time. Use #hwclock to query the current RTC time or set a new RTC time.
IA260-261-262 EM-2260 LX User’s Manual Managing Embedded Linux NTP Client The IA260/IA261/IA262/EM-2260 has a built-in NTP (Network Time Protocol) client that is used to initialize a time request to a remote NTP server. Use #ntpdate 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 root@Moxa:~# date ; hwclock Sat Jan 1 00:00:36 CST 2000 Sat Jan 1 00:00:37 2000 -0.
IA260-261-262 EM-2260 LX User’s Manual Managing Embedded Linux Cron—Daemon to Execute Scheduled Commands Start Cron from the directory /etc/rc.d/rc.local. It will return immediately, so you don’t need to start it with ‘&’ to run in the background. 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.
4 Chapter 4 Managing Communications In this chapter, we explain how to configure the IA260/IA261/IA262/EM-2260’s various communication functions.
IA260-261-262 EM-2260 LX User’s Manual Managing Communications Telnet / FTP In addition to supporting Telnet client/server and FTP client/server, the IA260/IA261/IA262/EM-2260 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.
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 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 .
IA260-261-262 EM-2260 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: Check that you have enough free space 192.168.3.127 – PuTTY root@Moxa:/bin# df -h Filesystem Size /dev/mtdblock2 8.0M /dev/ram0 499.0k /dev/mtdblock3 6.0M /dev/mtdblock3 6.
IA260-261-262 EM-2260 LX User’s Manual Managing Communications If you want to uninstall PHP, follow steps 2 to 4 but select the uninstall option.
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 LX User’s Manual Managing Communications The following figure shows the IPTABLES hierarchy.
IA260-261-262 EM-2260 LX User’s Manual Managing Communications The IA260/IA261/IA262/EM-2260 supports the following sub-modules. Be sure to use the module that matches your application.
IA260-261-262 EM-2260 LX User’s Manual Managing Communications 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.
IA260-261-262 EM-2260 LX User’s Manual Managing Communications Examples: Example 1: Accept all packets from lo interface. # iptables –A INPUT –i lo –j ACCEPT Example 2: Accept TCP packets from 192.168.0.1. # iptables –A INPUT –i eth0 –p tcp –s 192.168.0.1 –j ACCEPT Example 3: Accept TCP packets from Class C network 192.168.1.0/24. # iptables –A INPUT –i eth0 –p tcp –s 192.168.1.0/24 –j ACCEPT Example 4: Drop TCP packets from 192.168.1.25. # iptables –A INPUT –i eth0 –p tcp –s 192.168.1.
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 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. 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.
IA260-261-262 EM-2260 LX User’s Manual Managing Communications 6. 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 7. Use the following command to create a pppoe connection: pppd eth0 The eth0 is what is connected to the ADSL modem LAN port. The example above uses LAN1.
IA260-261-262 EM-2260 LX User’s Manual Managing Communications 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. To send an email message, use the ‘smtpclient’ utility, which uses SMTP protocol. Type #smtpclient –help to see the help message. Example: smtpclient –s test –f sender@company.
IA260-261-262 EM-2260 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).
IA260-261-262 EM-2260 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”
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 LX User’s Manual 6. Managing Communications To create an indirect connection to Host B from Host A, you need to 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, you need to 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.
IA260-261-262 EM-2260 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.
IA260-261-262 EM-2260 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.
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 IA260/IA261/IA262/EM-2260 embedded computer is called a target computer.
IA260/IA261/IA262/EM-2260 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.
IA260/IA261/IA262/EM-2260 Linux User’s Manual Development Tool Chains The following cross compiler tools are provided: ar Manages archives (static libraries) as Assembler c++, g++ C++ compiler cpp C preprocessor gcc C compiler gdb Debugger ld Linker nm Lists symbols from object files objcopy Copies and translates object files objdump Displays information about object files ranlib Generates indexes to archives (static libraries) readelf Displays information about ELF files size Lis
6 Chapter 6 Programmer’s Guide This chapter includes important information for programmers.
IA260/IA261/IA262/EM-2260 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 – 0x0005FFFF 0x00040000 – 0x002FFFFF 0x00300000 – 0x00FFFFFF 0x01000000 – 0x01FFFFFF Size 384 KB 2.
IA260/IA261/IA262/EM-2260 Linux User’s Manual Programmer’s Guide Buzzer The device node is located at /dev/console. The IA260/IA261/IA262/EM-2260 supports Linux standard buzzer control, with the IA260/IA261/IA262/EM-2260’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.
IA260/IA261/IA262/EM-2260 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
IA260/IA261/IA262/EM-2260 Linux User’s Manual Programmer’s Guide MoxaCAN Programming Guide 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.
IA260/IA261/IA262/EM-2260 Linux User’s Manual unsigned char unsigned char unsigned char Programmer’s Guide byte6; byte7; byte8; } byte; } can_data_u; typedef struct user_frame_struct { int id; int info; // RTR & extend ID flag #define USER_RTR BIT(0) #define USER_EXTEND_ID BIT(1) int data_length; can_data_u data; } user_frame_t; // ioctl command code #define MOXACAN_IOCTL_SET_BAUD_RATE 0x100 #define MOXACAN_IOCTL_GET_BAUD_RATE 0x101 #endif // _MOXACAN_IOCTL_H Then we can include this header for CAN pro
IA260/IA261/IA262/EM-2260 Linux User’s Manual Programmer’s Guide 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
IA260/IA261/IA262/EM-2260 Linux User’s Manual Programmer’s Guide $(STRIP) $(TARGET)-release $(TARGET1)-release clean: rm -f *.o $(TARGET)-debug $(TARGET)-release $(TARGET1)-debug $(TARGET1)-release 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.
IA260/IA261/IA262/EM-2260 Linux User’s Manual Programmer’s Guide Description: To get the DOUT port state. Input: int doport - get the current state of which DOUT port. int *state - save the current state. Output: state - DIO_HIGH (1) for high, DIO_LOW (0) for low. Return: reference the error code. 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.
IA260/IA261/IA262/EM-2260 Linux User’s Manual Programmer’s Guide int get_din_event(int diport, int *mode, long int *duration) Description: To retrieve the DIN event configuration, including mode (DIN_EVENT_HIGH_TO_LOW or DIN_EVENT_LOW_TO_HIGH), and the value of “duration.” Input: int diport - which DIN port you want to retrieve. - The port whose din event setting we wish to retrieve int *mode - save which event is set. unsigned long *duration - the duration of the DIN port is kept in high or low state.
IA260/IA261/IA262/EM-2260 Linux User’s Manual Programmer’s Guide } 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 ) { printf("\nSelect a number of menu, other key to exit. \n\ 1. set high to low event \n\ 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.
IA260/IA261/IA262/EM-2260 Linux User’s Manual Programmer’s Guide } else if ( i == 3 ) { // set low to high event printf("Please keyin the DIN number : "); scanf("%d", &i); printf("Please input the DIN duration, this minimun value must be over %d :", MIN_DURATION); scanf("%lu", &duration); retval = set_din_event(i, lowtohighevent, DIN_EVENT_LOW_TO_HIGH, duration); } else if ( i == 4 ) { // clear event printf("Please keyin the DIN number : "); scanf("%d", &i); retval=set_din_event(i, NULL, DIN_EVENT_CLEAR,
IA260/IA261/IA262/EM-2260 Linux User’s Manual Programmer’s Guide printf("Select error, please select again !\n"); } switch(retval) { case DIO_ERROR_PORT: printf("DIO error port\n"); break; case DIO_ERROR_MODE: printf("DIO error mode\n"); break; case DIO_ERROR_CONTROL: printf("DIO error control\n"); break; 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 Exampl
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.
IA260/IA261/IA262/EM-2260 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.