ATOP ABLELinkTM Serial Server GW21x Series Software Development Kit
ATOP ABLELinkTM Serial Server GW21x Series Software Development Kit
Programming Guide
Version 1.61
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Revision History
2003/10/20: Created
2004/05/14: Update ComConfig(), add mark and space parity.
2006/07/31: Update SetNetworkType(), using 4 to configure as ad-hoc mode, but not 3.
2006/11/28: Update the description of return value of GetSerialData().
2006/11/28: Remove ReadMacEEPROM() and WriteMacEEPROM(), because there are more user
friendly functions can be used. e.g. GetLocalIpAddr(), SetLocalIpAddr(),
GetLocalNetmask(), SetLocalNetmask(),..etc .
2006/12/21: Add SetDefaultKeyProc() to provide a customized default key process.
Add Read_ApState(), Getnewporttype(), Setnewporttype(), Setnewporttype2()
2007/02/13: Remove Figure 1.2 GW21x-MAXI Front View. because it is GW21S-256 front view.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Contents
1. Introduction....................................................................................................................................8
1.1 Packaging...................................................................................................................................8
1.2 Product Description ...................................................................................................................8
2. Installation ......................................................................................................................................9
4 Advance Course.............................................................................................................................18
5. API Overview................................................................................................................................20
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
udp_close().................................................................................................................................51
udp_receive() .............................................................................................................................51
udp_receiveX()...........................................................................................................................52
udp_send()..................................................................................................................................53
udp_reset() .................................................................................................................................54
GetLocalIPAddr().......................................................................................................................54
GetLocalEthAddr() ....................................................................................................................55
GetDefaultGateway() .................................................................................................................55
GetLocalNetmask()....................................................................................................................56
GetHostName() ..........................................................................................................................56
GetDhcp()...................................................................................................................................57
GetConnectStatus() ....................................................................................................................57
SetLocalIPAddr() .......................................................................................................................59
SetDefaultGateway()..................................................................................................................60
SetLocalNetmask().....................................................................................................................60
SetHostName()...........................................................................................................................61
6.5 Memory Functions ...................................................................................................................61
EraseSector()..............................................................................................................................61
ProgOneByte() ...........................................................................................................................62
ProgString()................................................................................................................................63
ReadEEPROM().........................................................................................................................64
WriteEEPROM()........................................................................................................................64
6.6 Watch Dog Timer Functions.....................................................................................................65
WatchDogCtrl()..........................................................................................................................65
ClrWatchDogTime()...................................................................................................................65
SetupWatchDogTime()...............................................................................................................66
6.7 Advanced Serial Port API (in comapi.obj) ..............................................................................66
Com_Config() ............................................................................................................................66
Com_GetBuf() ...........................................................................................................................67
Com_PutBuf()............................................................................................................................67
Com_ClearRxQue() ...................................................................................................................68
Com_ClearTxQue() ...................................................................................................................68
Com_TxQueIsEmpty() ..............................................................................................................69
Com_DTR_Active()...................................................................................................................69
Com_RTS_Active() ...................................................................................................................70
Com_DSR_Status()....................................................................................................................70
Com_CTS_Status() ....................................................................................................................70
Com_RI_Status() .......................................................................................................................71
Com_DCD_Status() ...................................................................................................................71
6.8 Digital Input and Digital Output Functions .........................................................................71
SetIOMode() ..............................................................................................................................71
GetIOMode()..............................................................................................................................72
SetOutState() ..............................................................................................................................72
GetInState()................................................................................................................................72
ReadDigitalInput() .....................................................................................................................73
SetupRelayOutput() ...................................................................................................................73
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
1. Introduction
1.1 Packaging
GW21x-MAXI ABLELinkTM Embedded Serial Server x 1.
Product CD containing Software Development Kit (SDK).
A DOS-like development toolkit is provided for developing and downloading applications from a PC on
the network to the Serial Server through Ethernet. With the built-in TCP/IP engine, the Serial Server can
then communicate local area network directly. In versatile applications, it can function as a gateway
between field devices and cell controller. By using the RS-232/RS-485 ports, it functions as a gateway
between field bus and Ethernet.
The development toolkit is ATOP ABLELinkTM Embedded Serial Server SDK. It contains a set of API
library, sample programs, development utilities, a download utility and a configuration utility. You can
develop an application program in a PC-based environment. After you develop the application program,
you can download the application program to the Serial Server. Then the Serial Server can work as you
wish.
The Serial Server Software Development Kit (SDK) is a PC-based software package for developing
specific applications on the Serial Server. There are two important types of applications.
The application that handles the TCP/IP communication protocol and data exchange between the
Serial Server and a host computer.
The application that handles the RS-232/RS-485 communication protocol and data exchange
between the Serial Server and field devices.
The GW21x-MAXI is a generic term for ATOP Embedded ABLELinkTM Serial Servers. About detailed
hardware information please refer to each model’s user manual. This document only describes how to
develop an application been run in GW21x-MAXI.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
2. Installation
2.1 Development Environment
The application program of the Serial Server is developed in the PC environment. After the application
program is developed and ready, you can download it to the Serial Server. The Serial Server with the
specific application program will be ready the next time the power is turned on.
During application development stage, you may simulate the application program in the PC environment.
If the simulation is OK, you can compile and link the application again for the Serial Server and then
download the application program to the Serial Server to perform test on it.
Note:
1. These compilers have been tested and found fully compatible with the ATOP ABLELinkTM Serial
Server. The final version is MSVC 1.52.
2. For debugging and simulation purpose. Please refer to section 4.1 for more details.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
CD C:\GW21S2\NEWLIB <ENTER>
Edit “MEMU.BAT” to select MSC6.0,MSC7.0,or later and model.
Edit “MAKEFILE” to set the 'SRC' field to the correct path name of MSC library.
MEMU <ENTER>
COPY C:\GW21S2\NEWLIB\SSILCE.LIB C:\GW21S2\LIB
Step 3:Installation OK
You can now start creating your applications based on SDK sample program.
Note:
The host (PC) AP can use the standard MSC library, but the ABLELinkTM Serial Server AP can
only use the rebuilt MSC library resides for example in the “C:\GW21S2\NEWLIB” directory.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
3. Development Description
3.1 AP development flow
Before developing an application program, please install Microsoft C 6.0 or above (16 bits complier)
and GW21x-MAXI SDK. For more information, you can refer chapter 2.
The process flow of developing an application program is as following:
AP
C.ASM
COMPILER
LINK
AP
USERLOC.CMD .EXE
EXE2HEX
AP
.OMF
XOH86
AP
.HEX
DOWNLOAD
to
GW21S-512
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
following:
2. Append the SDK \BIN directory to the system environment parameter: PATH. Then you can
use SDK utilities in any directory.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
After you have generated the user application programs in .exe format and before downloading them to
the Serial Server, please do the following:
1. Find the memory location of the user application program .exe file:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
The Serial Server kernel does not support dynamic locating function. You can run a user
application program .exe file in the DOS system directly, but you cannot do it in the Serial
Server. During development stage of Serial Server, it is necessary to locate the code and data
segment of the user application program (.exe file) before downloading it to the Serial Server.
After generating the user AP .exe format, you must use the locating tool to locate the .exe file to
a specific memory location. The .OMF file will then be generated.
The user application program memory location is specified in the “userloc.cmd” file as follow.
(Following data is for 512 K flash ROM and more than 256K SRAM.)
AP code segment = 0x8000, data segment = 0x1000
Note:
Please don’t change the context of the “userloc.cmd” unless you wish to download multiple APs to
the Serial Server. However, this is not recommended.
The ABLELinkTM Serial Server kernel will get the processing control immediately after the Serial Server
boots up, and the kernel program tries to transfer the control right to the user application program located
in the memory address of 0x8000 if the user application program was found. otherwise the kernel
program will set the Serial Server to the listen state to wait for a user application program to be
downloaded.
You may short the JP1 (in main board) to prevent the user application program from running. This
function is particularly used in the situation that you download a wrong firmware causing the
GW21x-MAXI system down and the correct application program firmware cannot be downloaded.
For JP1 location information, please refer to Figure 1.1 GW21x-MAXI Front View for details.
Please note that when the GW21x-MAXI powers on, you will see the RUN LED blinking twice. This is
happened before “System Initialization”. After “System Initialization” the RUN LED will blink twice
again. The time interval is about 1 seconds.
Note: After ‘System Initialization’, ‘User AP ok’ and ‘Enable User AP’ the RUN LED will all blink twice.
Because the time intervals between them are too short, we cannot identify each other but maybe
only one.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Power On
2
1
RUN-LED
Blinking twice
End of
No Timeout ? No
System Downloading ?
Initialization
Yes
RUN-LED Yes
Blinking twice 1
Programming
Flash memory
User AP
No
OK ?
RUN-LED
1
Blinking thrice
Enable
No
User AP ?
Yes
1
RUN-LED
Blinking twice
Upon downloading
Upon downloading,
,
Jump to IDLE LOOP DAP will suspend
GW21S-512 will suspend
User AP (WAIT DOWNLOADING) anything and
Anything,and GOTO 2
(ENDLESS LOOP) GOTO 2
RUN-LED RUN-LED
Always On Always Blinking
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
4 Advance Course
4.1 Simulation on PC
4.1.1 Simulation Introduction
It’s not necessary to download the target application programs to the Serial Server immediately after
writing the application programs & drivers, Instead, you can conduct a preliminary functional test on the
PC to verify their integrities with the system including program flow, RS-232/RS-485 communication
handling, TCP/IP connection handling with host computer, message handling between field equipment
and host, and etc. Once the simulation is done, you can download your application programs to the Serial
Server.
Please note that if you are sending/receiving data through the API, the Serial Server kernel will
resolve the differences. If you are using the H/W interrupt technique to send/receive data, you will
need to resolve the differences by yourself.
RS-232 Registers
PC Normal.
Serial Server The ‘Out1’ bit of MCR (Modem Control Register) is used to control the
COM LED.
DOS-dependent functions
PC Fully supported.
Serial Server Only support following functions:
SetIntrVector( ), GetIntrVector( ) and GetVersion( ).
BIOS-dependent functions
PC Fully supported.
Serial Server Only support followings:
INT10H: Video, Audio I/O and Run LED functions. (This is like
INT10H of DOS)
INT14H: Serial I/O functions. (This is like INT14H of DOS)
INT1CH: Software timer interrupt (every 55 ms). (This is like INT1CH
of DOS)
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Each downloaded section must be arranged into the multiplication of a segment (64K bytes).
The starting address of a segment can only be 0x8000:0, 0x9000:0, 0xA000:0, 0xB000:0,
0xC000:0, 0xD000:0.
Download one section at a time.
For example, you will do the following when downloading multiple application programs.
Note:
1. The reasonable value of code segment is from 0x8000 to 0xD000.
2. The reasonable value of data segment is 0x1000.
3. The code and data segments cannot be overlapped.
4. By editing the ‘userloc.cmd’ file, you can change the code segment and data segment value
as you wish.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
5. API Overview
The Serial Server SDK supports many basic C-function calls for your application development. All of the
function calls are implemented by ISR (Interrupt Service Routine) and can be divided into the following
groups:
These APIs use application program’s stack, meaning that the Serial Server kernel does not change the
stack when your AP requests the service of API. The default stack size is 4 K bytes and is defined in
“makefile”. (Please refer the sample program)
In general, reserving 1K bytes stack memory is enough for these APIs calling and Serial Server kernel
processing.
Function Descriptions
InitSerialMode Initialize the serial port communication mode. Set baud rate,
data bit, parity and stop bit
SendSerialData Send data to the serial port.
GetSerialData Receive data from the serial port.
GetSerialStatus Get serial line status.
EnableSerialHWintr Enable hardware interrupts of serial port.
DisableSerialHWintr Disable hardware interrupts of serial port.
EnableRS485rx Set the RS-485 transceiver to RX mode.
EnableRS485tx Set the RS-485 transceiver to TX mode.
SerialIntrEOI The same as EOI(End Of Interrupt) command of assembly
language
Set485type Set COM Port to RS-422(4 wire) / RS-485(2 wire).
Get485type Get the type of COM Port, if it is RS485 (2 wires / 4 wires).
Getporttype Get the type of COM (RS-232/RS-485).
Getnewporttype Get the type of COM Port (RS232/RS422/RS485).
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
The UDP is an unreliable and connectionless communication protocol. Unlike TCP protocol, using UDP
the application program must pay more attention on the error handling of communication. In the Serial
Server, the AP can support up to 16 channels for UDP communications. It supports both point-to-point
and broadcast communications. For normal UDP application, the server device must issue udp_receive( )
or udp_receiveX( ) first. Then the client device sends data by issuing an udp_send( ) function call. If the
sequence is wrong, the data might be lost. The maximum data length per packet must be less than 1460
bytes.
Function Descriptions
tcp_connect Try to establish a connection by TCP client.
tcp_listen Try to establish a connection by TCP server.
tcp_disconnect Disconnect the established connection.
tcp_send Send data to the remote site via TCP connection.
tcp_receive Receive data from the remote site with post function.
tcp_getdata Receive data from the remote site with polling method
tcp_getsockopt Get some configuration option of the TCP connection.
tcp_setsockopt Set some configuration option to the TCP connection.
udp_open Establish an UDP communication channel.
udp_close Close an UDP communication channel.
udp_receive Receive data from any node of network.
udp_receiveX Receive data from the specific node.
udp_send Send data to the destination node.
udp_reset Release all of the UDP ports.
udp_close Close an UDP communication channel.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
There is one structure definition named CmdBlock in the header file “tcpdef.h”. Through this structure,
you can request the TCP/IP’s service either by TCP or UDP and examine the returned code. The
following structure elements are important to your AP:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Function Descriptions
EraseSector Erase one sector of flash memory.
ProgOneByte Write one byte into flash memory.
ProgString Write a block of data into flash memory.
ReadEEPROM Read one word from EEPROM.
WriteEEPROM Write one word into EEPROM
You can use GW21S API SetIntrVector() routine to redirect these 3 post routines as you need. The default
post routine is IRET.
Function Descriptions
WatchDogCtrl Set the Watch Dog Timer to be auto mode or manual mode.
As auto mode, the Watch Dog Timer is cleared by system (55
ms)
As manual mode, the Watch Dog Timer is cleared by AP
ClrWatchDogTime Clear Watch Dog Timer
SetupWatchDogTime Set the timeout period of the Watch Dog Timer. Only for
manual mode.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
When data are come from serial port, the ISR will get these data and put to the received queue
automatically. And then we can use the “COM_GetBuf()” to get these input data. The received queue is
defined in ‘comalo.c”. You can modify this file to change the size of queue.
When data are sent to serial port, we use the “COM_PutBuf()” to put these output data to sent queue. And
the ISR will get these data and send to serial port automatically. The sent queue is defined in ‘comalo.c”.
You can modify this file to change the size of queue.
Function Descriptions
Com_Config Initialize the serial port. Including ISR, baud rate, data bit,
parity and stop bit
Com_GetBuf Get data from receiving buffer (automatically received by
ISR).
Com_PutBuf Put data to sending buffer (automatically sent by ISR).
Com_ClearRxQue Clear receiving buffer.
Com_ClearTxQue Clear sending buffer.
Com_TxQueIsEmpty Check sending buffer is empty or not.
Com_DTR_Active Control the DTR signal.
Com_RTS_Active Control the RTS signal.
Com_DSR_Status Get the status of DSR signal.
Com_CTS_Status Get the status of CTS signal.
Com_RI_Status Get the status of RI signal.
Com_DCD_Status Get the status of DCD signal.
Function Descriptions
SetIOMode Set a channel to be DI/DO.
GetIOMode Get the channel’s I/O mode.
SetOutState Set the DO channel’s state (on/off)
GetInState Get the DI channel’s state (on/off)
ReadDigitalInput get data from the digital input port.
SetupRelayOutput Control relay outputs to on/off.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Function Descriptions
ReadRTCTime Read system time (including: hour, min, sec)
ReadRTCDate Read system date (including: year, month, day, week)
WriteRTCTime Write system time (including: hour, min, sec).
WriteRTCDate Write system date (including: year, month, day, week).
EnableWRProtect Allow to write system date/time.
DisableWRProtect Not allow to write system date/time.
Function Descriptions
AddAccount Add an account (add user name and password)
DelAccount Delete an account (delete user)
VerifyAccount Verify an account (verify user name and password)
Function Descriptions
GetESSID Get the Extended Service Set ID
SetESSID Set the Extended Service Set ID
GetFrame Get frame length used for RTS/CTS handshake control
SetFrame Set frame length used for RTS/CTS handshake control
GetFragment Get fragment length for unicast message transmission
SetFragment Set fragment length for unicast message transmission
GetChannel Get communication channel number for BSS creation
SetChannel Get net connection control characteristics
GetNetWorkType Get net connection control characteristics
SetNetWorkType Set net connection control characteristics
GetTransmitRate Get data rate for message transmission
SetTransmitRate Set data rate for message transmission
GetXI300WEPFlag Get WEP flag
SetXI300WEPFlag Set WEP flag
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
6. API Reference
6.1 General Functions
GetIntrVector()
Description: Get ISR (Interrupt Service Routine) entry point.
Include: dapapi.h
Usage: ulong GetIntrVector (uchar vector)
Input Parameters: vector: target interrupt vector
Return Value: ISR (Interrupt Service Routine) entry point is the starting code
address of the routine. It is represented as a LONG data format. It
contains the “Segment” and “Offset” address of the entry point.
Link: dapapi.dll
Example: Get the entry point of 1ms timer interrupt
ulong isr_1ms
isr_1ms = GetIntrVector(0x7D)
Remarks: Get the entry point of the interrupt vector specified by vector. This
function is generally used with SetIntrVector. To replace an interrupt
first save the current vector entry point by GetIntrVector, then set the
vector to your own interrupt function with SetIntrVector. The saved
vector can be restored if needed.
Note: Because Interrupt Service Routine maybe disable hardware interrupt, please don’t spend too
many CPU time in an interrupt service routine.
SetIntrVector()
Description: Set ISR (Interrupt Service Routine) entry point.
Include: dapapi.h
Usage: void SetIntrVector (uchar vector, farFUNC isr )
Input Parameters: vector target interrupt vector to replace
isr: the entry point of ISR
Return Value: None
Link: dapapi.dll
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Example: Setup the ISR to the 1st RS-232/RS-485 communication port. The
ISR codes in assembly language.
extern void far SIOIntr0();
main() {
SetIntrVector ( 0x0C, SIOIntr0 );
:
}
Note: Because Interrupt Service Routine maybe disable hardware interrupt, please don’t spend too
many CPU time in an interrupt service routine.
GetVersion()
Description: Gets the Serial Server F/W (kernel) version.
Include: dapapi.h
Usage: ushort GetVersion (void )
Input Parameters: None
Return Value: Low byte: major version number
High byte: minor version number
Link: dapapi.dll
Example: ushort dap_version;
dap_version = GetVersion()
Remarks: Gets the Serial Server firmware version number.
GetAPSerialNo()
Description: Get the version of the Application Program. This version string is set
by SetAPSerialNo().
Include: dapapi.h
Usage: void GetAPSerialNo(char*buf);
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
buf[[AP_VERSION_LEN] = ‘\0’ ;
GetAPSerialNo(buf);
Remarks: buf must be a characters array of 80+1 bytes
SetAPSerialNo()
Description: Set AP version
Include: dapapi.h
Usage: void SetAPSerialNo(char*ap_version);
Input Parameters: ap_version: a string which specifies the Application Program version
and some information about it.
Return Value: None
Link: dapapi.dll
Example: SetAPSerialNO(“termsrv1.0”);
Remarks: 1. ap_version is a null terminated string with 80 bytes maximum.
2. The ap_version can be displayed on the tool of ”moniter.exe”.
GetGwModel()
Description: Get the model number of this device
Include: dapapi.h
Usage: void GetGwModel(char*buf);
Input Parameters: buf:buffer for storing the model number.
The max. buffer length is 17 bytes (max. model number is 16
characters + 1 byte null terminator)
Return Value: None
Link: dapapi.dll
Example: #define GW_MODEL_LEN 16
Char buf[GW_MODEL_LEN+1] ;
GetGwModel( buf);
Remarks: buf must be a characters array of 17 bytes
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 2
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetConfigData()
Description: Get the device’s configuration data including TCP/IP configuration
data and version information.
Include: dapapi.h
Usage: void GetConfigData(char*buf);
Input Parameters: buf: buffer for storing the configuration data.
The buffer length must be 300 bytes
Return Value: None
Link: dapapi.dll
Example: #define GW_CONFIG_LEN 300
Char buf[GW_CONFIG_LEN] ;
GetConfigData( buf);
Remarks:
Reserved (4 Bytes)
Reserved (4 Bytes)
Reserved (4 Bytes)
Device’s IP Address (4 Bytes)
Reserved (4 Bytes)
Reserved (4 Bytes)
Gateway IP Address (4 Bytes)
(16 Bytes)
Offset 0-5 : Device MAC Address
Offset 6-15 : Reserved
(64 Bytes)
Offset 0-15 : Model Name
Offset 16-62 : Reserved
Offset 63 : Number of serial ports provided by device
(128 Bytes)
Offset 0 : Major version of kernel
Offset 1 : Minor version of kernel
Offset 2-127 : AP version
(64 Bytes)
Offset 0-3 : Subnet Mask
Offset 4-63 : Reserved
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetConsoleSta()
Description: Get the state which specifies it is in console mode or not.
Include: dapapi.h
Usage: ushort GetConsoleSta( void);
Input Parameters: None
Return Value: 0: console mode disable
1: console mode enable
Link: dapapi.dll
Example: ushort console_mode ;
console_mode = GetConsoleSta();
Remarks:
SYSTEM_RESET()
Description: Reset the system.
Include: dapapi.h
Usage: void SYSTEM_RESET(void);
Input Parameters:
Return Value: None
Link: dapapi.dll
Example: SYSTEM_RESET();
Remarks:
BatteryLowDetect()
Description: Detect the system battery. (Battery is for RTC and SRAM)
(only for GW26A)
Include: dapapi.h
Usage: int BatteryLowDetect(void);
Input Parameters:
Return Value: 0 : battery low;(please change battery).
Other: battery normal;
Example: batt_detect = BatteryLowDetect();
if(!batt_detect) {
/* error, battery low */
};
;
Remarks:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
SetDefaultKeyProc()
Description: Provide a customized default key process.
Include: dapapi.h
Usage: void SetDefaultKeyProc( farFUNCi );
main() {
…
SetDefaultKeyProc( default_key_proc) ;
…for (;;) {
…
}
}
Remarks:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Read_ApState ()
Description: Read the application program jumper is enabled or disabled.
Include: dapapi.h
Usage: unsigned short Read_ApState(void);
Input Parameters: None
Return Value: 0:the allpication program is enabled, 1:enabled
Link: dapapi.dll
Example: ret = Read_ApState();
Remarks:
InitSerialMode()
Description: Initialize the serial port communication mode.
Include: dapapi.h
Usage: ushort InitSerialMode (ushort port, uchar mode)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
mode: Mode consists of four parts: baud rate, parity, data length and
stop bit length all in binary numbers. For detailed information,
please refer followings.
Bit 7 6 5 4 3 2 1 0
Setting Baud rate Parity Stop bit Data length
000 – 19200 X0 - None 0 – 1 10 - 7 bits
001 – 38400 01 - Odd 1 – 2 11 – 8 bits
010 – 57600 11 - Even
011 –115200
100 - 1200
101 – 2400
110 - 4800
111 – 9600
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
SendSerialData()
Description: Send data to the serial port.
Include: dapapi.h
Usage: ushort SendSerialData (ushort port, uchar Send_data)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
Send_data: unsigned char
A character to be sent out
Return Value: The status of the specified serial line.
High byte contain: LSR(Line Status Register)
Bit 7 = Time out. 0: No time out; 1: Send data Time out
Bit 6 = Transmission shift register empty
Bit 5 = Transmission holding register empty
Bit 4 = Break detect
Bit 3 = Framing error
Bit 2 = Parity error
Bit 1 = Overrun error
Bit 0 = Data ready
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetSerialData()
Description: Receive data from the serial port.
Include: dapapi.h
Usage: ushort GetSerialData (ushort port)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
Return Value: The status of the specified serial line and received data.
High byte contain:
Bit 7 = Time out
Bit 4 = Break detect
Bit 3 = Framing error
Bit 2 = Parity error
Bit 1 = Overrun error
GetSerialStatus()
Description: Get the line status of the specific serial port.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Include: dapapi.h
Usage: ushort GetSerialStatus (ushort port)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
Return Value: Refer to InitSerialMode() return value
Link: dapapi.dll
Example: /* Get line status of the 1st port. */
Line_status = GetSerialStatus(0)
Remarks:
EnableSerialHWintr()
Description: Enable the hardware interrupt of the specific serial port.
Include: dapapi.h
Usage: void EnableSerialHWintr (ushort port)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
Return Value: None
Link: dapapi.dll
Example: /* Enable the 1st serial port H/W interrupt. */
EnableSerialHWintr( 0 )
Remarks: Before calling this function, you must setup the Interrupt Service
Routine (ISR) first.
DisableSerialHWintr()
Description: Disable the hardware interrupt of the specific serial port.
Include: dapapi.h
Usage: void DisableSerialHWintr (ushort port)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
Return Value: None
Link: dapapi.dll
Example: Disable the 1st serial port H/W interrupt.
DisableSerialHWintr(0)
Remarks:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
EnableRS485rx()
Description: Set the RS-485 transceiver to RX mode for the specific serial port.
Include: dapapi.h
Usage: void EnableRS485rx (ushort port)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
Return Value: None
Link: dapapi.dll
Example: Enable RX mode of the 1st serial port.
EnableRS485rx( 1 )
Remarks: This function has no effect to RS-232 port. If the RS-485 serial port
want to send data then its RS-485 transceiver must be set to TX
mode. After sending data is over then its RS-485 transceiver must be
set to RX mode for receiving data.
EnableRS485tx()
Description: Set the RS-485 transceiver to TX mode for the specific serial port.
Include: dapapi.h
Usage: void EnableRS485tx (ushort port)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
Return Value: None
Link: dapapi.dll
Example: Enable TX mode of the 1st serial port.
EnableRS485tx( 0 )
Remarks: This function has no effect to RS-232 port. If the RS-485 serial port
want to send data then its RS-485 transceiver must be set to TX
mode. After sending data is over then its RS-485 transceiver must be
set to RX mode for receiving data.
SerialIntrEOI()
Description: Execute the EOI command for the serial port H/W interrupt service
routine.
Include: dapapi.h
Usage: void SerialIntrEOI (ushort port)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
Return Value: None
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Link: dapapi.dll
Example: Issue EOI command for the 1st port.
SerialIntrEOI( 1 )
Remarks: It must issue the H/W End Of Interrupt (EOI) command before
terminating the H/W ISR (Interrupt Service Routine).
Getnewporttype()
Description: Get the type of COM Port (RS232/RS422/RS485).
Include: dapapi.h
Usage: ushort Getnewporttype (ushort port)
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
Return Value: 0: RS232
1: RS485 (2 wires)
2: RS422 (4 wires)
3: Console mode
4: RS422/RS485
5:Unknown
Link: dapapi.dll
Example: ushort port_type ;
port_type = Genewporttype();
Remarks:
Setnewporttype()
Description: Set the type of COM Port (RS232/RS422/RS485).
(only for SE5001 and SE5002)
Include: dapapi.h
Usage: ushort Setnewporttype (ushort port, uchar type)
Input Parameters: port: unsigned short, =0: for COM1, 1: for COM2
type: unsigned char, =0: RS232, 1: RS485 (2 wires),
2: RS422 (4 wires)
Return Value: <0: setting failed, >=0:ok
Link: dapapi.dll
Example: /* Set COM1 as RS-232 */
Senewporttype( 0, 0);
Remarks:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Setnewporttype2()
Description: Set the type of COM Port (RS232/RS422/RS485) and save the
configuration to EEPRPOM.
(only for SE5001 and SE5002)
Include: dapapi.h
Usage: ushort Setnewporttype2 (ushort port, uchar type)
Input Parameters: port: unsigned short, =0: for COM1, 1: for COM2
type: unsigned char, =0: RS232, 1: RS485 (2 wires),
2: RS422 (4 wires)
Return Value: <0: setting failed, >=0:ok
Link: dapapi.dll
Example: /* Set COM1 as RS-232 */
Senewporttype2( 0, 0);
Remarks:
Getporttype()
Description: Get the type of COM (RS-232/RS-485)
(Note: For GW26A, it can not be detected to RS232 or RS485)
Include: dapapi.h
Usage: ushort Getporttype(void )
Input Parameters: None
Return Value: unsigned short.
= 0xFFFF: The device does not support this function
= Others:
bit 0 (Port1): 0-> RS485, 1-> RS232
bit 1 (Port2): 0-> RS485, 1-> RS232
Note: If the device does not have COM2, then the bit 1 can be ignored.
Link: dapapi.dll
Example: get_porttype = Getporttype();
if (get_porttype & 1)
/* This is RS232 for port1*/
else
/* This is RS485 for port2 */
Remarks:
Get485type()
Description: Get the type of COM Port, if it is RS485 (2 wires / 4 wires).
(Note: GW21S-MAXI does not support this function.)
Include: dapapi.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 3
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Set485type()
Description: Set Com Port to RS-422(4 wire) / RS-485(2 wire).
(Note: Only GW21L, GW21R and GW21W support this function)
Include: dapapi.h
Usage: int Set485type( uchar Set_485type)
Input Parameters: Set_485type: unsigned char,
bit 0 (Port1): 0-> RS422(4 wires), 1-> RS485(2 wires)
bit 1 (Port2): 0-> RS422(4 wires), 1-> RS485(2 wires)
Note: If the device does not have COM2, then the bit 1 can be ignored.
Return Value: None
Link: dapapi.dll
Example: /* set COM1 as RS485 and COM2 as RS422 */
Set485type(0x01)
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetTotalPort()
Description: Get the count of serial ports in the device.
Include: dapapi.h
Usage: ushort GetTotalPort ( void);
Input Parameters: None
Return Value: >=0: count of serial ports
Link: dapapi.dll
Example: ushort port_count ;
GetPhyState()
Description: Get the Ethernet cable connecting status.
Include: dapapi.h
Usage: ushort GetPhyState ( void);
Input Parameters: None
Return Value: >0: ok
Link: dapapi.dll
Example: int ret ;
SetupProcessLed()
Description: Set RUN LED to on/off.
Include: dapapi.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
BuzzerOn()
Description: Make a buzzer on.
Include: dapapi.h
Usage: Void BuzzerOn ( void )
Input Parameters: None
Return Value: None
Link: dapapi.dll
Example: BuzzerOn()
Remarks: Turn the buzzer on for 40ms and then off.
For GW21S-maxi and GW21L, they do not have buzzers so
calling this function is the same as calling SetupProcessLed().
Except that SetupProcessLed() is a state changed function and
BuzzerOn() is a trigger function.
SetupComLed()
Description: Set LEDs on/off of a specified COM ports.
Include: dapapi.h
Usage: void SetupComLed(ushort port, uchar com_led);
Input Parameters: port: unsigned short
=0: for COM1, 1: for COM2
com_led: unsigned char
= 0:off, 1:on
Return Value: None
Link: dapapi.dll
Example: SetupComLed(0,1); // com port1 led on
SetupComLed(1,0); // com port2 led off
Remarks:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
tcp_connect()
Description: Request to establish a connection to a peer by client site.
Include: tcpapi.h, tcpdef.h
Usage: int tcp_connect (int far *handle, unsigned short fromPort,
unsigned long toIPaddr, unsigned short toPort, farFUNC postfunc,
char far *parg)
Input Parameters: phandle: the address of an unique handle establishing the
connection.
fromPort: local TCP socket port number
toIPaddr: the IP address of remote device which you want to
connect to
toPort: remote TCP socket port number
postfunc: entry point of the post-function which will be called by
kernel system after the connecting is successful or failed.
parg : the address of an argument to pass to post-function
Return Value: =SUCCESS : the TCP/IP driver accepts this request.
others : error, refer to error message defined in tcpdef.h
Link: dapapi.dll
Example: /* about detailed program please refer the sample in Appendix */
/* establishes a TCP connection */
ushort localPort = 0;
ulong remoteIP = 0x2034000a; /* 10.0.52.32 */
ushort remotePort = 0x4321;
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
tcp_listen()
Description: Establish a connection by server site.
Include: tcpapi.h, tcpdef.h
Usage: int tcp_listen (int far *phandle, unsigned short fromPort, farFUNC
postfunc, char far *parg)
Input Parameters: phandle: the address of an unique handle establishing the
connection.
fromPort: local TCP socket port number
postfunc:entry point of the post-function which will be called by
kernel system after the connecting is successful or
failed.
parg: The address of an argument to pass to post-function.
Return Value: =SUCCESS: the TCP/IP driver accepts this request.
others : error, please refer to the file tcpdef.h
Link: dapapi.dll
Example: /* about detailed program please refer the sample in Appendix */
ushort localPORT = 0x1234;
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
tcp_disconnect()
Description: Disconnect the established connection.
Include: tcpapi.h, tcpdef.h
Usage: int tcp_disconnect (int handle)
Input Parameters: handle: the unique handle of the established connection
Return Value: =SUCCESS : disconnect is successful
others : error, please refer to the file tcpdef.h
Link: dapapi.dll
Example: /* disconnect to the device */
tcp_discount ( handle ); // disconnect the established connection
Remarks: This function is used by the client and severs devices to disconnect
the connection that has already been established. After calling this
function one of the devices (client or server) will disconnect first and
the other device will disconnect in 2 seconds for garbage processing.
You can establish a new connection between these two devices again.
tcp_send()
Description: Request to send data to the remote site via TCP connection.
Include: tcpapi.h, tcpdef.h
Usage: int tcp_send (int handle, char far *pbuf, unsigned short len, farFUNC
postfunc, char far *parg)
Input Parameters: handle: the unique handle of the established connection
pbuf : the pointer of data buffer to be sent out
len: data length
postfunc: entry point of the post-function which will be called by
kernel system after the data are sent to remote site
successfully or failed to send.
parg: The address of an argument to pass to post-function.
Return Value: =SUCCESS : the TCP/IP driver accepts this request.
others : error, please refer to the file tcpdef.h
Link: dapapi.dll
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Example: /* send data via TCP and check the data are sent to remote site
successfully or not. */
int flag_result;
int main()
{
:
flag_result = 1;
ret = tcp_send( handle, “1234”, 4, send_post, NULL);
if ( ret == SUCCESSFUL) {
while( flag_result == 1 ) ; // wait for result
return( flag_result );
}
:
}
void _loadds far send_post( CMDBLK far *cb, void far *arg)
{
if( cb->retcode == SUCCESS )
flag_result = OK; //=0
else flag_result = cb->retcode; //<0
}
Remarks: This function is used to send data to the remote site via the
established connection. The maximum data length is 1460 bytes. In
the post-function, you can check whether this function is successful
or not. In the tcp_send post-function, you can issue tcp_send again.
When the data are sent to remote site successfully or not, the
post-function which will be called by kernel system
tcp_receive()
Description: Request to receive data from the remote site via TCP connection.
Include: tcpapi.h, tcpdef.h
Usage: int tcp_receive (int handle, char far *pbuf, unsigned short len,
farFUNC postfunc, char far *parg)
Input Parameters: handle: the unique handle of the established connection
postfunc: entry point of the post-function which will be called by
kernel system after data are received or the connection is
disconnected.
parg: The address of an argument to pass to post-function.
pbuf: the address of receive buffer
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
tcp_getdata()
Description: Poll to receive data from the remote site via TCP connection.
Include: tcpapi.h, tcpdef.h
Usage: int tcp_getdata (int handle, char far *pbuf, short far *plen)
Input Parameters: handle: the unique handle of the established connection
plen: the address of requested length when calling, and the
address of actual length after calling
pbuf the address of receive buffer
Return Value: =SUCCESS : connect is successful
others : error, please refer to the file tcpdef.h
Link: dapapi.dll
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Example: //expect to get 100 bytes data length form TCP driver.
char buf[512];
short len;
len = 100;
if ( tcp_getdata( handle, buf, (short far *)&len) == SUCCESS )
{
if ( len == 0 )
{
//No received data
}
else
{
//Process received data
:
}
}
else
{
//fatal error, the connection may be failed.
:
}
Remarks: This function is almost the same as tcp_receive(). The difference
between these two functions is that tcp_getdata() is without
post-function. The practical received data length will store into the
plen.
tcp_getsockopt()
Description: Get some configuration option of the TCP connection.
Include: tcpapi.h, tcpdef.h
Usage: int tcp_getsockopt (int handle, int cmd_type, char far *pbuf, short far
*plen)
Input Parameters: handle: the unique handle of the established connection
cmd_type: A command ID to identify a configuration job.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
short keep_alive;
keep_alive = 0;
if ( tcp_getsockopt( handle, SO_KEEPALIVE_TIME , &keep_alive,
sizeof(keep_alive)) == SUCCESS )
{
/* ok */
}
else
{
/* failed */
}
tcp_setsockopt()
Description: Set some configuration option to the TCP connection.
Include: tcpapi.h, tcpdef.h
Usage: int tcp_setsockopt (int handle, int cmd_type, char far *pbuf, short far
*plen)
Input Parameters: handle: the unique handle of the established connection
cmd_type: A command ID to identify a configuration job.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 4
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
keep_alive = 0;
if ( tcp_setsockopt( handle, SO_KEEPALIVE_TIME , &keep_alive,
sizeof(keep_alive)) == SUCCESS )
{
/* ok */
}
else
{
/* failed */
}
Remarks: For cmd_type = SO_KEEPALIVE_TIME
If the TCP connection is silent more than n*10 sec, then the TCP
driver will send a keep-alive packet to make sure the connection is
ok. If the remote site is still no response then the TCP driver will
re-send the keep-alive packet every 10 sec at least 7 times then
disconnect this TCP connection.
The n is an short integer type and its address is as the pbuf parameter.
Its default value is 4. The default disconnect time is (4*10sec +
7*10sec) which is about 110 sec.
If its value is 0 then there is no keep-alive packet will be sent.
udp_open()
Description: Establish an UDP communication channel.
Include: tcpapi.h, tcpdef.h
Usage: int udp_open (int *phandle, short *plocalPort)
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
udp_close()
Description: Close an UDP communication channel.
Include: tcpapi.h, tcpdef.h
Usage: int udp_close (int handle)
Input Parameters: handle the unique handle of the established communication
channel
Return Value: =SUCCESS : close is successful
others : error, the definition of ERROR number please refer to
the file “tcpdef.h”
Link: dapapi.dll
Example: //Close an exist UDP channel
udp_close ( handle );
udp_receive()
Description: Receive data from the remote site.
Include: tcpapi.h, tcpdef.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Usage: int udp_receive (int handle, char far *pbuf, unsigned short len,
farFUNC postfunc, void far *parg)
Input Parameters: handle the handle of the UDP channel created by udp_open
udp_receiveX()
Description: Request to receive UDP data from the remote site.
Include: tcpapi.h, tcpdef.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
udp_send()
Description: Send data to the destination node.
Include: tcpapi.h, tcpdef.h
Usage: int udp_send (int handle, short toPort, long toIPaddr, char far
*pbuf, short len)
Input Parameters: handle the unique handle of the established connection
toPort the UDP port number of destination node
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
main()
{
udp_open( &handle )
udp_send ( handle, remotePORT, remoteIP, buf, len);
: // processing
:
}
Remarks: This function is used to send UDP data to the destination node. The
maximum data length is 1460 bytes.
udp_reset()
Description: Release all of the UDP ports.
Include: tcpapi.h, tcpdef.h
Usage: int udp_reset ()
Input Parameters:
Return Value: =SUCCESS : successful
others : error, the definition of ERROR number please refer to
the file “tcpdef.h”
Link: dapapi.dll
Example: /* Close all of the UDP channels */
udp_open ( handle1 );
udp_open ( handle2 );
:
udp_reset ( );
GetLocalIPAddr()
Description: Get the local device’s IP address.
Include: tcpapi.h, tcpdef.h
Usage: int GetLocalIPAddr ( char far *buf )
Input Parameters: buf buffer to store the IP address. The buffer must be more than 4
bytes.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetLocalEthAddr()
Description: Get the Serial Server’s ETHERNET address
Include: tcpapi.h, tcpdef.h
Usage: int GetLocalEthAddr (char far *buf )
Input Parameters: buf buffer to store the ETHERNET address. The buffer must be
more than 6 bytes.
Return Value: =SUCCESS : successful
others : error, the definition of ERROR number please refer to
the file “tcpdef.h”
Link: dapapi.dll
Example: /* Gets the Serial Server’s ETHERNET address */
uchar buf[6];
GetLocalEthAddr ( buf ); // assume ETHERNET address
// buf[0] = 0x00 // = 00:60:E9-01:02:03
// buf[1] = 0x60
// buf[2] = 0xE9
// buf[3] = 0x01
// buf[4] = 0x02
// buf[5] = 0x03
Remarks: This function is used to get the Serial Server’s physical address, it is
also called the MAC (Medium Access Control) address. An example
of the ETHERNET address shown below
manufacture ID board ID
| 0x00 0x60 0xE9 | 0x01 0x02 03 |
GetDefaultGateway()
Description: Get the Serial Server’s default gateway address.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetLocalNetmask()
Description: Get the Serial Server’s NET-MASK value.
Include: tcpapi.h, tcpdef.h
Usage: int GetLocalNetmask (char far *buf )
Input Parameters: buf: buffer to store the NET-MASK value. The buffer must be
more than 4 bytes.
Return Value: =SUCCESS :successful
others : error, the definition of ERROR number please refer to
the file “tcpdef.h”
Link: dapapi.dll
Example: /* Get the Serial Server’s NET-MASK value */
uchar buf[4];
GetLocalNetmask ( buf ); // assume NET-MASK value
// buf[0] = 0xFF // = 255.255.255.0
// buf[1] = 0xFF
// buf[2] = 0xFF
// buf[3] = 0x00
Remarks: This function is used to get the NET-MASK value. Each Serial
Server must have a NET-MASK value.
GetHostName()
Description: Get the name of this device.
Include: tcpapi.h, tcpdef.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetHostName ( buf );
Remarks: This host name is as the DHCP host name and the SNMP system
name.
GetDhcp()
Description: Check the DHCP mode being enable or disable.
Include: tcpapi.h, tcpdef.h
Usage: int GetDhcp (char far *dhcp_mode )
Input Parameters: dhcp_mode: The address of DHCP mode.
Return Value: =SUCCESS :successful
others : error, the definition of ERROR number please refer to the
file “tcpdef.h”
Link: dapapi.dll
Example: /* Set the device name */
char dhcp_mode;
GetDhcp( &dhcp_mode);
If ( dhcp_mode==0) {
/* DHCP is disable */
}
else {
/* DHCP is enable */
}
Remarks: After calling this function, if the value is 0 then the DHCP is disable and
the IP address being gotten from GetLocalIPAddr() is a fixed IP,
otherwise the DHCP is enable and the IP address is a dynamic IP..
GetConnectStatus()
Description: Get the status of a TCP connection.
Include: tcpapi.h, tcpdef.h
Usage: int GetConnectStatus (int handle, struct connectStatus far *conn_status )
Input handle: the unique handle of the established connection.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
/* In general,
state = 1 : connection is closed
state = 2, 3, 4 : wait to connect or to be connected
state = 5 : connection is ok
state = 6,7,8,9,10,11: connection is closing
*/
SetLocalIPAddr()
Description: Get the local device’s IP address.
Include: tcpapi.h, tcpdef.h
Usage: int SetLocalIPAddr ( unsigned long ip )
Input Parameters: ip new IP address.
Return Value: =SUCCESS : successful
others : error, the definition of ERROR number please refer to
the file “tcpdef.h”
Link: dapapi.dll
Example: /* set a new IP address = 10.0.0.1*/
unsigned long ip;
ip = 0x100000a ;
SetLocalIPAddr ( ip ); // assume IP address = 10.0.0.1
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 5
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Remarks: This function is used to set the Serial Server local IP address. Each
Serial Server must have its own unique IP address to identify the
node on the local network via TCP/IP.
SetDefaultGateway()
Description: Set the Serial Server’s default gateway address.
Include: tcpapi.h, tcpdef.h
Usage: int SetDefaultGateway (unsigned long gateway)
Input Parameters: gateway new gateway address.
Return Value: =SUCCESS : successful
others : error, the definition of ERROR number please refer to the
file “tcpdef.h”
Link: dapapi.dll
Example: /* set a new gateway = 10.0.0.254*/
unsigned long gateway;
gateway = 0xFE00000a ;
SetDefaultGateway ( gateway);
Remarks: This function is used to set the default gateway IP address in the Serial
Server. Each Serial Server must have a default gateway IP address to
forward the TCP/IP packet to another segment of the network.
SetLocalNetmask()
Description: Set the Serial Server’s NET-MASK value.
Include: tcpapi.h, tcpdef.h
Usage: int SetLocalNetmask (unsigned long netmask)
Input Parameters: netmask new netmask
Return Value: =SUCCESS :successful
others : error, the definition of ERROR number please refer to
the file “tcpdef.h”
Link: dapapi.dll
Example: /* set a new netmask = 255.255.255.0 */
unsigned long netmask;
netmask = 0x00FFFFFF ;
SetLocalNetmask ( netmask);
Remarks: This function is used to set the NET-MASK value. Each Serial
Server must have a NET-MASK value.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
SetHostName()
Description: Set a name for the device.
Include: tcpapi.h, tcpdef.h
Usage: int SetHostName (char far *buf )
Input Parameters: buf: buffer to store the device name. The buffer size is 16+1 bytes
including null terminator.
Return Value: =SUCCESS :successful
others : error, the definition of ERROR number please refer to
the file “tcpdef.h”
Link: dapapi.dll
Example: /* Set the device name */
char buf[16+1];
Remarks: This host name is as the DHCP host name and the SNMP system
name.
EraseSector()
Description: Erase one sector of flash memory.
Include: dapapi.h,
Usage: ushort EraseSector ( uchar sector_id )
Input Parameters: sector_id: sector id to be erase.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ret = EraseSector(2);
if ( ret ) {
// fatal error found !!!
}
else {
// OK !!!
}
Remarks: This function is used to erase one sector of flash memory. For
GW21x-maxi and GW21R, one sector is 64K bytes. But For GW21L
and GW21W, one sector is 128K bytes.
ProgOneByte()
Description: Write one byte into flash memory.
Include: dapapi.h
Usage: ushort ProgOneByte ( uchar data, uchar *addr)
Input Parameters: data byte value being written into flash memory
addr address of flash memory.
Note:
1. The segment value of the address must be 64k boundary,
it means that the legal segment value is 0x8000、
0x9000....or 0xD000. For example: the address D000:F000
is correct but DF00:0 is error.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Remarks: This function is used to write one byte data into the flash memory.
ProgString()
Description: Write a string of data into flash memory.
Include: dapapi.h
Usage: ushort ProgString ( ushort len, uchar *src, uchar *dest )
Input Parameters: len byte count of data
src source address of data
dest destination address of flash memory.
Note:
1. The segment value of the address must be 64k boundary,
it means that the legal segment value is 0x8000、
0x9000....or 0xD000. For example: the address D000:F000
is correct but DF00:0 is error.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ushort ret;
uchar *addr;
Remarks: This function is used to write a block of data into the flash memory.
ReadEEPROM()
Description: Read one word from EEPROM.
Include: dapapi.h,
Usage: ushort ReadEEPROM ( ushort index )
Input Parameters: index word index, address range (0 ~ 151), 152 words
Return Value: value being stored at the address of index in the EEPROM
Link: dapapi.dll
Example: /* Read the 5th word data in the serial EEPROM. */
ushort ee_data;
ee_data = ReadEEPROM ( 4 );
Remarks: This function is used to read one word data stored in the EEPROM.
WriteEEPROM()
Description: Write one word data into EEPROM.
Include: dapapi.h
Usage: void WriteEEPROM ( ushort id, ushort data )
Input Parameters: index word identifier, address range (0 ~ 151), 152 words
data value being written into the EEPROM
Return Value: None
Link: dapapi.dll
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Example: /* Write the 24th word data with 0x1234 into the EEPROM. */
Remarks: This function is used to write one word data into the EEPROM.
WatchDogCtrl()
Description: choose to control the watch-dog by the system or user.
Include: dapapi.h
Usage: void WatchDogCtrl(uchar ch);
Input Parameters: ch; = 0 : watch-dog controls by system automatically.
= 1 : watch-dog controls by user’s application program.
Return Value: None
Link: dapapi.dll
Example: /* System will clear the watch-dog timer automatically. */
WatchDogCtrl(0x00);
ClrWatchDogTime()
Description: clear watch dog timer.
Include: dapapi.h
Usage: void ClrWatchDogTime(void);
Input Parameters:
Return Value: None
Link: dapapi.dll
Example: /* Clear watch-dog timer. */
ClrWatchDogTime();
Remarks: When the watch dog timer is set to be controlled by user, the AP
must call this function to clear watch dog timer before watch dog is
timeout to reset the system.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
SetupWatchDogTime()
Description: Set the timeout time of watch dog timer.
Include: dapapi.h
Usage: void SetupWatchDogTime(ushort value);
Input Parameters: value: timeout time of watch dog timer by msec. (0x0000 -
0xFFFF). Timeout time = (value * 55 msec) + 1.6 sec.
Return Value: none
Link: dapapi.dll
Example: /* Watch Dog Time out = watch-dog-time * 55 msec + 1.6 sec
if watch-dog-time = 1000 (=0x3e8), then the timeout = 56.6 sec. */
SetupWatchDogTime( 0x3e8);
Remarks: When the watch dog timer is set to be controlled by user, the AP
must call ClrWatchDogTime() function to clear watch dog timer
before this timeout time is reached. Otherwise the system will be
reset.
Com_Config()
Description: Initialize the serial port. Including ISR, baud rate, data bit, parity and stop
bit
Include: comapi.h
Usage: int Com_Config (int iport, unsigned long lBaudRate, int iParity, int
iData, int iStop)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
lBaudRatet: Baud Rate: 1200, 2400, 4800, 9600, 19200, 38400, 57600,
115200.
iparity: Parity check: 0:none, 1:odd parity, 2:even parity, 3:mark
parity, 4:space parity
iData: Data bits: 7:7 data bits, 8:8 data bits
iStop: Stop bits: 1:1 stop bit, 2:2 stop bits
Return Value: 0: ok, others: parameters error
Link: comapi.obj
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Com_GetBuf()
Description: Get data from receiving buffer (automatically received by ISR).
Include: comapi.h
Usage: int Com_GetBuf (int iport, char *buf, int cnt)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
buf: Give a buffer for storing received data.
cnt: Size of buffer.
Return Value: Count of received data in buffer, 0: no data.
Link: comapi.obj
Example: Char buf[256] ;
com_port = 0 ; // 0:COM1
cnt = 256 ;
ret = Com_GetBuf( com_port, buf, cnt) ; //get data from com port
if (ret>0) { //receive data
receive_count = ret ;
}
else {
//receive no data
}
Remarks:
Com_PutBuf()
Description: Put data to sending buffer (automatically sent by ISR).
Include: comapi.h
Usage: int Com_PutBuf (int iport, char *buf, int cnt)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Com_ClearRxQue()
Description: Clear receiving buffer.
Include: comapi.h
Usage: void Com_ClearRxQue (int iport)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
Return Value: none.
Link: comapi.obj
Example: com_port = 0 ; // 0:COM1
Com_ClearRxQue( com_port) ;
Remarks:
Com_ClearTxQue()
Description: Clear sending buffer.
Include: comapi.h
Usage: void Com_ClearTxQue (int iport)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
Return Value: none.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Link: comapi.obj
Example: com_port = 0 ; // 0:COM1
Com_ClearTxQue( com_port) ;
Remarks:
Com_TxQueIsEmpty()
Description: heck sending buffer is empty or not.
Include: comapi.h
Usage: int Com_TxQueIsEmpty (int iport)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
Return Value: 0:not empty, <>0:empty.
Link: comapi.obj
Example: com_port = 0 ; // 0:COM1
ret = Com_TxQueIsEmpty( com_port) ;
if (ret==0) {
//not empty
}
else {
//is empty
}
Remarks:
Com_DTR_Active()
Description: Control the DTR signal.
Include: comapi.h
Usage: void Com_DTR_Active (int iport, int active)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
active: 0: inactive, 1: active
Return Value: none.
Link: comapi.obj
Example: com_port = 0 ; // 0:COM1
active = 1
Com_DTR_Active( com_port, active) ;
Remarks:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 6
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Com_RTS_Active()
Description: Control the RTS signal.
Include: comapi.h
Usage: void Com_RTS_Active (int iport, int active)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
active: 0: inactive, 1: active
Return Value: none.
Link: comapi.obj
Example: com_port = 0 ; // 0:COM1
active = 1
Com_RTS_Active( com_port, active) ;
Remarks:
Com_DSR_Status()
Description: Get the status of DSR signal.
Include: comapi.h
Usage: int Com_DSR_Status (int iport)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
Return Value: 0: inactive, <>0: active.
Link: comapi.obj
Example: com_port = 0 ; // 0:COM1
status = Com_DSR_Status( com_port) ;
Remarks:
Com_CTS_Status()
Description: Get the status of CTS signal.
Include: comapi.h
Usage: int Com_CTS_Status (int iport)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
Return Value: 0: inactive, <>0: active.
Link: comapi.obj
Example: com_port = 0 ; // 0:COM1
status = Com_CTS_Status( com_port) ;
Remarks:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Com_RI_Status()
Description: Get the status of RI signal.
Include: comapi.h
Usage: int Com_RI_Status (int iport)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
Return Value: 0: inactive, <>0: active.
Link: comapi.obj
Example: com_port = 0 ; // 0:COM1
status = Com_RI_Status( com_port) ;
Remarks:
Com_DCD_Status()
Description: Get the status of DCD signal.
Include: comapi.h
Usage: int Com_DCD_Status (int iport)
Input Parameters: iport: serial port number of Serial Server, 0: 1st port, 1:2nd port
Return Value: 0: inactive, <>0: active.
Link: comapi.obj
Example: com_port = 0 ; // 0:COM1
status = Com_DCD_Status( com_port) ;
Remarks:
SetIOMode()
Description: Set a channel to be as DI or DO.
(only for GW21S-maxi, and SE5001)
Include: dapapi.h
Usage: void SetIOMode( uchar channel, uchar mode) ;
Input Parameters: channel: = 0~3 for channel 1~4
mode: = 0: as DO, 1: as DI
Return Value: None
Link: dapapi.dll
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetIOMode()
Description: Get a channel’s I/O mode.
(only for GW21S-maxi, and SE5001)
Include: dapapi.h
Usage: ushort GetIOMode( uchar channel) ;
Input Parameters: channel: /= 0~3 for channel 1~4
Return Value: = 0:DO, 1:DI
Link: dapapi.dll
Example: mode1 = GetIOMode(0); // get channel-1’s mode
mode4 = GetIOMode(3); // get channel-4’s mode
Remarks:
SetOutState()
Description: Set the DO channel’s state (on/off).
(only for GW21S-maxi, and SE5001)
Include: dapapi.h
Usage: void SetOutState(uchar channel, uchar state) ;
Input Parameters: channel: = 0~3 for channel 1~4
State: = 0:DO off, 1:DO on
Return Value: None
Link: dapapi.dll
Example: SetOutState(0, 1); // set channel-1 DO to be on
SetOutState(0, 0); // set channel-1 DO to be off
Remarks:
GetInState()
Description: Get the DI/DO channel’s state (on/off).
(only for GW21S-maxi, and SE5001)
Include: dapapi.h
Usage: ushort GetInState( uchar channel) ;
Input Parameters: channel: = 0~3 for channel 1~4
Return Value: =0:off, 1:on
Link: dapapi.dll
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ReadDigitalInput()
Description: get data from the digital input port.
(only for GW26A)
Include: dapapi.h
Usage: ushort ReadDigitalInput(void);
Input Parameters: void
Return Value: An unsigned short value (2 bytes, contain 16 digital-input values)
Bit 0 ~ Bit 11 are for DI-1 ~ DI-12.
Example: DigitalInput_value = ReadDigitalInput();
Remarks:
SetupRelayOutput()
Description: Control relay outputs to on/off.
(only for GW26A)
Include: dapapi.h
Usage: void SetupRelayOutput(uchar relay);
Input Parameters: An unsigned char value (1 bytes, contain 8 digital-output values)
Bit 0 ~ Bit 7 are for DO-1 ~ DO-8.
Return Value: None
Example: //Enable relay output port Number 1 and Number 2.
SetupRelayOutput(0x03);
Remarks:
ReadRTCTime()
Description: Read the system time from the RTC.
(only for GW21C-maxi, GW21S-maxi, GW26A)
Include: dapapi.h
Usage: ulong ReadRTCTime(void);
Input Parameters: Void
Return Value: RTC time (hour/min/second) with BCD format.
Link: dapapi.dll
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ReadRTCDate()
Description: Read the system Date from the RTC.
(only for GW21C-maxi, GW21S-maxi, GW26A)
Include: dapapi.h
Usage: ulong ReadRTCDate(void);
Input Parameters: Void
Return Value: RTC date (week/day/month/year) with BCD format.
Link: dapapi.dll
Example: unsigned long Sys_Date ;
Sys_Date = ReadRTCDate();
//if the Date is (2001/03/16 Friday) then Sys_Date will be
0x05160301
Remarks:
WriteRTCTime()
Description: Write the time to the RTC as system time.
(only for GW21C-maxi, GW21S-maxi, GW26A)
Include: dapapi.h
Usage: void WriteRTCTime( uchar hour, uchar minute, uchar
second);
Input Parameters: With BCD format
hour : 0x00 ~ 0x23 (24hrs, BCD format).
minute : 0x00 ~ 0x59 (60 minutes, BCD format).
second : 0x00 ~ 0x59 (60 seconds, BCD format).
Return Value: None
Link: dapapi.dll
Example: //if set the time to (14:23:59)
WriteRTCTime(0x14, 0x23, 0x59);
Remarks:
WriteRTCDate()
Description: Write the Date to the RTC as system date.
(only for GW21C-maxi, GW21S-maxi, GW26A)
Include: dapapi.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
EnableWRProtect()
Description: Enable RTC write protect. (user can only read RTC but can not
write it).
(only for GW21C-maxi, GW21S-maxi, GW26A)
Include: dapapi.h
Usage: void EnableWRProtect(void);
Input Parameters: void
Return Value: None
Link: dapapi.dll
Example: EnableWRProtect();
Remarks:
DisableWRProtect()
Description: Disable RTC write protect. (user can read and write RTC).
(only for GW21C-maxi, GW21S-maxi, GW26A)
Include: dapapi.h
Usage: void DisableWRProtect(void);
Input Parameters: void
Return Value: None
Link: dapapi.dll
Example: DisableWRProtect();
Remarks:
GetStartupTime()
Description: Get a time interval from system startup. It is by mini-second.
Include: dapapi.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
sys_msec = GetStartupTime();
GetSysMsec()
Description: Get a time interval from system startup. It is by mini-second.
Include: dapapi.h
Usage: ulong GetSysMsec( void);
Input Parameters: None
Return Value: a time interval from system startup. It is by mini-second.
Link: dapapi.dll
Example: ulong sys_msec ;
sys_msec = GetSysMsec();
GetSysTick()
Description: Get a time interval from system startup. It is by tick (55ms).
Include: dapapi.h
Usage: ulong GetTickTime ( void);
Input Parameters: None
Return Value: a time interval from system startup. It is by tick.
Link: dapapi.dll
Example: ulong sys_sec ;
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Remarks: The max. time interval is 2^32-1 tick. It is about 2734 days (about
7.5 years).
GetSysSec()
Description: Get a time interval from system startup. It is by second.
Include: dapapi.h
Usage: ulong GetSysSec( void);
Input Parameters: None
Return Value: a time interval from system startup. It is by second.
Link: dapapi.dll
Example: ulong sys_sec ;
sys_sec = GetSysSec();
Remarks: The max. time interval is 2^32-1 second. It is about 49710 days
(about 136 years).
This function is the same as GetSysTime()
GetSysTime()
Description: Get a time interval from system startup. It is by second.
Include: dapapi.h
Usage: ulong GetSysTime( void);
Input Parameters: None
Return Value: a time interval from system startup. It is by second.
Link: dapapi.dll
Example: ulong sys_sec ;
sys_sec = GetSysTime();
Remarks: The max. time interval is 2^32-1 second. It is about 49710 days
(about 136 years).
This function is the same as GetSysSec()
AddAccount()
Description: System provides some API to maintain user names and password.
This function is to add a user name and password. There are
maximum 4 user accounts which are kept in system.
Include: dapapi.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
DelAccount()
Description: This function is to delete a user account.
Include: dapapi.h
Usage: ushort DelAccount(char *name);
Input Parameters: name : a user name string
Return Value: 1 : delete successful
other: error, the user name not exist
Link: dapapi.dll
Example: …
ret=DelAccount( name);
if (ret==0) {
//error
}
else {
//ok
}
Remarks:
VerifyAccount()
Description: This function is to verify a user name and password.
Include: dapapi.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetESSID()
Description: Get the Extended Service Set ID
Include: dapapi.h
Usage: void GetESSID ( uchar *buf);
Input Parameters: buf: buffer for storing the extended service set ID
Return Value: None
Link: dapapi.dll
Example: GetESSID(buf);
Remarks: buf must be a characters array of 32 bytes
SetESSID()
Description: Set the Extended Service Set ID
Include: dapapi.h
Usage: void SetESSID ( uchar *buf);
Input Parameters: buf: buffer for setting the extended service set ID
Return Value: None
Link: dapapi.dll
Example: SetESSID(buf);
Remarks: buf must be a characters array of 32 bytes
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 7
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetFrame()
Description: Get frame length used for RTS/CTS handshake control
Include: dapapi.h
Usage: uint GetFrame (void);
Input Parameters: None
Return Value: Frame length
Link: dapapi.dll
Example: GetFrame();
Remarks: Default:2432
SetFrame()
Description: Set frame length used for RTS/CTS handshake control
Include: dapapi.h
Usage: void SetFrame (uint frame_size);
Input Parameters: Frame_size
Return Value: None
Link: dapapi.dll
Example: SetFrame(frame_size);
Remarks: Frame_size value is from 0..3000
GetFragment()
Description: Get fragment length for unicast message transmission
Include: dapapi.h
Usage: uint GetFragment (void);
Input Parameters: None
Return Value: Fragment length
Link: dapapi.dll
Example: GetFragment();
Remarks: Default:2346
SetFragment()
Description: Set fragment length for unicast message transmission
Include: dapapi.h
Usage: void SetFragment (uint fragment_size);
Input Parameters: Framment_size
Return Value: None
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Link: dapapi.dll
Example: SetFragment(fragment_size);
Remarks: Fragment_size value is from 256..2346
GetChannel()
Description: Get communication channel number for BSS creation
Include: dapapi.h
Usage: Uchar GetChannel (void);
Input Parameters: None
Return Value: Channel No., The value is from 1..14
Example: GetChannel();
Remarks: The default channel is 3.
SetChannel()
Description: Set communication channel number for BSS creation
Include: dapapi.h
Usage: void SetChannel (uchar channel_no);
Input Parameters: Channel_no
Return Value: None
Link: dapapi.dll
Example: SetChannel(channel_no);
Remarks: Channel_no value is from 1..14
GetNetWorkType()
Description: Get the topology of WLAN.
Include: dapapi.h
Usage: Uchar GetNetWorkType (void);
Input Parameters: None
Return Value: Network Type : 1:InfraStructure mode, 3:Ad-hoc mode;
Link: dapapi.dll
Example: ret = GetNetWorkType();
If (ret==1) {
/* infrastructure mode */
}
else {
/* ad-hoc mode */
}
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
SetNetWorkType()
Description: Set the topology of WLAN.
Include: dapapi.h
Usage: void SetNetWorkType (uchar networktype);
Input Parameters: Networktype : 1:InfraStructure mode, 4:Ad-hoc mode
Return Value: None
Link: dapapi.dll
Example: /* set to ad-hoc mode */
networktype = 4;
SetNetWorkType( networkrtype);
Remarks: Network Type : 1:InfraStructure mode, 4:Ad-hoc mode.
GetTransmitRate()
Description: Get data rate for message transmission
Include: dapapi.h
Usage: Uchar GetTransmitRate (void);
Input Parameters: None
Return Value: Transmit rate : 1:1Mb, 2:2Mb, 3:Auto 1/2, 4:5.5Mb, 8:11Mb, 15:Full Auto
Link: dapapi.dll
Example: Ret =n GetTransmitRate();
Remarks: The default is 15 (Full auto)
SetTransmitRate()
Description: Set data rate for message transmission
Include: dapapi.h
Usage: void SetTransmitRatee (uchar transmit_rate);
Input Parameters: Transmit_rate : 1,2,3,4,8 or 15
Return Value: None
Link: dapapi.dll
Example: SetTransmitRate(transmit_rate);
Remarks: Transmit Rate : 1:1Mb, 2:2Mb, 3:Auto 1/2, 4:5.5Mb, 8:11Mb, 15:Full Auto
GetXI300WEPFlag()
Description: Get WEP flag
Include: dapapi.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
SetXI300WEPFlag()
Description: Set WEP flag
Include: dapapi.h
Usage: void SetXI300WEPFlag(uchar type);
Input Parameters: WEP flag : 0,1,2,3,4
Return Value: None
Link: dapapi.dll
Example: SetXI300WEPFlag (wep_flag);
Remarks: WEP flag : 0:Disable WEP,
1 : use WEP 1
2 : use WEP 2
3 : use WEP 3
4: use WEP 4
GetXI300WEPBit()
Description: Get WEP bits
Include: dapapi.h
Usage: ushort GetXI300WEPBit(void);
Input Parameters: None
Return Value: WEP Bit : 0 : 64 Bits,
1 : 128 Bits
Link: dapapi.dll
Example: Wep_bits = GetXI300WEPBit ();
Remarks: Default:1
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
SetXI300WEPBit()
Description: Set WEP bits
Include: dapapi.h
Usage: void SetXI300WEPBit(uchar type);
Input Parameters: WEP bit : 0,1
Return Value: None
Link: dapapi.dll
Example: SetXI300WEPBit (WEP_Bit);
Remarks: WEP Bit : 0 : 64 Bits,
1 : 128 Bits
GetXI300WEPKey()
Description: Get WEP Key
Include: dapapi.h
Usage: void GetXI300WEPKey(ushort index, uchar *buf);
Input Parameters: index: the index of WEP Key, 1~4
buf : the buffer for storing the WEP Key
Return Value: None
Link: dapapi.dll
Example: GetXI300WEPKey( id, buf) ;
Remarks: WEP64 is 5-Byte data. WEP128 is 13-Byte data
Set XI300WEPKey()
Description: Set WEP Key
Include: dapapi.h
Usage: void void SetXI300WEPKey( ushort index, uchar *buf) ;
Input Parameters: index: index of WEP Key, 1~4
buf : the WEP Key being set
Return Value: None
Link: dapapi.dll
Example: /* if the WEP key is 64 bits, set the 2nd WEP key to “12345” */
SetXI300WEPKey( 2, “12345”);
Remarks: WEP64 is 5-Byte data, WEP128 is 13-Byte data
GetRFRealChannel()
Description: Get the RF channel when linking with Access Point
Include: dapapi.h
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetRFTXRate()
Description: Get the real transmission rate when linking with Access Point
Include: dapapi.h
Usage: int GetRFTxRate(void);
Input Parameters: None
Return Value: Transmit_rate : 1,2,3,4,8
Link: dapapi.dll
Example: GetRFTxRate ();
Remarks: Transmit Rate : 1:1Mb,2:2Mb,3:Auto 1/2,4:5.5Mb,8:11Mb,
GetAPName()
Description: Get the name of Access Point which linking with
Include: dapapi.h
Usage: void GetAPName(uchar * buf);
Input Parameters: buf: the AP name
Return Value: None
Link: dapapi.dll
Example: char buf[64] ;
GetAPName( buf);
Remarks:
GetAPMac()
Description: Get the MAC address of Access Point which linking with
Include: dapapi.h
Usage: void GetAPName(uchar * buf);
Input Parameters: buf:AP mac address
Return Value: None
Link: dapapi.dll
Example: char buf[64] ;
GetAPName( buf);
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Remarks:
LanRestart()
Description: Reset and restart the wireless LAN driver
Include: dapapi.h
Usage: void LanRestart(void);
Input Parameters: None
Return Value: None
Link: dapapi.dll
Example: LanRestart ();
Remarks:
WGetMacStatus()
Description: Get the WLAN connection status.
Include: dapapi.h
Usage: int WGetMacStatus(void);
Input Parameters: None
Return Value: = 1: Disabled
= 2: Searching for initial connection
= 3: Connected to IBSS
= 4: Connected to ESS
= 5: Out of Range
others: unknown error
Link: dapapi.dll
Example: Ret = WGetMacStatus();
Remarks:
WGetBssQuality()
Description: Get communication quality of the WLAN.
Include: dapapi.h
Usage: unsigned short * WGetBssQuality(void);
Input Parameters: None
Return Value: The return value is an unsigned short pointer to a 2 word array.
The 1st word is the communication quality. Its range is from 0 to 92.
The 2nd word is the signal strength. Its range is from 27 to 154.
Link: dapapi.dll
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
GetCountry()
Description: About WLAN, different countries have different legal channels. When
manufacturing, every device was assigned a country code which can be use
to decide legal channels.
Include: dapapi.h
Usage: int GetCountry(void);
Input Parameters: None
Return Value: = 0: USA
= 1: Europe
= 2: Japan
= 3: France
= 4: Spain
others: unknown error
Link: dapapi.dll
Example: ret = GetCountry();
Remarks:
GetLegalChannel()
Description: About WLAN, different countries have different legal channels. When
manufacturing, every device was assigned a country code which can be
used to decide legal channels.
Include: dapapi.h
Usage: unsigned short GetLegalChannel( int country_code);
Input Parameters: country_code: this is gotten from GetCountry()
Return Value: The return value is a 16 bits unsigned short. Each bit represents a channel.
The bit 0 to bit 13 is as channel 1 to channel 14.
country_code= 0: USA, channel 1-11, return value=0x7FF
country_code = 1: Europe, channel 1-13, return value=0x1FFF
country_code = 2: Japan, channel 1-14, return value=0x3FFF
country_code = 3: France, channel 10-13, return value=0x1E00
country_code = 4: Spain, channel 10-11, return value=0x600
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Link: dapapi.dll
Example: ret = GetLegalChannel( 2); /* get the legal channels of Japan */
Remarks: Followings are legal channels of countries:
USA:1-11, Europe:1-13, Japan:1-14, France:10-13, Spain:10-11
WscanRequest()
Description: Request to scan Basic Service Set (BSS). In general it is to search Access
Points (AP).
Include: dapapi.h
Usage: Int WScanRequest( unsigned short *buf, int buf_size);
Input Parameters: buf : address of an unsigned short array for storing responded Access
Points information.
buf_size: count of the unsigned short array. The byte count of the array is
buf_size * 2.
Return Value: <0 : this request is failed. Maybe the previous request is still pending.
>=0: system accepts this request..
Link: dapapi.dll
Example:
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Remarks: After calling this function, you must call WscanReady() continually to check
the result is ready or not. When it is ready, the buf will be stored following
data:
Word offset Field description Size(words)
0 Data length= 3+31*n, (n=0,1…) 1
1 reserved 3
4 The 1st AP information 31
WscanReady()
Description: Check the searching Access Points request WscanRequest() is finished or
not.
Include: dapapi.h
Usage: Int WScanReady();
Input Parameters: None
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 8
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Step 1: Prepare a PC with Windows 95/98/NT/2000 and the GW21x-MAXI you wish to upgrade
the firmware and make sure they are all connected in the same TCP/IP network. Use
command ping or monitor.exe utility program to ensure their availability.
Step 2: Get the new version of software for the GW21x-MAXI. The new program (.HEX file) that
you want to download to the GW21x-MAXI should be found in the product CD or
diskette along with the shipping package or can be obtained from ATOP’s Web site.
Step 3: Prepare the download tool. The utility program gwdl.exe and its configuration file
dapdl.cfg can be found in the GW21x-MAXI product CD or diskette or from ATOP’s Web
site.
Step 4: Edit the "dapdl.cfg" file to fit your system and configurations. The format of the file
looks like the following. Be sure to save your modifications.
Remote_IP 10.0.21.128
Load Gw21Lterm23.hex
The first line identifies the IP address of GW21x-MAXI you want to download new
software to. The second line identifies the file name of to be downloaded.
Step 5: Execute the download utility program. Please go to Windows command mode or from
Windows, select the Run command in the Start menu and specify correct file path, then
execute the command <file_path>\gwdl dapdl.cfg.
Step 6: Type in user name and the password. After execute the download utility program, please
type in user name and the password as the following screen and new firmware will be
downloaded.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Step 7: Restart the GW21x-MAXI. The GW21x-MAXI will restart automatically each time the
program is successfully downloaded.
2. If the GW21x-MAXI does not receive any upgrade data within 30 seconds during process, the
GW21x-MAXI will restart itself automatically and the system remains intact.
3. After the upgrading process is finished, the GW21x-MAXI will program the flash memory.
During programming the flash memory, the GW21x-MAXI will clear the corresponding
memory and reset itself once an error occurs.
If everything is OK, the GW21x-MAXI's RUN LED blinks 3 times. It will then restart.
Normally, it will take around 10 seconds to complete programming the flash memory.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
*You can use the 'telnet' utility to test this sample program
--------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include "..\..\inc\gw_api.h"
#define MY_PORT 23
#define DEF_MSS 512
#define _OK 0
#define _ERR 1
#define _WAITING 2
#define NULL_ARG (char far *)0
int handle;
int conn_state ;
int connect_f = _ERR ;
void _loadds far send_post( CMDBLK far *cb, void far *arg) ;
void _loadds far listen_post( CMDBLK far *cb, void far *arg) ;
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
main()
{
int i, j, ret, free_cnt, loop_cnt ;
char *ptr ;
char tmpbuf[ 80+256] ;
unsigned long tmp_sec ;
conn_state = CONN_STATE_CLOSE ;
loop_cnt = 100 ;
handle = -1 ;
while(1)
{
if ( ++loop_cnt >= 10) /* to decrease the checking time count */
{
loop_cnt = 0 ;
tmp_sec = GetSysSec() ;
if ( tmp_sec != now_sec)
{
now_sec = tmp_sec ;
sprintf( tmpbuf, "tcp_getdata(), sec=%ld", now_sec) ;
SetAPSerialNo( tmpbuf); /*set AP version */
}
}
switch( conn_state)
{
case CONN_STATE_CLOSE:
conn_state = CONN_STATE_LISTEN ;
connect_f = _WAITING ;
ret = tcp_listen( (int far *)&handle, MY_PORT, listen_post, 0);
if ( ret != SUCCESS) /*fatal err */
{
SetAPSerialNo( "tcp_listen err"); /*set AP version */
/*wait a moment */
conn_state = CONN_STATE_IDLE ;
old_sec = now_sec ;
}
break ;
case CONN_STATE_IDLE:
if ( now_sec-old_sec >= 1)
{
conn_state = CONN_STATE_CLOSE ;
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
}
break ;
case CONN_STATE_FAIL:
if ( handle != -1)
{
tcp_disconnect( handle) ; /*diconnect */
handle = -1 ;
}
conn_state = CONN_STATE_IDLE ;
old_sec = now_sec ;
break ;
case CONN_STATE_LISTEN:
if ( connect_f==_OK) /*listen ok */
{
conn_state = CONN_STATE_CONNECTED ;
/*send a message after connecting */
ptr = "Hello, this is GW21 series\r\n" ;
ret = tcp_send( handle, ptr, strlen(ptr), send_post, NULL_ARG);
if ( ret != SUCCESS) /*if connection failed */
{
conn_state = CONN_STATE_FAIL ;
break ;
}
}
else
if ( connect_f==_ERR) /*listen err */
{
conn_state = CONN_STATE_FAIL ;
break ;
}
else
{
/*do nothing to wait listen ok */
}
break ;
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
default:
break ;
} /*---switch() */
} /*---while() */
}
void _loadds far send_post( CMDBLK far *cb, void far *arg)
{
/*----- check send success or not */
if( cb->retcode != SUCCESS ) {
connect_f = _ERR;
return;
}
}
void _loadds far listen_post( CMDBLK far *cb, void far *arg)
{
/*----- check listen success or not */
if( cb->retcode != SUCCESS ) {
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
connect_f = _ERR ;
return;
}
connect_f = _OK;
}
int ldumps2( unsigned char *dstbuf, unsigned char *srcbuf, int cnt, int auto_linefeed)
{
int i, k ;
*You can use the 'terminal' utility to test this sample program
-------------------------------------------------------------------------------------------------------*/
#include "dapapi.h"
#include "comapi.h"
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 9
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
//=============================================================
void main()
{
int i, com_port, cnt ;
int ret;
char buf[ 256], *ptr ;
com_port = 0 ; // 0:COM1
ret = Com_Config( com_port, 9600L, 0, 8, 1) ; //open com port: 9600,n,8,1
if (ret != 0)
{
//com port open error
}
COM_DTR_Active( com_port, 1); //set com port to be communication ready (for h/w
handshaking)
COM_RTS_Active( com_port, 1); //set com port to be send ready (for h/w handshaking)
while(1)
{
cnt = 256 ;
ret = Com_GetBuf( com_port, buf, cnt) ; //receive data from com port
if (ret>0) {
cnt = ret ;
ptr = "\r\nReceive data=" ;
Com_PutBuf( com_port, ptr, strlen(ptr)) ; //send data to com port
Com_PutBuf( com_port, buf, cnt) ; //send data to com port
}
};
}
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
Display Description
The following table lists the functional descriptions for all the fields.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
4. Click on the Invite button. This will display all the controllers and devices information you
have requested.
1. Repeat the steps in the section of D.2 Detecting Operational Controllers and Devices to bring
up controllers information.
2. Select the controller you want to configure from the IP Address column. Click on the Config
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249
GW21x series SDK Guide
3. Fill in information in the box along with the Password for the device and click on Config it to
save the change or Cancel to abort. The default password is null. You can press the reset key of
product to reset password to the default value.
4. The target controller will return an ACK message indicating the modification is successfully
modified.
ATOP Technologies, Inc., Suite 305, No. 47 Park Avenue II, Science-Based Industrial Park, Hsinchu, Taiwan, R.O. C 1
Tel:+886 3 578 1962 Fax:+886 3 578 4249