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

JANUS PSK for C/C++ Reference Manual, Version 2.1, pages 131 to 140

Pages 131 to 140 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 131

im_receive_buffer eor_char = eor_byte; printf ("Enter characters\n"); printf ("to be received\n"); printf ("from host\n"); printf ("CRLF to End of Line\n");

/* Each line end with a CR & LF */ do { actual_length = 0; /* Call Intermec receive buffer function with 50000 msec timeout */ status = im_receive_buffer(com_port, sizeof(data_buffer) - 1, data_buffer, 50000, &actual_length); if (actual_length > 0) { /* Append CR & LF before write it into files */ data_buffer[actual_length++] = '\x0D'; data_buffer[actual_length++] = '\x0A'; data_buffer[actual_length] = '\0'; /* Write results to file */ fwrite(data_buffer, actual_length, sizeof(char), out_fptr); printf("%s", data_buffer); /* Write data to on screen */ eor_byte = toupper(data_buffer[0]); } else { eor_byte = '\0'; printf("Rx Status: %xH\n", status); } } while (eor_byte != eor_char);

/* Close file and exit */ fclose(out_fptr); printf("Receive Done\n"); }

2-102

/* Loop until EOR char 'q' */

Page 132

im_receive_buffer_no_wait

2 im_receive_buffer_no_wait Purpose:

This function receives data from the designated communications port and places the data into a user-defined record. It differs from im_receive_buffer in that the programmer must set up the data record and monitor the transfer status until transmission is complete. This function runs in the background after it is initiated; no checks are made. Use this function when receiving multiple buffer transmissions in conjunction with im_rx_check_status.

Syntax:

#include <im20lib.h> IM_STATUS im_receive_buffer_no_wait (IM_COM_PORT port_id, IM_COM_DATA_BUFFER far *data_struct);

IN Parameters:

The port_id parameter identifies the communications port as follows: IM_COM1 IM_COM2 IM_COM4

COM1 COM2, scanner port (2010 and 2050) COM4 (RF only)

The data_struct parameter is a far pointer to the data array for the received data. This buffer must hold at least 256 bytes. OUT Parameters:

None.

Return Value:

This function returns one of the standard status codes defined in Appendix A, “Status Codes.”

Notes:

You must build and maintain a data_struct of the type IM_COM_DATA_BUFFER as described in IM20LIB.H. You must periodically check the protocol_xfer_status element in the IM_COM_DATA_BUFFER record to see if all the data has been received. When protocol_xfer_status is no longer code 8602H (communications port in use), all data is received. You must install a protocol handler to use this function.

2-103

Page 133

im_receive_buffer_no_wait

This function differs from im_receive_buffer_noprot in that program execution continues after im_receive_buffer_no_wait is called. When im_receive_buffer_noprot returns from a function call, the data has been read, the timeout has expired, or an error was encountered. See Also:

im_receive_buffer_noprot, im_cancel_rx_buffer, im_rx_check_status

Example /******************** im_receive_buffer_no_wait ************************/ /* Also with: im_rx_check_status */ /* im_cancel_rx_buffer */ /* */ /* Note: Must have reader services and comm protocol handler installed to /* enable send/receive buffer functions. /* Run these TSR's at DOS prompt before running these tests: /* rservice /* phimec 1 ( 1 is COM1)

*/ */ */ */ */

#include <stdio.h> #include <conio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> #include "im20lib.h" #include "immsg.h" static IM_COM_PORT static IM_UCHAR com_port = IM_COM1; eor_char = 'Q';

void main (void) { IM_COM_DATA_BUFFER IM_STATUS IM_UCHAR IM_UCHAR int com_buff_struct; /*Data buffer structure for receive/transmit */ status; eor_byte; data_buff[300]; index = 0;

printf("Type End of receive\nchar?"); eor_byte = getche(); eor_byte = toupper( eor_byte);

/* Uses COM1*/ /* Default end of receive char */

/* Get End of Receive char */ if ( isascii(eor_byte)) eor_char = eor_byte; printf ("Enter characters\n"); printf ("to be received\n"); printf ("from host\n"); printf ("CRLF to End of Line\n");

/* Each line end with a CR & LF */

/* Get the receive environment ready */ status = im_cancel_rx_buffer(com_port); printf ("RX Init =%XH\n", status); /* Set up com_buff structure for init Receive Buffer No Wait */ com_buff_struct.command = IM_CU_RECEIVE; com_buff_struct.comm_length = 0;

2-104

Page 134

im_receive_buffer_no_wait

2 com_buff_struct.user_length = sizeof(data_buff); com_buff_struct.data_ptr = data_buff; com_buff_struct.protocol_mode = IM_NO_PROTOCOL; com_buff_struct.eom_char = 0x0d; /* CR for terminating char */ com_buff_struct.protocol_xfer_status = IM_COMM_INUSE; /* Call Intermec function */ status = im_receive_buffer_no_wait(com_port, (IM_COM_DATA_BUFFER far *) &com_buff_struct); /* Uses im_rx_check_status to get the rest coming data */ do /* loop until first character in buffer is a 'Q' */ { /* Check for receive errors: Print the error status */ if ( IM_ISSUCCESS(status) ) { ++index; /* Indicator of the receiving buffer */ /* Let the receive data coming complete */ while (com_buff_struct.protocol_xfer_status == IM_COMM_INUSE) ; /* End of While loop, Wait the coming data settled */ printf ("Line %d Done\n", index); /* Put a null byte in received string for display */ data_buff[com_buff_struct.comm_length] = '\0'; /* If 1st byte in string is equal to eor_char, then quit the receive*/ eor_byte = toupper(data_buff[0]); /* Display received string to screen */ printf("%s\n", data_buff); /* ************************************************************* * Update buffer for next block before calling check status to * get protocol handler to reset status. ************************************************************** */ com_buff_struct.command = IM_CU_RECV_AGAIN; com_buff_struct.comm_length = 0; com_buff_struct.protocol_xfer_status = IM_COMM_INUSE; /* Call intermec function to see next block data */ status = im_rx_check_status(com_port); } else { eor_byte = '\0'; printf("Rx Error = %XH\n", status); } printf("ch: %xH, by: %xH\n", eor_char, eor_byte); } while ( eor_byte != eor_char);

/* Loop until reaching eor_char */ printf ("Receive Done\n"); }

