SlideShare a Scribd company logo
1 of 4
Download to read offline
MOXA White Paper Sample Code for Embedded Applications
Released on May 1, 2008
Copyright © 2008 Moxa Inc. All rights reserved.
Moxa manufactures one of the world’s leading brands of device networking solutions. Products include industrial
embedded computers, industrial Ethernet switches, serial device servers, multiport serial boards, embedded
device servers, and remote I/O products. Our products are key components of many networking applications,
including industrial automation, manufacturing, POS, and medical treatment facilities.
How to contact Moxa
Tel: 1-714-528-6777
Fax: 1-714-528-6778
Web: www.moxa.com
Email: info@moxa.com
This document was produced by the Moxa Technical Writing
Center (TWC). Please send your comments or suggestions
about this or other Moxa documents to twc@moxa.com.
Using Sample Code to Develop Embedded Applications
Saves Time and Keeps Bugs at a Minimum
Dr. CF Lin, Director of Software Development
cf.lin@moxa.com
It is often the case that software developers build application
programs based on sample code or code from previous
projects. Building on your own experience or the experience of
others is common practice in the software industry, since doing
so allows developers to deliver products faster, and also helps
guarantee that the source code is relatively bug-free. In
particular, when developers are faced with the challenge of
writing code for applications new to the programmer, relying on
sample code to get started goes a long way to keeping
frustrations at a minimum.
Sample code is a great educational tool for young software
developers who are just getting started with embedded
application programming. One of the biggest benefits of using
sample code is that programmers can quickly grasp the full
functionality of their applications, and in this way gain the
confidence needed to complete their project.
Sample code is a good reference for developers who are
already familiar with application programming. For a particular
application, the code can be used to demonstrate different
angles of implementation, and this kind of experience sharing
provides a good focal point for mutual learning.
Sample code also delivers a more precise means of sharing
technology between vendors and applications developers. In
MOXA White Paper Sample Code for Embedded Applications
Copyright © 2008 Moxa Inc. Page 2 of 4
particular, vendors often create proprietary software interfaces
for accessing special functionalities provided by hardware
components. Since these types of functionalities are not in the
public domain, providing relevant sample code may be the only
way for application developers to understand the functions,
after which they can proceed to write their own code.
Serial Port Programming Example
Perhaps the most widely used sample code provided by Moxa is
for serial communication applications. The code provides an
interface for accessing Moxa’s advanced ASIC chip used for
serial communication. This chipset follows the UART 16550
standard, but outperforms the standard in terms of
extensibility and data throughput. The chipset also supports a
wide range of baudrates up to 921.6 Kbps, including those not
used in standard Windows and Linux programming. To access
these special baudrates, a Linux user can utilize the following
code segment.
int mserial_port_set_special_baud_rate( int fd, unsigned int speed)
{
struct termios termios;
tcgetattr(fd, &termios);
termios.c_cflag &= ~(CBAUD | CBAUDEX);
/* a rate not one of them defined in the table */
termios.c_cflag |= B4000000;
return ioctl(fd, UC_SET_SPECIAL_BAUD_RATE, &speed)? -1:0;
}
Another useful function in the serial chipset arsenal is selecting
which serial interface to use for a 3-in-1 serial port. Selecting
either the RS-232, RS-422, or RS-485 interface can be done
using the following sample program.
Int mserial_port_set_interface(int fd, int iface)
{
if (iface != RS232_MODE && iface != RS485_2WIRE_MODE &&
iface != RS422_MODE && iface != RS485_4WIRE_MODE )
{
printf("not a supported interfacen");
return -1;
}
if (ioctl(fd, MOXA_SET_OP_MODE, &iface) != 0)
MOXA White Paper Sample Code for Embedded Applications
Copyright © 2008 Moxa Inc. Page 3 of 4
{
printf("fail to set serial port interfacen");
return -2;
}
return 0;
}
The Complexities of Socket Programming
Socket programming may seem easy enough for developers
who design client-server applications, but sophisticated
programming skill is required to create a truly stable
client-server application. Unfortunately, many programmers
start with a simple sample program, but quickly run into
trouble as their client-server code increases in complexity.
Socket programs for embedded applications require a very
high degree of stability and can be quite complicated. Such
programs not only involve reading and writing data to and from
socket ports, but also require maintaining a well-designed
structure for managing multiple clients, handling client
connection and reconnection, taking care of non-blocking read
and write operations, and other tasks.
The degree of reliability required for a client-server system can
be extremely high, and inexperienced developers often have
trouble creating such systems. In fact, based on the author’s
own experience, new programmers often invest a great deal of
effort before fully understanding where the problems lie.
Proceeding in this manner can take a long time, and also
increase your development costs to unacceptable levels.
Well-structured sample code helps application developers
minimize the difficulty of creating a stable system, and
provides a good way for programmers to develop a better
understanding of socket programming. The bottom line is that
you can reduce your development costs by using reliable
sample code.
MOXA White Paper Sample Code for Embedded Applications
Copyright © 2008 Moxa Inc. Page 4 of 4
Creating a Watchdog for Embedded Applications
Since embedded system applications are often left unattended
for long periods of time, most embedded applications
implement a watchdog function to ensure that the computer
system can reboot automatically when the system hangs
unexpectedly. Implementing such a function for RISC-based
computers is usually system-dependent, and for this reason,
using sample code to demonstrate how to use such a function
can be extremely valuable.
Summary
Software developers should always be on the lookout for ways
to ensure that products are developed quickly, but at the same
time are also reliable and cost-effective. A simple yet very
effective way of doing this is to rely on sample code when
getting started with a project. Using sample code not only
speeds up product development, but also helps ensure that
code is efficient and bug-free.
Embedded applications that can benefit from using sample
code include client-server programs, watchdogs, LCDs, and
DIOs, to name but a few.
NOTE: Moxa provides sample code for a wide range of embedded applications. For details,
please contact the author, Dr. CF Lin, at support@moxa.com.
Disclaimer
This document is provided for information purposes only, and the contents hereof are subject to change without
notice. This document is not warranted to be error-free, nor subject to any other warranties or conditions,
whether expressed orally or implied by law, including implied warranties and conditions of merchantability, or
fitness for a particular purpose. We specifically disclaim any liability with respect to this document and no
contractual obligations are formed either directly or indirectly by this document. This document may not be
reproduced or transmitted in any form for any purpose, without our prior written permission.

