The text of a manual · part 14 of 40
2D JANUS PSK for C/C++ Reference Manual, pages 131 to 140
Pages 131 to 140 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 131
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-105
Page 132
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-106
Page 133
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-107
Page 134
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-108
Page 135
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-109
Page 136
im_receive_input
OUT Parameters:
The source parameter specifies the actual input source and is one of these constants: IM_NO_SELECT IM_LABEL_SELECT IM_KEYBOARD_SELECT IM_COM1_SELECT IM_COM2_SELECT IM_COM4_SELECT
No selection made Label selected Keypad selected COM1 selected COM2, scanner port selected (2010 and 2050) COM4 selected (RF only)
The received parameter is the variable where the data is placed. Return Value:
This function returns one of the standard status codes defined in Appendix A, “Status Codes.”
Notes:
If input from more than one source is received before this function is called, the first available input is returned in this order: label, keypad, COM1, COM2, and COM4. If you are using a communications port, you must install a protocol handler and call im_link_comm. You must install the Reader Wedge to use this function. For information on loading RWTSR.EXE, see “Runtime Requirements” earlier in this chapter.
See Also:
im_get_length, im_get_label_symbology, im_link_comm
Example /******************** im_receive_input *******************************/ /* Also with: im_get_length */ /* im_link_comm */ /* im_unlink_comm */ /* im_get_input_mode */ /* im_set_input_mode */ #include <stdio.h> #include <conio.h> #include <stdlib.h> #include "im20lib.h" #include "immsg.h" #define COM_BUFSIZE 300 void main (void) { IM_UCHAR input[300];
2-110
/* Allocate 300 bytes comm buffer */
Page 137
im_receive_input
IM_USHORT IM_MODE IM_UCHAR IM_ORIGIN IM_ORIGIN IM_STATUS
2 length; original_mode; *com_buffer; in_source; source; status;
window(1, 1, 20, 16); clrscr();
/* Set the application text window */ /* Clear the screen */ printf("Demo im_receive_input\n'Q' to quit\n\'C' to clear screen\n"); /* Allocate a comm buffer */ com_buffer = (char *) malloc(COM_BUFSIZE); /* Get the previous input mode for restoring input mode later */ original_mode = im_get_input_mode(); /* Set Reader Wedge mode to program interface */ im_set_input_mode(IM_PROGRAMMER); /* Link com_buffer to com1 */ im_link_comm(IM_COM1, com_buffer, COM_BUFSIZE); /* Input loop */ do { /* Set up input source */ source = IM_LABEL_SELECT | IM_KEYBOARD_SELECT | IM_COM1_SELECT; /* Request input from label, keypad or com1 */ status = im_receive_input(source, IM_INFINITE_TIMEOUT, &source, input); length = im_get_length(source); if (IM_ISGOOD(status)) { /* Show the input source */ if (source == IM_LABEL_SELECT) printf("\nLabel input:\n"); else if (source == IM_KEYBOARD_SELECT) printf("\nKeybd input:\n"); else if ( source == IM_COM1_SELECT) printf("\nCom1 input:\n"); /* Display input data */ printf("%s\nInput length: %d\n", input, length); } else if (status == IM_APPLICATION_BREAK) { printf("application break detected"); } else /* input error */ printf("input error\n"); /* Upper case first char of input for simplifying to test input */ input[0] = toupper(input[0]); /*If the first char in string is 'C', then clear screen.*/ if (input[0] == 'C') clrscr(); } while (input[0] != 'Q');
/* First number in string is 'Q', then stop */
2-111
Page 138
im_receive_input
/* Unlink com_buffer from com1 */ im_unlink_comm(IM_COM1); /* Free allocated memory */ free(com_buffer); /* Restore original input mode */ im_set_input_mode(original_mode); }
2-112
Page 139
im_rs_installed
2 im_rs_installed Purpose:
This function determines whether or not the reader services (RSERVICE.EXE) program is installed.
Syntax:
#include <im20lib.h> IM_STATUS im_rs_installed (void);
IN Parameters:
None.
OUT Parameters:
None.
Return Value:
This function returns one of the standard status codes defined in Appendix A, “Status Codes.”
See Also:
None.
Example /******************** im_rs_installed *******************************/ /* Also with: im_message */ #include <stdio.h> #include "im20lib.h" void main (void) { printf("Check for reader\nservice installation\n"); im_message( im_rs_installed() ); }
2-113
Page 140
im_rx_check_status im_rx_check_status Purpose:
This function directs the active protocol handler to check the communications port buffer status variable to determine if the application program has accepted the previous data. Use this function with the im_receive_buffer_no_wait function to receive input from multiple buffers.
Syntax:
#include <im20lib.h> IM_STATUS im_rx_check_status (IM_COM_PORT port_id);
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:
None.
Return Value:
This function returns one of the standard status codes defined in Appendix A, “Status Codes.”
Notes:
You must install a protocol handler to use this function.
See Also:
im_receive_buffer_no_wait
Example See example for im_receive_buffer_no_wait.
2-114