2-105

Page 135

im_receive_buffer_noprot im_receive_buffer_noprot Purpose:

This function receives a text string from the designated port without using the active protocol. Only the PHIMEC.EXE protocol handler supports this function, which is often used to receive a host initialization string before beginning transmission.

Syntax:

#include <im20lib.h> IM_STATUS im_receive_buffer_noprot (IM_COM_PORT port_id, IM_USHORT user_length, IM_UCHAR far *data_buffer, IM_USHORT timeout, IM_UCHAR eom_char, IM_USHORT far *comm_length);

IN Parameters:

The port_id parameter identifies the communications port as follows: IM_COM1 IM_COM2 IM_COM4

COM1 COM2, scanner port (2010 and 2050) COM4 (RF only)

The user_length parameter is the maximum number of characters you can receive and must be at least 256 bytes. The data_buffer parameter is a far pointer to the data array where you want to place the received data. This buffer must hold at least 256 bytes. The timeout parameter is the receive timeout period. You can exit the function before data is received or before the timeout occurs by performing an application break sequence (see your JANUS user’s manual). The return status indicates whether the function was successful, a timeout occurred, or the application break was received. The timeout parameter is a number or one of these constants: 1 to 65,534 ms IM_ZERO_TIMEOUT IM_INFINITE_TIMEOUT

Numeric range No wait Wait forever

If IM_INFINITE_TIMEOUT is selected, the function will not return until the end of message character has been received.

2-106

Page 136

im_receive_buffer_noprot

2

The eom_char parameter is the end of message character needed to terminate input from the communications port. The character is normally a carriage return, but you can set it to any character. OUT Parameters:

The comm_length parameter returns the actual number of bytes received.

Return Value:

This function returns one of the standard status codes defined in Appendix A, “Status Codes.”

Notes:

You must install the PHIMEC.EXE protocol handler to use this function. The difference between this function and im_receive_buffer_no_wait is that when im_receive_buffer_noprot returns from the function call, the data has been read, the timeout has expired, or an error was encountered. When you call im_receive_buffer_no_wait, program execution continues without checking for received data or errors.

See Also:

im_receive_buffer_no_wait, im_cancel_rx_buffer, im_rx_check_status

Example /******************** im_receive_buffer_no_protocol ************************/ /* Also with: im_cancel_rx_buffer */ /* */ /* Note: Must have reader services and comm protocol handler installed to */ /* enable send/receive buffer functions. */ /* Run these TSR's at DOS prompt before running these tests: */ /* rservice */ /* phimec 1 ( 1 is COM1) */ #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include "im20lib.h" #include "immsg.h" static IM_COM_PORT static IM_UCHAR com_port = IM_COM1; eor_char = 'Q';