More Related Content

What's hot

[ITAS.VN]CxSuite Enterprise Edition
[ITAS.VN]CxSuite Enterprise Edition[ITAS.VN]CxSuite Enterprise Edition
[ITAS.VN]CxSuite Enterprise EditionITAS VIETNAM
 
MicroEJ software solution for IoT and embedded devices
MicroEJ software solution for IoT and embedded devicesMicroEJ software solution for IoT and embedded devices
MicroEJ software solution for IoT and embedded devicesMicroEJ
 
A taxonomy of obfuscating transformations
A taxonomy of obfuscating transformationsA taxonomy of obfuscating transformations
A taxonomy of obfuscating transformationsemanuele_nl
 
Bird binary interpretation using runtime disassembly
Bird binary interpretation using runtime disassemblyBird binary interpretation using runtime disassembly
Bird binary interpretation using runtime disassemblyUltraUploader
 
Vulnerabilities on the Wire: Mitigations for Insecure ICS Device Communication
Vulnerabilities on the Wire: Mitigations for Insecure ICS Device CommunicationVulnerabilities on the Wire: Mitigations for Insecure ICS Device Communication
Vulnerabilities on the Wire: Mitigations for Insecure ICS Device CommunicationMuhammad FAHAD
 
SivaBorra
SivaBorraSivaBorra
SivaBorraSiva Borra
 
IRJET- Development of Uncrackable Software
IRJET- Development of Uncrackable SoftwareIRJET- Development of Uncrackable Software
IRJET- Development of Uncrackable SoftwareIRJET Journal
 
CVAmit Bhawsar
CVAmit BhawsarCVAmit Bhawsar
CVAmit BhawsarAmit Bhawsar
 
Pattern based software patent
Pattern based software patentPattern based software patent
Pattern based software patentiaemedu
 
