Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeEnglishEspañolContact

The text of a manual · part 30 of 40

2D JANUS PSK for C/C++ Reference Manual, pages 291 to 300

Pages 291 to 300 of 400

The original document is the PDF (793 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Intermec J2020, Intermec J2010 and Intermec J2050

Page 291

Using the PSK With DCM

5 im_parse_host_response Return Codes Request Type Parameter

Return Code

Description

All

1A10

Received message

5A11

Data was truncated

5A12

Too many fields

1A01

Transaction success, ACK

5A02

Transaction failed, NAK

9A04

Receive port timeout

9A05

Packet header error

Request Type Parameter

Return Code

Description

All

1A00

Protocol parameters set successfully

9A08

Standby file I/O error, check system errno value im_setup_trx Return Codes

Standby file format is wrong

5-11

Page 292

2D JANUS PSK for C/C++ Reference Manual

Return Codes Listed in Numerical Order The following tables list the return codes for each DCM function in numerical order.

im_standard_trx Return Codes Return code

Severity

Description

1A00

00 Success

Action successful

1A01

00 Success

Transaction successful, ACK received

1A10

00 Success

Received message on Read operation

5A02

01 Warning

Transaction failed, NAK received. If im_dobest_enable is not set, then stop sending records.

5A07

01 Warning

Standby file is empty

5A11

01 Warning

Data was truncated

5A12

01 Warning

Too many fields

5A20

01 Warning

Record stored in standby file successfully

5A21

01 Warning

Record stored in standby file, but upload standby error

9A03

10 Error

Transmit failed

9A04

10 Error

Receive port timeout

9A05

10 Error

Packet header error

9A06

10 Error

Missing transaction ID

9A08

10 Error

Standby file I/O error

9A09

10 Error

Standby file is missing

9A40

10 Error

Buffer overflow

9A41

10 Error

Buffer overflow with upload standby error

5-12

Page 293

Using the PSK With DCM

5 im_parse_host_response Return Codes Return code

Severity

Description

1A01

00 Success

Transaction success, ACK

1A10

00 Success

Received message

5A02

01 Warning

Transaction failed, NAK

5A11

01 Warning

Data was truncated

5A12

01 Warning

Too many fields

9A04

10 Error

Receive port timeout

9A05

10 Error

Packet header error im_setup_trx Return Codes Return code

Severity

Description

1A00

00 Success

Protocol parameters set successfully

9A08

10 Error

Standby file I/O error, check system errno value Standby file format is wrong

5-13

Page 294

2D JANUS PSK for C/C++ Reference Manual

Symbolic Return Codes This table lists the return codes for all three DCM functions. Return Code

Hex Value

Description

IM_DCM_OK

1A00

Execution success

IM_DCM_ACK_RCD

1A01

ACK received

IM_DCM_MSG_RCD

1A10

Data received

IM_DCM_NAK_RCD

5A02

NAK received

IM_DCM_NO_RECORD

5A07

No more log records

IM_DCM_TRUNCATED

5A11

Received data truncated

IM_DCM_EXCESSFIELD

5A12

Fields overflow

IM_DCM_STANDBY

5A20

Record logged

IM_DCM_STANDBY_TXERR

5A21

Logged but upload error

IM_DCM_NOTRANSMIT

9A03

Transmit fails

IM_DCM_TIMEOUT

9A04

Receive timeout

IM_DCM_HEAD_ERR

9A05

Packet header error

IM_DCM_TRANSID_ERR

9A06

Transaction ID is missing

IM_DCM_NO_HANDLE

9A08

Standby file is missing

IM_DCM_FILE_ERR

9A09

Standby file I/O error

IM_DCM_FILLED

9A40

Buffer overflow

IM_DCM_FILLED_TXERR

9A41

Buffer overflow and upload error

5-14

Page 295

Using the PSK With DCM

5

Using a Standby File The im_setup_trx function supports using a standby file to store records when the transmit channel is unavailable. For example, you may use the JANUS reader to collect inventory data from a warehouse. The reader stores the records until you set it in the communications dock and then transmits the standby records to a database. By default, the standby file is not activated, so your application program must handle activating and deactivating the standby file. You activate the standby file by opening a file and passing the file handle as the hsafety parameter of im_setup_trx. You deactivate the standby file by passing 0 for the hsafety parameter. For more information on the im_setup_trx parameters, see Chapter 2, “C Language Support.” Your application must open and close the standby file in low level file I/O open() with binary mode and readable/writeable mode. For example, you may open a file named standby.txt as follows: handle = open("standby.txt", O_CREAT | O_BINARY | O_RDWR, S_IREAD | S_IWRITE); When you pass the standby file handle the first time after creating the file, im_setup_trx initializes the standby file with the correct format for you.

5-15

Page 296

2D JANUS PSK for C/C++ Reference Manual

Standby File Structure This section provides detailed file structure information for troubleshooting. Usually you do not need this level of detail. The PSK library functions and the following open statement create the correct file. handle = open("standby.txt", O_CREAT | O_BINARY | O_RDWR, S_IREAD | S_IWRITE); The first 14 bytes of the standby file are the file header. The remainder of the file contains records. The following figure shows the header structure. The first 4 bytes of header is the read pointer and the next 4 bytes of header is the write pointer. The next 4 bytes are reserved for future use. The last 2 bytes of the header are two $ characters that identify this file as a standby file. Read pointer

Byte

0 1

Write pointer

2 3 4

5

Reserved

Record Length

Data

Terminator

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... NULL $ $ JPSK.004

Each record starts with 2 bytes for length of the record. Each record is variable length and ends with a null character. If you activate the standby file and the file length is zero, the standby file is initialized with a header but no records. If the file length is not zero (0), the file header is read. Each record logged to the standby file is written at the byte specified by the write pointer. After the new record is written, the write pointer in the header is updated. When the transmit channel is available again, the logged records are uploaded. As each record is read for uploading, the read pointer in the header is updated. When all the records have been sent, the read pointer reaches the write pointer. Then the file is reset to the initial state, which has only the 14 byte header in the file.

5-16

Page 297

Using the PSK With DCM

5

The standby file retains data between program runs. You can exit your application or reboot the reader without losing data. However, if you reboot the reader while an application is running, the standby file may contain corrupt data. In this case you need to delete the standby file so that the next application will run correctly. To simplify error trapping, you do not need to use a standby file when you first design an application that uses DCM’s database server. After you test the application design for the database server protocol and accessing the database, then put the standby file function into the program. In this way, you can avoid the confusion of deciphering too many error return codes.

Sample Program //********************im_setup_trx **************************************** //********************im_standard_trx **************************************** //********************im_parse_host_response ********************************* // This program demonstrates the PSK's DCM support functions. // // First, it discards any records left in the database server queue by a // previous read transaction. // Second, it deletes all records from the BONUS table. // Third, it uses the batch capability to store 5 records in the // standby file, and then write the 5 records to the database. // Fourth, it writes the remaining records in the reader without batching them. // Fifth, it reads records from the database without pacing and then with pacing. // Sixth, it demostrates how to discard records after reading the first // 3 records. // // The program is divided into the following routines: // DemoInit() - Initializes the database server // DemoBatch() - Shows the batch process case // DemoStandby() - Shows the standby file capability // HandNoPace() - Reads records with handshaking and no pacing protocol // HandPace() - Reads records with handshaking and pacing protocol // HandDiscard() - Reads 3 records and then discards the rest of records. // // Note: You must load reader services and a protocol handler on the JANUS reader // to enable send/receive buffer functions. // Run these TSR's at DOS prompt before running this program: // rservice // phimec 1 ( 1 is COM1) // On the DCM side, you need to set up database table access and the TSTDEL, // TSTINS, TSTRD transactions. //**************************************************************************** #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <dos.h> #include <string.h> #include <fcntl.h>

5-17

Page 298

2D JANUS PSK for C/C++ Reference Manual

#include <io.h> #include <sys\stat.h> #include "imgenric.h" #include "im20lib.h" typedef struct BonusType { char *emp; char *dept; char *salgrade; char *end; } BONUSTYPE;

//Mapped to BONUS table's NAME column //Mapped to BONUS table's DEPT column //Mapped to BONUS table's SALGRADE column static BONUSTYPE EmpTable[] ={ {"Steve Chan", "Network", "1", NULL}, {"Stuart Bainey", "Software", "2", NULL}, {"Trixie Austin", "Hardware", "3", NULL}, {"Marcus Albrod", "Portable", "4", NULL}, {"Jeff Eastone", "Network", "5", NULL}, {"Roy Christoff", "Software", "6", NULL}, {"KK Luang", "Hardware", "7", NULL}, {"Joe Arant", "Portable", "8", NULL}, {"Matt Hartinger", "Network", "9", NULL}, {"Tom Dard", "Software", "10", NULL}, {"Ted Millen", "Hardware", "11", NULL}, {"Robert Chian", "Portable", "12", NULL}, {"Doug Kaatz", "Network", "13", NULL}, {"RuthAnn Hso", "Software", "14", NULL}, {"Will Powers", "Hardware", "15", NULL}, {"Kevin Cuffman", "Portable", "16", NULL}, {"C. K. Koonze", "Network", "17", NULL}, {"Ray Law", "Software", "18", NULL}, {"Mark Robinns", "Hardware", "19", NULL}, {"Cathy McCree", "Portable", "20", NULL}, {"Shar Leung", "Network", "21", NULL}, {"Jack Lincoln", "Software", "22", NULL}, {"Joe Schoening", "Hardware", "23", NULL}, {"Bill McDowell", "Portable", "24", NULL}, {"Sophia Renouard", "Network", "25", NULL}, {"Yong Qin Lee", "Software", "26", NULL}, {"Joe Waters", "Hardware", "27", NULL}, {"Paul Swann", "Portable", "28", NULL}, {"Mack Pickett", "Network", "29", NULL}, {"Raymond Wallice", "Software", "30", NULL}, {"Delanie Zerbi", "Hardware", "31", NULL}, {"Lisa Vanian", "Portable", "32", NULL}, {NULL, NULL, NULL, NULL} };

static IM_COM_PORT IM_UCHAR iPort = IM_COM1;

chOperation = 'R';

/* Uses communications port 1*/ //'W', ' Operation char

#define FLDSIZE 16 static char pszEmployee[FLDSIZE+1]="\0"; //Buffer mapped to Employee static char pszDepart[FLDSIZE+1]="\0"; //Buffer mapped to department static char pszSalary[FLDSIZE+1]="\0"; //Buffer mapped to Salary grade static char pszDummy[FLDSIZE+1]="\0"; //Buffer mapped to dummy

5-18

Page 299

Using the PSK With DCM

5

//data structure to get fields from packet. static IM_DCMSTRN pszGetData[] = { { pszEmployee, sizeof(pszEmployee)}, { pszDepart, sizeof(pszDepart)}, { pszSalary, sizeof(pszSalary)}, { pszDummy, sizeof(pszDummy)}, { NULL, 0} }; #define DEPT_NUM

4

//Number of dempartments static char *pszReadSoftware[] ={"Software", NULL}; static char *pszReadHardware[] ={"Hardware", NULL}; static char *pszReadNetwork[] ={"Network", NULL}; static char *pszReadPortable[] ={"Portable", NULL}; static char **pszRead[DEPT_NUM + 1] = { pszReadNetwork, pszReadSoftware, pszReadHardware, pszReadPortable, NULL }; static IM_UCHAR pszInString[257];

// pointer to output string static char static int standby[]="standby.bin"; standby_fh = 0;

//Standby file name void DemoInit(void ); void DemoBatch(void ); void DemoStandby(void ); void HandNoPace(void); void HandPace(void); void HandDiscard(void); /***************************************************************************/ void main (void) { //Always open standby file for use if ( (standby_fh = open(standby, O_CREAT | O_BINARY |O_RDWR, S_IREAD|S_IWRITE)) == -1) { printf("open file error\n"); exit(1); } //Send IM_DBRQT_DISCARD to discard all records left over from database server DemoInit(); //Use IM_BATCH_ENABLE to delete all records in BONUS table DemoBatch(); //Use standby function to insert records to BONUS table DemoStandby(); //Using handshaking with no pacing protocol //Read records that match dept criteria, using a FOR loop without pacing HandNoPace();

5-19

Page 300

2D JANUS PSK for C/C++ Reference Manual

//Using handshaking with pacing protocol //Read records that match dept criteria, using a FOR loop with pacing HandPace(); //Using handshaking with pacing protocol //Read 3 records that match dept criteria, and then discard the rest of records HandDiscard(); } //********************************************************************* // Initialize database access. // First, read data from communications port until timeout occurs, which // means no more data received. // Use TSTRD with IM_DBRQT_DISCARD to discard any records left in // the database. //********************************************************************* void DemoInit(void) { IM_USHORT status; IM_USHORT actual_length = 0; IM_USHORT iDBPrtcl; IM_UCHAR com_buff[257];

// handshake, pace, request type // Buffer for receiving

//Flush out all packets left from previous session. im_cancel_rx_buffer(iPort); //Clear buffer //Read data until timeout occurs do { status = im_receive_buffer(iPort, sizeof(com_buff)-1, com_buff, 3000, &actual_length); if (status == 0x0600 && actual_length > 0) printf("%s\n", com_buff); } while ( status != 0x4601);

iDBPrtcl = IM_DBPACE_ENABLE; //Set up communications port and protocol status = im_setup_trx(iPort, 240, IM_INFINITE_TIMEOUT, iDBPrtcl, ',', ',', 256, standby_fh); if (status != IM_DCM_OK) printf("error: %x\n", status); do { //Send discard transaction to the database server. status = im_standard_trx(RedpszTid, IM_DBRQT_DISCARD, NULL, 256, pszInString, pszGetData, &chOperation); if (status != IM_DCM_ACK_RCD && status != IM_DCM_NAK_RCD ) printf("Init error: %x\n", status); } while ( status != IM_DCM_NAK_RCD && status != IM_DCM_ACK_RCD); printf("\nInit Complete!\n");

5-20