/* Uses COM1*/ /* Default end of receive char */ void main (void) { IM_STATUS status; IM_UCHAR eor_byte; /* Uses 1st byte of receive to determine quit Rx*/ IM_UCHAR eom_char; /* End of message char */ IM_USHORT actual_length; IM_UCHAR data_buffer[300]; /* Get the receive environment ready */ status = im_cancel_rx_buffer(com_port);

2-107

Page 137

im_receive_buffer_noprot printf("Rx Cancel: %xH\n", status); printf("Type End of receive\nchar?"); eor_byte = toupper( getche()); if (isascii(eor_byte)) eor_char = eor_byte; printf ("Enter characters\n"); printf ("to be received\n"); printf ("from host\n"); printf ("CRLF to End of Line\n");

/* Get End of Receive char */

/* Each line end with a CR & LF */

/* Uses Carriage Return for End of Message character */ eom_char = 0x0d; /*CR */ do { /* Call the Intermec function */ status = im_receive_buffer_noprot(com_port, sizeof(data_buffer), (char far *)data_buffer, 50000, eom_char, &actual_length); if (actual_length > 0) { /* append CR & LF before write it into files */ data_buffer[actual_length++] = '\x0D'; data_buffer[actual_length++] = '\x0A'; data_buffer[actual_length] = '\0'; printf("%s", data_buffer); /* Write data to on screen */ eor_byte = toupper(data_buffer[0]); } else { eor_byte = '\0'; printf("Rx Status: %xH\n", status); } } while (eor_byte != eor_char);

/* Loop until reaching End of Receive*/

/* Show Exit receive no protocol message */ printf("Rx No Protocol Done\n"); }

2-108

Page 138

im_receive_byte

2 im_receive_byte Purpose:

This function receives one byte of data through the designated communications port. This function is identical to MS-DOS INT 14H service 02H.

Syntax:

#include <im20lib.h> IM_STATUS im_receive_byte (IM_COM_PORT port_id, IM_UCHAR *receive_byte);

IN Parameters:

The port_id parameter identifies the communications port as follows: IM_COM1 IM_COM2 IM_COM4

COM1 COM2, scanner port (2010 and 2050) COM4 (RF only)

OUT Parameters:

The receive_byte parameter is a pointer to the byte received from the communications port.

Return Value:

This function returns one of the standard status codes defined in Appendix A, “Status Codes.”

Notes:

This function requires the PC standard protocol handler PHPCSTD.EXE. If you are using PHIMEC.EXE and want to receive a single byte, use im_receive_buffer with a buffer length of one instead of the im_receive_byte procedure. This procedure will not work if linked.

See Also:

im_transmit_byte

Example /******************** im_receive_byte *******************************/ /* Uses Borland _bio_serialcom or Microsoft _bios_serialcom to init the */ /* com port for single byte receive. */ /* Operations. It sets up for 9600,E,7,1 on serial port */ /* To Terminate reception of bytes: */ /* To end the reception of bytes from the host, type <ESC> on JANUS */ /* and then type a Ctrl Z on the host */ /* Note: Phimec protocol handler must NOT be installed to run this routine */ /* Phpcstd protocol handler must be installed to run this routine */

2-109

Page 139

im_receive_byte

#include <stdio.h> #include <dos.h> #include <conio.h> #include <stdlib.h> #include <bios.h> #include <string.h> #include "im20lib.h" #include "immsg.h" /* Byte oriented defines */ #define COM1 0 #define SETTINGS (_COM_9600 | _COM_CHR7 | _COM_STOP1 | _COM_EVENPARITY ) static IM_COM_PORT com_port = IM_COM1;

/* Uses COM1*/ void main (void) { IM_UCHAR inchar; IM_STATUS status; printf("\nChoose a protocol:\n"); printf("1) PC Standard\n"); printf("2) No protocol\n"); if (getche() == '2') /* Call bios to initialize com port */ { /* Communications port init */ _bios_serialcom(_COM_INIT, COM1, SETTINGS); } printf ("\nChars received\n"); printf ("<ESC> to quit\n"); printf ("PC function\n"); printf ("Ctrl Z to finish at\n"); printf ("host\n"); /* Phimec protocol handler must NOT be installed ...*/ while (1) { /* Call Intermec function */ status = im_receive_byte(com_port, &inchar); if ( IM_ISERROR(status)) { printf("st: %xH\n", status); im_message(status); } else putch (inchar); /* If User press <ESC> key, then stop program */ if ( kbhit() && getch() == '\x1B') break; } }

2-110

Page 140

im_receive_input

2 im_receive_input Purpose:

This function gets input from the source and places it into the received buffer. You can use the im_get_length function after this function to get the input length.

Syntax:

#include <im20lib.h> IM_STATUS im_receive_input (IM_ORIGIN allowed, IM_UINT timeout, IM_ORIGIN *source, IM_CHAR *received);

IN Parameters:

The allowed parameter defines the available input source and is one or more of these constants: IM_LABEL_SELECT IM_KEYBOARD_SELECT IM_COM1_SELECT IM_COM2_SELECT IM_COM4_SELECT IM_ALL_SELECT

Label selected Keypad selected COM1 selected COM2, scanner port selected (2010 and 2050) COM4 selected (RF only) All sources are selected

The timeout parameter is the receive timeout period. You can exit the function before data is received or before the timeout occurs by performing an application break sequence (see your JANUS user’s manual). The return status indicates whether the function was successful, a timeout occurred, or the application break was received. The timeout parameter is a number or one of these constants: 1 to 65,534 ms IM_ZERO_TIMEOUT IM_INFINITE_TIMEOUT

Numeric range No wait Wait forever

If IM_INFINITE_TIMEOUT is selected, the function will not return until the end of message character has been received.

2-111