C/C++
Secondary develop Elastel Gateways by C/C++
Elastel gateways are built on an Open Linux system, allowing developers to create custom applications using C and C++.
All Elastel models support compiling and running native applications, and most devices come pre-installed with toolchains or support cross-compilation.
Typical use cases like:
- High-performance data processing and device control
- Serial, network, and protocol communication (e.g., Modbus RTU/TCP, MQTT, TCP/UDP)
- Real-time control and edge logic processing
- Integration with low-level device drivers or GPIO access
1. Supported Models
Series | Model | Compilation Method |
---|---|---|
Industrial Raspberry Pi Series | EG500, EG410, ElastBox400 | Native Compilation (built-in gcc) |
ARM-based IIoT Gateway Series | EG324 (Ubuntu OS) | Native Compilation (built-in gcc) |
EG324 Lite, EC212, EC211 | Cross Compilation (using toolchain) |
✅ The EG324 model runs Ubuntu OS with gcc pre-installed, you can compile directly on it.
✅ EG324 Lite, EC212, and EC211 series do not include a compilation environment and require cross-compiling on a PC before uploading to the gateway.
2. Cross-Compilation Environment Setup
The below example uses "admin" user on Ubuntu 20.04 PC to setup the cross-compilation environment for EG324 Lite:
-
Contact with Elastel support team to download the toolchain, and extract to
/home/admin
on your Ubuntu PC:tar -xzvf eg324l-aarch64-none-linux-gnu.tar.gz -C /home/admin
-
Add the toolchain path to
~/.bashrc
and apply:export PATH=$PATH:/home/admin/eg324l-aarch64-none-linux-gnu/bin
source ~/.bashrc -
Write a test program
hello.c
and compile it using the cross-compiler:aarch64-none-linux-gnu-gcc hello.c -o hello
3. Programming Example: LED Control (ledtest)
The following program controls the system LED blinking via /dev/led
:
#include <stdio.h>
#include <linux/types.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
char buf;
#define LED_ON buf = '1'; write(fd, &buf, 1) // Turn LED on
#define LED_OFF buf = '0'; write(fd, &buf, 1) // Turn LED off
int main(int argc, char *argv[])
{
int fd;
fd = open("/dev/led", O_RDWR);
if (fd < 0)
{
printf("Failed to open led device");
exit(1);
}
while (1)
{
LED_ON;
usleep(500000); // Delay 500 ms
LED_OFF;
usleep(500000); // Delay 500 ms
}
exit(0);
}
3.1. Compile command:
gcc ledtest.c -o ledtest ## Compile on device directly
# OR
aarch64-none-linux-gnu-gcc ledtest.c -o ledtest ## Cross Comile on PC
3.2 Upload and run on the gateway
Method 1: Upload via Web Terminal (Check ElastPro for more details)
-
Open browser at
http://192.168.1.1
→ System → Terminal → Upload Files -
Move the uploaded file to persistent path:
sudo mv /tmp/terminal/ledtest /home/admin/
Method 2: Using MobaXterm / Xshell
- Drag and drop via SFTP to
/home/admin/
Run the program:
cd /home/admin
chmod +x ledtest
./ledtest
The LED will blink every 0.5 seconds, indicating successful control.
4. Recommendations Practices
- Use built-in interfaces (e.g., serial ports, GPIO, LED) for development
- Configure
/etc/init.d/rcS
for startup service or usecrontab
for scheduled runs - Deploy programs under
/home/admin
to avoid temporary directories - Add error handling and logging mechanisms for production use
5. Appendix Tables
EG324 Peripheral Resource | Device Interface Name |
---|---|
COM1 | /dev/ttyAMA0 |
COM2 | /dev/ttyAMA1 |
COM3 | /dev/ttyAMA2 |
COM4 | /dev/ttyAMA3 |
SYS LED Indicator | /dev/led |
SYS2 LED Indicator | /dev/led2 |
Buzzer | /dev/buzzer |
Ethernet Port 1 | eth0 |
Ethernet Port 2 | eth1 |
For other models, please contact Elastel support or refer to models hardware manuals for Peripheral Interface tables.
- Official Website: https://www.elastel.com
- Support Email:
support@elastel.com