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 31 of 42

JANUS PSK for C/C++ Reference Manual, Version 2.1, pages 301 to 310

Pages 301 to 310 of 414

The original document is the PDF (690 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 301

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 302

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

Page 303

Using the PSK With DCM

5

//Wait for 1 second (optional) im_standby_wait(1000); } //********************************************************************* //Demostrate batch process to clean up the database table. // Log records into the standby file, and then flush them. // Use TSTDEL to delete all records from BONUS table. // Use IM_BATCH_ENABLE to log transactions, then process in batch mode //********************************************************************* void DemoBatch(void) { BONUSTYPE *pszBonus; IM_USHORT status; IM_USHORT del_status; IM_USHORT iDBPrtcl; IM_UCHAR pszTid[8]="TSTDEL";

// handshake, pace, request type //delete transaction

//Turn on batch process iDBPrtcl = IM_BATCH_ENABLE + IM_DBPACE_ENABLE; status = im_setup_trx(iPort, 240, IM_INFINITE_TIMEOUT, iDBPrtcl, ',', NULL, ',', 256, standby_fh); if (status != IM_DCM_OK) printf("Batch setup error: %x\n", status); //Send all records first pszBonus = EmpTable; while (pszBonus->emp != NULL) { status = im_standard_trx(pszTid, IM_DBRQT_DATA, pszBonus, 256, pszInString, pszGetData, &chOperation); //It will receive IM_DCM_STANDBY, because IM_BATCH_ENABLE is on if (status != IM_DCM_STANDBY) printf("Standby error: %x\n", status); pszBonus++;

//go to next record

} //Flush standby records do { //Continue flushing standby records until receive IM_DCM_OK status = im_standard_trx(pszTid, IM_ZIP_RECORD, pszBonus, 256, pszInString, pszGetData, &chOperation); //If the TSTDEL transaction deletes a record in table, then reader receives // ACK and im_standard_trx() continues sending logged records until the // standby file is empty. When the file is empty, the function returns // IM_DCM_OK. // If the database table has no records, then the DCM TSTDEL transaction sends

5-21

Page 304

JANUS PSK for C/C++ Reference Manual

// NAK to the reader. im_standard_trx() returns IM_DCM_NAK_RCD and any records // remain in the standby file. Use IM_ADVANCE_RECORD to discard any // remaining records in the standby file. // If IM_DOBEST_ENABLE is on, then do not check for IM_DCM_NAK_RCD. // im_standard_trx() treats NAK the same as ACK and uploads the next record. if (status == IM_DCM_NAK_RCD) { printf("NAK: %s\n", pszInString); //See which record is //Skip this TSTDEL transaction because no records in database table. del_status = im_standard_trx(pszTid, IM_ADVANCE_RECORD, pszBonus, 256, pszInString,pszGetData, &chOperation); //If Error occurs, print it if (del_status != IM_DCM_OK) printf("%x\n", del_status); } } while (status != IM_DCM_OK); printf("\nDelete Complete!\n"); } //************************************************************************ //Demostrate standby functionality. // Use TSTINS transaction to insert all records into the BONUS table // using a standby file. // Use batch process to log five transactions, then turn off batch process // and send remaining transactions in normal mode. Upload all standby // records before sending current record. //************************************************************************ void DemoStandby(void) { IM_USHORT i; BONUSTYPE *pszBonus; IM_USHORT status; IM_USHORT iDBPrtcl; IM_UCHAR pszTid[8]="TSTINS"; //Turn on Batch process iDBPrtcl = IM_BATCH_ENABLE

// handshake, pace, request type //delete transaction.

+ IM_DBPACE_ENABLE;

status = im_setup_trx(iPort, 240, IM_INFINITE_TIMEOUT, iDBPrtcl, ',', ',', 256, standby_fh); if (status != IM_DCM_OK) printf("error: %x\n", status); //Process 5 records in batch mode pszBonus = EmpTable; for (i= 0; i < 5; i++) { status = im_standard_trx(pszTid, IM_DBRQT_DATA, pszBonus, 256, pszInString, pszGetData, &chOperation); if (status != IM_DCM_STANDBY) printf("Standby error: %x\n", status);

5-22

Page 305

Using the PSK With DCM pszBonus++;

5

//go to next records

} //Turn off batch processing iDBPrtcl = IM_DBPACE_ENABLE; status = im_setup_trx(iPort, 240, IM_INFINITE_TIMEOUT, iDBPrtcl, ',', NULL, ',', 256, standby_fh); if (status != IM_DCM_OK) printf("error: %x\n", status); //Sending the rest of records. while (pszBonus->emp != NULL) { status = im_standard_trx(pszTid, IM_DBRQT_DATA, pszBonus, 256, pszInString, pszGetData, &chOperation); if (status != IM_DCM_ACK_RCD) printf("Sending error: %x\n", status); pszBonus++;

//go to next record

} //Flush standby records and make sure no records left in standby file do { status = im_standard_trx(pszTid, IM_ZIP_RECORD, pszBonus, 256, pszInString, pszGetData, &chOperation); //See what is problem if (status != IM_DCM_OK) printf("Flush error: %x\n", status); } while (status != IM_DCM_OK); printf("\nInsert Complete!\n"); //Wait for 5 seconds im_standby_wait(5000); } //********************************************************************* // Demostrate reading records without pacing protocol. // TSTRD transaction reads records, without pacing protocol. // It reads records by department, so it needs to loop thru 4 times. //********************************************************************* void HandNoPace(void) { IM_USHORT i; IM_USHORT status; IM_USHORT iDBPrtcl; // Handshake, No pace, request type IM_UCHAR pszTid[16]="TSTRD"; //Handshaking, no pacing iDBPrtcl = 0; //Set up protocol status = im_setup_trx(iPort, 240, IM_INFINITE_TIMEOUT, iDBPrtcl, ',', ',', 256, standby_fh);