Pattern based software patent
Pattern based software patentPattern based software patent
Pattern based software patentIAEME Publication
 
Strategies for Web Application Security
Strategies for Web Application SecurityStrategies for Web Application Security
Strategies for Web Application SecurityOpSource
 
Test Automation Processes Log4j Vulnerability
Test Automation Processes Log4j VulnerabilityTest Automation Processes Log4j Vulnerability
Test Automation Processes Log4j VulnerabilityaNumak & Company
 
Tau Technologies intro
Tau Technologies introTau Technologies intro
Tau Technologies introtau-technologies
 

What's hot (17)

[ITAS.VN]CxSuite Enterprise Edition
[ITAS.VN]CxSuite Enterprise Edition[ITAS.VN]CxSuite Enterprise Edition
[ITAS.VN]CxSuite Enterprise Edition
 
MicroEJ software solution for IoT and embedded devices
MicroEJ software solution for IoT and embedded devicesMicroEJ software solution for IoT and embedded devices
MicroEJ software solution for IoT and embedded devices
 
A taxonomy of obfuscating transformations
A taxonomy of obfuscating transformationsA taxonomy of obfuscating transformations
A taxonomy of obfuscating transformations
 
Resume
ResumeResume
Resume
 
Project
ProjectProject
Project
 
Bird binary interpretation using runtime disassembly
Bird binary interpretation using runtime disassemblyBird binary interpretation using runtime disassembly
Bird binary interpretation using runtime disassembly
 
Vulnerabilities on the Wire: Mitigations for Insecure ICS Device Communication
Vulnerabilities on the Wire: Mitigations for Insecure ICS Device CommunicationVulnerabilities on the Wire: Mitigations for Insecure ICS Device Communication
Vulnerabilities on the Wire: Mitigations for Insecure ICS Device Communication
 
kavita_resume_3
kavita_resume_3kavita_resume_3
kavita_resume_3
 
SivaBorra
SivaBorraSivaBorra
SivaBorra
 
IRJET- Development of Uncrackable Software
IRJET- Development of Uncrackable SoftwareIRJET- Development of Uncrackable Software
IRJET- Development of Uncrackable Software
 
WebRTC for Beginners Webinar Slides
WebRTC for Beginners Webinar SlidesWebRTC for Beginners Webinar Slides
WebRTC for Beginners Webinar Slides
 
CVAmit Bhawsar
CVAmit BhawsarCVAmit Bhawsar
CVAmit Bhawsar
 
Pattern based software patent
Pattern based software patentPattern based software patent
Pattern based software patent
 
Pattern based software patent
Pattern based software patentPattern based software patent
Pattern based software patent
 
Strategies for Web Application Security
Strategies for Web Application SecurityStrategies for Web Application Security
Strategies for Web Application Security
 
Test Automation Processes Log4j Vulnerability
Test Automation Processes Log4j VulnerabilityTest Automation Processes Log4j Vulnerability
Test Automation Processes Log4j Vulnerability
 
Tau Technologies intro
Tau Technologies introTau Technologies intro
Tau Technologies intro
 

Similar to Moxa white paper---Using Sample Code to Develop Embedded Applications

Atmel - Next-Generation IDE: Maximizing IP Reuse [WHITE PAPER]
Atmel - Next-Generation IDE: Maximizing IP Reuse [WHITE PAPER]Atmel - Next-Generation IDE: Maximizing IP Reuse [WHITE PAPER]
Atmel - Next-Generation IDE: Maximizing IP Reuse [WHITE PAPER]Atmel Corporation
 
137.gsm, fprs ,keypad_based_atm_security_(doc)
137.gsm, fprs ,keypad_based_atm_security_(doc)137.gsm, fprs ,keypad_based_atm_security_(doc)
137.gsm, fprs ,keypad_based_atm_security_(doc)Karteek Irukulla
 
Eurotech M2M Building Blocks and Multi-Service Gateway Approach
Eurotech M2M Building Blocks and Multi-Service Gateway ApproachEurotech M2M Building Blocks and Multi-Service Gateway Approach
Eurotech M2M Building Blocks and Multi-Service Gateway ApproachEurotech
 
