FORGE 8 Series AG OCX
Programming Guide
DOC Version 1.00
Copyright © 2008 ~ 2009 CIPHERLAB CO.,LTD.
All rights reserved.
The software contains proprietary information of CIPHERLAB CO., LTD.; it is provided
under a license agreement containing restrictions on use and disclosure and is also
protected by copyright law. Reverse engineering of the software is prohibited.
Due to continued product development this information may change without notice. The
information and intellectual property contained herein is confidential between CIPHERLAB
and the client and remains the exclusive property of CIPHERLAB CO., LTD. If you find
any problems in the documentation, please report them to us in writing. CIPHERLAB
does not warrant that this document is error-free.
No part of this publication may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, electronic, mechanical, photocopying,
recording or otherwise without the prior written permission of CIPHERLAB CO., LTD.
For product consultancy and technical support, please contact your local sales
representative. Also, you may visit our web site for more information.
The CipherLab logo is a registered trademark of CIPHERLAB CO., LTD.
Microsoft, Windows, and the Windows logo are registered trademarks of Microsoft
Corporation in the United States and/or other countries.
Bluetooth is a trademark of Bluetooth SIG, Inc., U.S.A.
Other product names mentioned in this manual may be trademarks or registered
trademarks of their respective companies and are hereby acknowledged.
The editorial use of these names is for identification as well as to the benefit of the
owners, with no intention of infringement.
CIPHERLAB CO., LTD.
Website: http://www.cipherlab.com
RELEASE NOTES
Version Date Notes
1.00 Feb. 26, 2009 Initial Release.
CONTENTS
RELEASE NOTES.......................................................................................- 3 -
INTRODUCTION........................................................................................... 1
REGISTER OCX............................................................................................ 3
INCLUDE OCX INTO VS 2005 PROJECT .............................................................. 5
PROPERTIES .............................................................................................. 7
METHODS.................................................................................................. 9
ERROR CODE DESCRIPTION ........................................................................... 11
VC++ SAMPLE CODE FOR READ/DOWNLOAD FILE VIA RS232, COM1 AND 115200......... 13
INTRODUCTION
The purpose of Forge 8 series AG OCX is to simplify complex data transmission protocol
to concise API call approach to provide convenient way for programmer to develop
program to transmit data between PC and terminal with Forge 8 series AG runtime.
This manual briefly describes what the properties’ and methods’ function provided by
OCX at chapter 1, 2 and 3 and further how to use them at chapter 4. We recommend
that you read the document thoroughly before use and keep it at hand for quick
reference.
Thank you for choosing CipherLab products!
1
FORGE 8 Series AG OCX Programming Guide
2
Chapter 1
REGISTER OCX
For correctly programming with CipherLab 8 series AG OCX component, please register
OCX component first. Run “Regsvr32 [path\]CipherAGB.ocx” in command line to register
OCX. [path\] indicate the path of CipherAGB.ocx file.
3
FORGE 8 Series AG OCX Programming Guide
4
Chapter 2
INCLUDE OCX INTO VS 2005 PROJECT
Right click on Toolbox panel and Toolbox menu will appear as picture 1. Click “Choose
Item” menu item and “Choose Toolbox Items” appeared as picture 2.
Picture 1
Select COM Components tab and check CipherAGB Control, then click “OK” button and
CipherAGB OCX will be included into project as picture 3.
5
FORGE 8 Series AG OCX Programming Guide
Picture 2
Picture 3
6
Chapter 3
PROPERTIES
The programmer must finish setting the communication properties Port, BaudRate and
Timeout settings in advance, so as to operate the method functions in the Chapter 4
correctly.
1. Port: the port number for Serial or TCP communication
2. BaudRate: the transmission rate for serial communication
3. Timeout: the connection waiting time-out
The VB/C# programmer can assign the appropriate value to the object property directly,
so as to finish the property settings. The C++ programmer can set the relative properties
by the property functions illustrated below. The valid property value range is described in
the property functions.
SetPort
Purpose Set the port number for Serial or TCP communication.
Syntax Void SetPort(long nPortNo);
Parameter nPortNo
Serial or TCP communication port, valid value from 1 to 65,535, 1 is default.
Return value None
See also GetPort
GetPort
Purpose Get current serial or TCP/IP communication port number.
Syntax long GetPort();
Parameter None
Return value Return serial or TCP/IP communication port number.
See also SetPort
SetBaudRate
Purpose To set transmission rate for serial communication
Syntax void SetBaudRate(long nBaudRate);
Parameter nBaudRate
transmission baud rate, supported baud rates are 115200, 57600, 38400,
19200, 9600, 115200 is default
Return value None
Remark This property is available only for serial communication, including RS232,
Cradle-IR and Modem.
7
FORGE 8 Series AG OCX Programming Guide
See also GetBaudRate
GetBaudRate
Purpose To get serial transmission baud rate setting
Syntax long GetBaudRate();
Return value Return transmission baud rate setting
See also SetBaudRate
SetTimeout
Purpose To set connection waiting time-out
Syntax void SetTimeout(long nTimeout);
Parameter nTimeout
connection timeout, valid value from 1 to 65,535 second, 15 second is default
Return value None
See also GetTimeout
GetTimeout
Purpose To get connection timeout setting
Syntax long GetTimeout();
Return value Return connection timeout setting, valid range from 1 to 65,535.
See also SetTimeout
8
Chapter 4
METHODS
InitConnection
Purpose Initialize a connection according to link type.
Syntax long InitConnection(long nLinkType);
Parameter nLinkType
link type, 0:RS232, 1:Cradle-IR, 2:Modem, 3:Ethernet
Return Value >0 indicates successfully initialize a connection, otherwise, indicate error
occurs on initialization period and the below error code will be returned.
Properties Error -1201 (Invalid communication port assigned)
-1202 (Invalid Timeout value assigned)
RS232/Cradle/Modem -1004 (Communication port does not exist)
Error
-1005 (Communication interface access denied)
-1006 (Open Comm error)
Modem Error -1000 (Initialize Communication error)
Ethernet Error -1000 (Initialize Communication error)
See Also CloseConnection
CloseConnection
Purpose Close opened connection
Syntax void CloseConnection();
Parameter None
Return Value None
See Also InitConnection
ReadFile
Purpose To receive data from terminal
Syntax long ReadFile(LPCTSTR sTargetFile);
Parameter sTargetFile
target file path.
Return Value >=0 indicates successfully receive terminal records and record count returned,
otherwise, indicate error occurs during receiving terminal data and the below
error code will be returned.
Properties Error -1200 (Link type error)
9
FORGE 8 Series AG OCX Programming Guide
RS232/Cradle/Modem -1003 (Communication Timeout)
Error
-1008 (Cradle-IR Device error)
-1100 (Open file error)
-1101 (Communication error)
Ethernet Error -1001 (Socket error)
-1002 (Program error)
-1003 (Communication Timeout)
-1100 (Open file error)
See Also DownloadFile
DownloadFile
Purpose To download lookup file from PC to terminal, only RS232, Cradle-IR and Modem
supported.
Syntax long DownloadFile(LPCTSTR sSourceFile);
Parameter sSourceFile
source file path.
Return Value >0 indicates successfully download file to terminal, otherwise, indicates error
occurs during downloading file and the below error code will be returned.
Properties Error -1200 (Link type error)
RS232/Cradle/Modem -1003 (Communication Timeout)
Error
-1008 (Cradle-IR Device error)
-1100 (Open file error)
-1101 (Communication error)
See Also ReadFile
10
Appendix I
ERROR CODE DESCRIPTION
Error Code Description
-1000 Initialize modem or TCPIP error.
-1001 Create socket error.
-1002 Create thread error.
-1003 Wait response timeout
-1004 Specified com port does not exist.
-1005 Com port resource is pending and can’t be opened.
-1006 Open com port error except error -1004 and -1005
-1007 Com port is not opened before transmitting data.
-1008 Fail to initialize Cradle-IR device
-1100 Fail to open target or source file
-1101 Transmit data error.
-1200 Specified link type is not supported, for example, the DownloadFile() function
does not support file download via Ethernet or invalid value assigned.
-1201 Invalid port number assigned, for example, 0 or minus value.
-1202 Invalid timeout value assigned, for example, 0 or minus value.
11
FORGE 8 Series AG OCX Programming Guide
12
Appendix II
VC++ SAMPLE CODE FOR READ/DOWNLOAD FILE
VIA RS232, COM1 AND 115200
CCipherAGBctrl1 CipherAGB; // To create CipherAGB object
BOOL AGBOcxTransmission()
{
CipherAGB.SetPort(1); // Transmit data via COM1
CipherAGB.SetBaudRate(115200); // Transmission rate, 115200 bps
CipherAGB.SetTimeout(15); // Connection timeout, 15 seconds
if (CipherAGB.InitConnection(0) < 0) // initialize RS-232 connection
{
MessageBox ("Inititializing connection error!", "Error", MB_OK | MB_ICONEXCLAMATION);
CipherAGB.CloseConnection();
return FALSE;
}
// To recieve data from terminal and save to file lookup.txt
int rdcount = CipherAGB.ReadFile("C:\\lookup.txt");
if (rdcount >= 0)
{
TCHAR msg[100];
ZeroMemory(msg, sizeof(msg));
wsprintf(msg, "Total %d records recieved!", rdcount);
MessageBox (msg, "Complete", MB_OK | MB_ICONINFORMATION);
}
else
{
MessageBox ("Failed to receive data from terminal!", "Error", MB_OK | MB_ICONEXCLAMATION);
CipherAGB.CloseConnection();
return FALSE;
}
// To download file lookup.txt to terminal
// if (CipherAGB.DownloadFile("C:\\lookup.txt") > 0)
// MessageBox ("Send file complete", "Complete", MB_OK | MB_ICONINFORMATION);
// else
// {
// MessageBox ("Failed to send file to terminal!", "Error", MB_OK | MB_ICONEXCLAMATION);
// CipherAGB.CloseConnection();
// return FALSE;
// }
CipherAGB.CloseConnection();
return TRUE; // return TRUE
}
13