5-23

Page 306

JANUS PSK for C/C++ Reference Manual if (status != IM_DCM_OK) printf("error: %x\n", status); //Read records with FOR loop. Each loop covers each department. for (i = 0; i < DEPT_NUM; i++) { status = im_standard_trx(pszTid, IM_DBRQT_DATA, pszRead[i], 256, pszInString, pszGetData, &chOperation); if (status & 0x0010) //See if data has been received { do { //Display Salary Grade, Employee name, department on screen. printf("%s, %s, %s\n", pszGetData[2].pszField, pszGetData[0].pszField, pszGetData[1].pszField); //Get next record because protocol is no pace. status = im_parse_host_response( 256, pszInString, pszGetData, &chOperation); } while ((status & 0x0010) != 0); //End of records is ACK/NAK, // instead of data received. } //Returns ACK when no more records coming from database if (status != IM_DCM_ACK_RCD) { printf("NoPace: %x\n", status); printf("%s\n", pszInString); } } printf("\nRead No Pace Complete!\n"); } //********************************************************************* // Demonstrate reading records with pacing protocol on. // TSTRD transaction reads records with pacing protocol on. // It reads records by department, so it needs to loop thru 4 times. //********************************************************************* void HandPace(void) { IM_USHORT i; IM_USHORT status; IM_USHORT iDBPrtcl; // handshake, pace, request type IM_UCHAR pszTid[16]="TSTRD"; //Handshaking and pacing. iDBPrtcl = IM_DBPACE_ENABLE; //Set up protocol status = im_setup_trx(iPort, 240, IM_INFINITE_TIMEOUT, iDBPrtcl, ',', ',', 256, standby_fh); if (status != IM_DCM_OK) printf("error: %x\n", status);

5-24

Page 307

Using the PSK With DCM

5

//Read records with FOR loop. Each loop covers each department. for (i= 0; i < DEPT_NUM; i++) { //Read first record back if record exists status = im_standard_trx(pszTid, IM_DBRQT_DATA, pszRead[i], 256, pszInString, pszGetData, &chOperation); if ( status & 0x0010) //data received { do { //Display Salary Grade, Employee name, Department on screen. printf("%s, %s, %s\n", pszGetData[2].pszField, pszGetData[0].pszField, pszGetData[1].pszField); //wait 2 seconds im_standby_wait(2000); //Ask for next records status = im_standard_trx(pszTid, IM_DBRQT_NEXTROW, NULL, 256, pszInString, pszGetData, &chOperation); } while ((status & 0x0010) != 0); //End of records is ACK/NAK, // instead of data received. } //Returns ACK when no more records coming from database if (status != IM_DCM_ACK_RCD) { printf("Pace: %x\n", status); printf("%s\n", pszInString); } } printf("\nRead Pace Complete!\n"); } //********************************************************************* //Demostrate discarding records with pacing protocol on. //********************************************************************* void HandDiscard(void) { IM_USHORT i; IM_USHORT j; IM_USHORT status; IM_USHORT iDBPrtcl; // handshake, pace, request type IM_UCHAR pszTid[16]="TSTRD"; IM_UCHAR chPaceChar; //Handshaking and pacing. iDBPrtcl = IM_DBPACE_ENABLE; //Set up protocol status = im_setup_trx(iPort, 240, IM_INFINITE_TIMEOUT, iDBPrtcl, ',', ',', 256, standby_fh); if (status != IM_DCM_OK) printf("error: %x\n", status);

5-25

Page 308

JANUS PSK for C/C++ Reference Manual

//Read 3 records with FOR loop. Each loop covers a department. for (i= 0; i < DEPT_NUM; i++) { //Read first record in database if record exists status = im_standard_trx(pszTid, IM_DBRQT_DATA, pszRead[i], 256, pszInString, pszGetData, &chOperation); //Initialize count so that after 3 records, // rest of the records j = 0; if ( status & 0x0010) //data received { do { j++;

we can discard the

//Display Salary Grade, Employee name, department on screen. printf("%s, %s, %s\n", pszGetData[2].pszField, pszGetData[0].pszField, pszGetData[1].pszField); if (j > 2) chPaceChar = IM_DBRQT_DATA; else chPaceChar = IM_DBRQT_NEXTROW;

//'S' -Discard records //'N' -next row

//wait 2 seconds im_standby_wait(2000); //Ask for next record or discard rest of records status = im_standard_trx(pszTid, chPaceChar, NULL, 256, pszInString, pszGetData, &chOperation); } while ((status & 0x0010) != 0); }

} if (status != IM_DCM_ACK_RCD) { printf("Discard: %x\n", status); printf("%s\n", pszInString); } //for printf("\nRead Discard Complete!\n"); }

5-26

//End of records is ACK/NAK, // instead of data received.

Page 309

A Appendix A: Status Codes

Page 310

This page is a scan with no text; see it in the PDF.