IRJET- Obfuscation: Maze of Code
IRJET- Obfuscation: Maze of CodeIRJET- Obfuscation: Maze of Code
IRJET- Obfuscation: Maze of CodeIRJET Journal
 
The Benefits of POSIX
The Benefits of POSIXThe Benefits of POSIX
The Benefits of POSIXWhitfield Thomas
 
Sarah CV 2016 External
Sarah CV 2016 ExternalSarah CV 2016 External
Sarah CV 2016 ExternalSarah Thomas
 
Ankit sarin
Ankit sarinAnkit sarin
Ankit sarinsarinsahab
 
MicroEJ, the OS for IoT
MicroEJ, the OS for IoTMicroEJ, the OS for IoT
MicroEJ, the OS for IoTMicroEJ
 
MicroEJ OS for IoT devices
MicroEJ OS for IoT devicesMicroEJ OS for IoT devices
MicroEJ OS for IoT devicescharlotte75009
 
Resume_Appaji
Resume_AppajiResume_Appaji
Resume_AppajiAppaji K
 
IRJET- Implementation of Web Enabled Notice Board using SOC
IRJET- Implementation of Web Enabled Notice Board using SOCIRJET- Implementation of Web Enabled Notice Board using SOC
IRJET- Implementation of Web Enabled Notice Board using SOCIRJET Journal
 
A CASE STUDY ON EMBEDDED SYSTEM SOFTWARE STACK LAYERS
A CASE STUDY ON EMBEDDED SYSTEM SOFTWARE STACK LAYERS A CASE STUDY ON EMBEDDED SYSTEM SOFTWARE STACK LAYERS
A CASE STUDY ON EMBEDDED SYSTEM SOFTWARE STACK LAYERS MOHAMMED FURQHAN
 
Performance of State-of-the-Art Cryptography on ARM-based Microprocessors
Performance of State-of-the-Art Cryptography on ARM-based MicroprocessorsPerformance of State-of-the-Art Cryptography on ARM-based Microprocessors
Performance of State-of-the-Art Cryptography on ARM-based MicroprocessorsHannes Tschofenig
 
tranning synopsis(java programming).pdf
tranning synopsis(java programming).pdftranning synopsis(java programming).pdf
tranning synopsis(java programming).pdfsumitgiri32
 
Challenges of integrating code signing with CI.pdf
Challenges of integrating code signing with CI.pdfChallenges of integrating code signing with CI.pdf
Challenges of integrating code signing with CI.pdfSavinder Puri
 
Dusun Gateway Hardware For Developer White Paper.pdf
Dusun Gateway Hardware For Developer White Paper.pdfDusun Gateway Hardware For Developer White Paper.pdf
Dusun Gateway Hardware For Developer White Paper.pdfYongxiaoCheng
 
Anti key logging and real-time encrypting software | keystrokes encrypting so...
Anti key logging and real-time encrypting software | keystrokes encrypting so...Anti key logging and real-time encrypting software | keystrokes encrypting so...
Anti key logging and real-time encrypting software | keystrokes encrypting so...Mike Taylor
 

Similar to Moxa white paper---Using Sample Code to Develop Embedded Applications (20)

Atmel - Next-Generation IDE: Maximizing IP Reuse [WHITE PAPER]
Atmel - Next-Generation IDE: Maximizing IP Reuse [WHITE PAPER]Atmel - Next-Generation IDE: Maximizing IP Reuse [WHITE PAPER]
Atmel - Next-Generation IDE: Maximizing IP Reuse [WHITE PAPER]
 
137.gsm, fprs ,keypad_based_atm_security_(doc)
137.gsm, fprs ,keypad_based_atm_security_(doc)137.gsm, fprs ,keypad_based_atm_security_(doc)
137.gsm, fprs ,keypad_based_atm_security_(doc)
 
Eurotech M2M Building Blocks and Multi-Service Gateway Approach
Eurotech M2M Building Blocks and Multi-Service Gateway ApproachEurotech M2M Building Blocks and Multi-Service Gateway Approach
Eurotech M2M Building Blocks and Multi-Service Gateway Approach
 
IRJET- Obfuscation: Maze of Code
IRJET- Obfuscation: Maze of CodeIRJET- Obfuscation: Maze of Code
IRJET- Obfuscation: Maze of Code
 
The Benefits of POSIX
The Benefits of POSIXThe Benefits of POSIX
The Benefits of POSIX
 
Sarah CV 2016 External
Sarah CV 2016 ExternalSarah CV 2016 External
Sarah CV 2016 External
 
Ankit sarin
Ankit sarinAnkit sarin
Ankit sarin
 
MicroEJ, the OS for IoT
MicroEJ, the OS for IoTMicroEJ, the OS for IoT
MicroEJ, the OS for IoT
 
MicroEJ OS for IoT devices
MicroEJ OS for IoT devicesMicroEJ OS for IoT devices
MicroEJ OS for IoT devices
 
Resume_Appaji
Resume_AppajiResume_Appaji
Resume_Appaji
 
IRJET- Implementation of Web Enabled Notice Board using SOC
IRJET- Implementation of Web Enabled Notice Board using SOCIRJET- Implementation of Web Enabled Notice Board using SOC
IRJET- Implementation of Web Enabled Notice Board using SOC
 
A CASE STUDY ON EMBEDDED SYSTEM SOFTWARE STACK LAYERS
A CASE STUDY ON EMBEDDED SYSTEM SOFTWARE STACK LAYERS A CASE STUDY ON EMBEDDED SYSTEM SOFTWARE STACK LAYERS
A CASE STUDY ON EMBEDDED SYSTEM SOFTWARE STACK LAYERS
 
Sa*ple
Sa*pleSa*ple
Sa*ple
 
Performance of State-of-the-Art Cryptography on ARM-based Microprocessors
Performance of State-of-the-Art Cryptography on ARM-based MicroprocessorsPerformance of State-of-the-Art Cryptography on ARM-based Microprocessors
Performance of State-of-the-Art Cryptography on ARM-based Microprocessors
 
Middleware Technologies ppt
Middleware Technologies pptMiddleware Technologies ppt
Middleware Technologies ppt
 
tranning synopsis(java programming).pdf
tranning synopsis(java programming).pdftranning synopsis(java programming).pdf
tranning synopsis(java programming).pdf
 
Challenges of integrating code signing with CI.pdf
Challenges of integrating code signing with CI.pdfChallenges of integrating code signing with CI.pdf
Challenges of integrating code signing with CI.pdf
 
OPC -Connectivity using Java
OPC -Connectivity using JavaOPC -Connectivity using Java
OPC -Connectivity using Java
 
Dusun Gateway Hardware For Developer White Paper.pdf
Dusun Gateway Hardware For Developer White Paper.pdfDusun Gateway Hardware For Developer White Paper.pdf
Dusun Gateway Hardware For Developer White Paper.pdf
 
Anti key logging and real-time encrypting software | keystrokes encrypting so...
Anti key logging and real-time encrypting software | keystrokes encrypting so...Anti key logging and real-time encrypting software | keystrokes encrypting so...
Anti key logging and real-time encrypting software | keystrokes encrypting so...
 

More from Digital River

UC-8100 Wireless Computers
UC-8100 Wireless ComputersUC-8100 Wireless Computers
UC-8100 Wireless ComputersDigital River
 
Moxa white paper---Using Embedded Computers to Manage Your Solar Power System
Moxa white paper---Using Embedded Computers to Manage Your Solar Power SystemMoxa white paper---Using Embedded Computers to Manage Your Solar Power System
Moxa white paper---Using Embedded Computers to Manage Your Solar Power SystemDigital River
 
Moxa white paper---Embedded Computing for Industrial Embedded Computing for I...
Moxa white paper---Embedded Computing for Industrial Embedded Computing for I...Moxa white paper---Embedded Computing for Industrial Embedded Computing for I...
Moxa white paper---Embedded Computing for Industrial Embedded Computing for I...Digital River
 
Moxa Tech White Paper - Choosing An Embedded Operating System
Moxa Tech White Paper - Choosing An Embedded Operating SystemMoxa Tech White Paper - Choosing An Embedded Operating System
Moxa Tech White Paper - Choosing An Embedded Operating SystemDigital River
 
The Next Link in IPC Evolution
The Next Link in IPC EvolutionThe Next Link in IPC Evolution
The Next Link in IPC EvolutionDigital River
 
A Primer on Obtaining IEC 61850-3 Certification for Embedded Computers
A Primer on Obtaining IEC 61850-3 Certification for Embedded ComputersA Primer on Obtaining IEC 61850-3 Certification for Embedded Computers
A Primer on Obtaining IEC 61850-3 Certification for Embedded ComputersDigital River
 

More from Digital River (6)

UC-8100 Wireless Computers
UC-8100 Wireless ComputersUC-8100 Wireless Computers
UC-8100 Wireless Computers
 
Moxa white paper---Using Embedded Computers to Manage Your Solar Power System
Moxa white paper---Using Embedded Computers to Manage Your Solar Power SystemMoxa white paper---Using Embedded Computers to Manage Your Solar Power System
Moxa white paper---Using Embedded Computers to Manage Your Solar Power System
 
Moxa white paper---Embedded Computing for Industrial Embedded Computing for I...
Moxa white paper---Embedded Computing for Industrial Embedded Computing for I...Moxa white paper---Embedded Computing for Industrial Embedded Computing for I...
Moxa white paper---Embedded Computing for Industrial Embedded Computing for I...
 
Moxa Tech White Paper - Choosing An Embedded Operating System
Moxa Tech White Paper - Choosing An Embedded Operating SystemMoxa Tech White Paper - Choosing An Embedded Operating System
Moxa Tech White Paper - Choosing An Embedded Operating System
 
The Next Link in IPC Evolution
The Next Link in IPC EvolutionThe Next Link in IPC Evolution
The Next Link in IPC Evolution
 
A Primer on Obtaining IEC 61850-3 Certification for Embedded Computers
A Primer on Obtaining IEC 61850-3 Certification for Embedded ComputersA Primer on Obtaining IEC 61850-3 Certification for Embedded Computers
A Primer on Obtaining IEC 61850-3 Certification for Embedded Computers
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Moxa white paper---Using Sample Code to Develop Embedded Applications

  • 1. MOXA White Paper Sample Code for Embedded Applications Released on May 1, 2008 Copyright © 2008 Moxa Inc. All rights reserved. Moxa manufactures one of the world’s leading brands of device networking solutions. Products include industrial embedded computers, industrial Ethernet switches, serial device servers, multiport serial boards, embedded device servers, and remote I/O products. Our products are key components of many networking applications, including industrial automation, manufacturing, POS, and medical treatment facilities. How to contact Moxa Tel: 1-714-528-6777 Fax: 1-714-528-6778 Web: www.moxa.com Email: info@moxa.com This document was produced by the Moxa Technical Writing Center (TWC). Please send your comments or suggestions about this or other Moxa documents to twc@moxa.com. Using Sample Code to Develop Embedded Applications Saves Time and Keeps Bugs at a Minimum Dr. CF Lin, Director of Software Development cf.lin@moxa.com It is often the case that software developers build application programs based on sample code or code from previous projects. Building on your own experience or the experience of others is common practice in the software industry, since doing so allows developers to deliver products faster, and also helps guarantee that the source code is relatively bug-free. In particular, when developers are faced with the challenge of writing code for applications new to the programmer, relying on sample code to get started goes a long way to keeping frustrations at a minimum. Sample code is a great educational tool for young software developers who are just getting started with embedded application programming. One of the biggest benefits of using sample code is that programmers can quickly grasp the full functionality of their applications, and in this way gain the confidence needed to complete their project. Sample code is a good reference for developers who are already familiar with application programming. For a particular application, the code can be used to demonstrate different angles of implementation, and this kind of experience sharing provides a good focal point for mutual learning. Sample code also delivers a more precise means of sharing technology between vendors and applications developers. In
  • 2. MOXA White Paper Sample Code for Embedded Applications Copyright © 2008 Moxa Inc. Page 2 of 4 particular, vendors often create proprietary software interfaces for accessing special functionalities provided by hardware components. Since these types of functionalities are not in the public domain, providing relevant sample code may be the only way for application developers to understand the functions, after which they can proceed to write their own code. Serial Port Programming Example Perhaps the most widely used sample code provided by Moxa is for serial communication applications. The code provides an interface for accessing Moxa’s advanced ASIC chip used for serial communication. This chipset follows the UART 16550 standard, but outperforms the standard in terms of extensibility and data throughput. The chipset also supports a wide range of baudrates up to 921.6 Kbps, including those not used in standard Windows and Linux programming. To access these special baudrates, a Linux user can utilize the following code segment. int mserial_port_set_special_baud_rate( int fd, unsigned int speed) { struct termios termios; tcgetattr(fd, &termios); termios.c_cflag &= ~(CBAUD | CBAUDEX); /* a rate not one of them defined in the table */ termios.c_cflag |= B4000000; return ioctl(fd, UC_SET_SPECIAL_BAUD_RATE, &speed)? -1:0; } Another useful function in the serial chipset arsenal is selecting which serial interface to use for a 3-in-1 serial port. Selecting either the RS-232, RS-422, or RS-485 interface can be done using the following sample program. Int mserial_port_set_interface(int fd, int iface) { if (iface != RS232_MODE && iface != RS485_2WIRE_MODE && iface != RS422_MODE && iface != RS485_4WIRE_MODE ) { printf("not a supported interfacen"); return -1; } if (ioctl(fd, MOXA_SET_OP_MODE, &iface) != 0)
  • 3. MOXA White Paper Sample Code for Embedded Applications Copyright © 2008 Moxa Inc. Page 3 of 4 { printf("fail to set serial port interfacen"); return -2; } return 0; } The Complexities of Socket Programming Socket programming may seem easy enough for developers who design client-server applications, but sophisticated programming skill is required to create a truly stable client-server application. Unfortunately, many programmers start with a simple sample program, but quickly run into trouble as their client-server code increases in complexity. Socket programs for embedded applications require a very high degree of stability and can be quite complicated. Such programs not only involve reading and writing data to and from socket ports, but also require maintaining a well-designed structure for managing multiple clients, handling client connection and reconnection, taking care of non-blocking read and write operations, and other tasks. The degree of reliability required for a client-server system can be extremely high, and inexperienced developers often have trouble creating such systems. In fact, based on the author’s own experience, new programmers often invest a great deal of effort before fully understanding where the problems lie. Proceeding in this manner can take a long time, and also increase your development costs to unacceptable levels. Well-structured sample code helps application developers minimize the difficulty of creating a stable system, and provides a good way for programmers to develop a better understanding of socket programming. The bottom line is that you can reduce your development costs by using reliable sample code.
  • 4. MOXA White Paper Sample Code for Embedded Applications Copyright © 2008 Moxa Inc. Page 4 of 4 Creating a Watchdog for Embedded Applications Since embedded system applications are often left unattended for long periods of time, most embedded applications implement a watchdog function to ensure that the computer system can reboot automatically when the system hangs unexpectedly. Implementing such a function for RISC-based computers is usually system-dependent, and for this reason, using sample code to demonstrate how to use such a function can be extremely valuable. Summary Software developers should always be on the lookout for ways to ensure that products are developed quickly, but at the same time are also reliable and cost-effective. A simple yet very effective way of doing this is to rely on sample code when getting started with a project. Using sample code not only speeds up product development, but also helps ensure that code is efficient and bug-free. Embedded applications that can benefit from using sample code include client-server programs, watchdogs, LCDs, and DIOs, to name but a few. NOTE: Moxa provides sample code for a wide range of embedded applications. For details, please contact the author, Dr. CF Lin, at support@moxa.com. Disclaimer This document is provided for information purposes only, and the contents hereof are subject to change without notice. This document is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or implied by law, including implied warranties and conditions of merchantability, or fitness for a particular purpose. We specifically disclaim any liability with respect to this document and no contractual obligations are formed either directly or indirectly by this document. This document may not be reproduced or transmitted in any form for any purpose, without our prior written permission.