The text of a manual · part 15 of 40
2D JANUS PSK for C/C++ Reference Manual, pages 141 to 150
Pages 141 to 150 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 141
im_serial_protocol_control
2 im_serial_protocol_control Purpose:
This function controls the protocol mode for a designated communications port and determines whether the receive mode is with or without protocol according to the input parameter. Any change clears the input buffer and resets the reader command parser. Use this function to set the protocol when connected to a communications port. The return value indicates a success if the port is currently linked to the Virtual Wedge. If the port is not currently linked to the Virtual Wedge, the function returns an error.
Syntax:
#include <im20lib.h> IM_STATUS im_serial_protocol_control (IM_COM_PORT port_id, IM_PROTOCOL_CMD protocol, IM_UCHAR eom_char);
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 protocol parameter affects how incoming messages are received and is one of these constants: IM_NO_CHANGE IM_PROTOCOL_OFF IM_PROTOCOL_ON IM_NEW_TERM_CHAR
Keep the current protocol Turn the protocol OFF Turn the protocol ON Use the new termination character
The protocol parameter affects all incoming messages as follows: • If IM_NO_CHANGE is specified, the protocol and end of message settings remain the same as the last time the function was called. • If IM_PROTOCOL_OFF is specified, the incoming data is terminated with the specified end of message character. If the end of message character is null, the function terminates upon receiving the first character.
2-115
Page 142
im_serial_protocol_control
• If IM_PROTOCOL_ON is specified, the incoming message is terminated with the end of message character of the active protocol. • If IM_NEW_TERM_CHAR is specified, IM_PROTOCOL_OFF is assumed and the new end of message character specified in the parameter list is used. 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 other character. An EOM character is required when using IM_PROTOCOL_OFF and IM_NEW_TERM_CHAR for protocol. OUT Parameters:
None.
Return Value:
This function returns one of the standard status codes defined in Appendix A, “Status Codes.”
Notes:
Requires im_link_comm. The receive buffers are cleared whenever the protocol is turned ON or OFF. To change the termination character (or to not change the setting at all), use IM_NEW_TERM_CHAR or IM_NO_CHANGE instead of toggling the protocol.
See Also:
im_link_comm
Example /******************** im_serial_protocol_control ************************/ /* Also with: im_set_input_mode */ /* im_link_comm */ /* im_unlink_comm */ #include <stdio.h> #include <conio.h> #include <dos.h> #include <stdlib.h> #include <ctype.h> #include "immsg.h" #include "im20lib.h" #define
COM_BUFSIZE 300 void main (void) { IM_UCHAR *com_buffer; IM_UCHAR input[256];
2-116
/* Allocate 300 bytes for comm buffer */
Page 143
im_serial_protocol_control
IM_ORIGIN IM_STATUS IM_CHAR int
2 source; status; *msg_ptr; sw_flag, order_flag;
window(1, 1, 20, 16); /* Set the reader services text window */ clrscr(); /* Clear the screen */ printf("Demo IM_SERIAL_PROTOCOL_CONTROL\n'Q' to quit\n"); /* Allocate a comm buffer */ com_buffer = (char *) malloc(COM_BUFSIZE); /* Set Reader Wedge into PROGRAMMER mode im_set_input_mode(IM_PROGRAMMER);
*/
/* Link com_buffer to com1 */ im_link_comm(IM_COM1, com_buffer, COM_BUFSIZE); order_flag = 0;
/* Set flag to start from CR & LF */
/* Demo Input loop */ do { sw_flag = order_flag % 3; switch (sw_flag) { case 0: /*Turn on protocol handle with EOM char CR & LF. */ status = im_serial_protocol_control(IM_COM1, IM_PROTOCOL_ON, 0x0D); msg_ptr = "CR & LF"; break; case 1: /* Turn off protocol handle with EOM char Ctrl-Z */ status = im_serial_protocol_control(IM_COM1, IM_PROTOCOL_OFF, 0x1A); msg_ptr = "Ctrl-Z"; break; case 2: /* Turn off protocol handle with EOM char Ctrl-Y */ status = im_serial_protocol_control(IM_COM1, IM_PROTOCOL_OFF, 0x19); msg_ptr = "Ctrl-Y"; break; } printf("\nEOM: %s, P-status: %x\n", msg_ptr, status); im_receive_input(IM_COM1, IM_INFINITE_TIMEOUT, &source, input); if ( source == IM_COM1_SELECT) { printf("%s\n", input); } else printf("error\n"); order_flag++; input[0] = toupper(input[0]); } while (input[0] != 'Q'); /* Unlink com_buffer from com1 */ im_unlink_comm(IM_COM1); /* Free allocated memory */ free(com_buffer); im_set_input_mode(IM_WEDGE); }
2-117
Page 144
im_set_abort_callback im_set_abort_callback Purpose:
This function sets up the callback address for notification of an exit program reader command. It determines which function is activated when /$ is received. For example, use this function when you are running a program and want to exit without using a warm boot.
Syntax:
#include <im20lib.h> IM_STATUS im_set_abort_callback (IM_ORIGIN source, void *notify_routine);
IN Parameters:
The source parameter is one of these constants: IM_LABEL_SELECT IM_COM1_SELECT IM_COM2_SELECT IM_COM4_SELECT IM_ALL_SELECT
No source selected COM1 selected COM2, scanner port selected (2010 and 2050) COM4 selected (RF only) All sources are selected
The notify_routine parameter is a pointer to the callback routine. OUT Parameters:
None.
Return Value:
This function returns one of the standard status codes defined in Appendix A, “Status Codes.”
Notes:
IRL uses the /$ as an exit command when received from a host or scanned from a label. This im_set_abort_callback function allows you to specify a routine that is called whenever the /$ is detected from the host or from the scanner. You can also use this capability from within a PSK application. The /$ is called the IRL exit command, but the application can use it for actions other than exiting the program. The callback is called by the Reader Wedge as soon as the /$ is detected. The /$ must be the only two characters in the string. Nothing occurs if the /$ is in the middle of other characters. It is recommended that your callback routine be short (such as setting a flag or performing some other action).
2-118
Page 145
im_set_abort_callback
2
Scan in the exit IRL program command to activate the abort callback. When the abort callback routine is called, the processor services an interrupt. The routine must reenable interrupts before doing any other interrupt-driven function such as writing to the screen. If you use im_set_abort_callback to set up a callback, you must use im_clear_abort_callback before exiting your program. Otherwise, the Reader Wedge continues to call the callback each time the /$ is detected. Since the callback is no longer at the address that the Reader Wedge calls, the result is unpredictable. The notification source parameter replaces the previously set source. Only one callback routine can be submitted. On callback, the abort function’s first parameter contains the origin of the abort program command. The second parameter is left for further expansion. This command does not work in Wedge mode. For this routine to work correctly, you must use the keyword _loadds to set the data segment in the callback routine. Since the abort routine is called as an interrupt, all other interrupts are disabled until the system returns from the abort function or until an interrupt is explicitly enabled. 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_clear_abort_callback
2-119
Page 146
im_set_abort_callback
Example /******************** im_set_abort_callback *******************************/ /* Also with: im_clear_abort_callback */ /* im_set_input_mode */ /* im_standby_wait */ /* im_irlv */ /* */ /* Note: When using Microsoft "C" compiler, Inside Abort_Callback routines */ /* avoid to call any run-time routines referring to __iob variable */ /* Since microsoft put __iob into another segment. */ /* Borlandc "C" compiler doesn't have this problem. */ #include <stdio.h> #include <conio.h> #include <dos.h> #include "im20lib.h" #include "immsg.h" /* INTERNAL FUNCTIONS (EXPORTED) */ void _loadds Abort_Callback(unsigned short arg1, unsigned short arg2); /* STATIC FUNCTIONS (KNOWN ONLY BY THIS FILE) static int abort_flag;
*/ void main (void) { IM_UCHAR input[256]; IM_ORIGIN source; IM_USHORT cc; IM_DECTYPE symbol; /* FUNCTION BODY */ window(1, 1, 20, 16); clrscr();
/* Set the application text window */ /* Clear the screen */
/* Display Demo message */ printf("Demo IM_SET_ABORT_CALLBACK\n 'Q' to quit\n"); /* Set Reader Wedge mode to program interface */ im_set_input_mode(IM_PROGRAMMER); /* Set up abort callback notification hook */ im_set_abort_callback(IM_ALL_SELECT, Abort_Callback); /* Clear the abort flag */ abort_flag = 0; /* Demo's input loop */ do { /* Test wait */ printf("Start waiting for 3 seconds\n"); im_standby_wait(3000); printf("Done waiting for 3 seconds\n"); /* Test input IRL V */ printf("IRL V test\n"); /* Set source for labels and keypad */ source = IM_LABEL_SELECT | IM_KEYBOARD_SELECT;
2-120
Page 147
im_set_abort_callback
2
/* Request input from Reader Wedge */ im_irl_v(IM_INFINITE_TIMEOUT, IM_ENABLE, IM_WEDGE_BEEP, IM_ENABLE, &source, input, &cc, &symbol); /* Display the input */ printf("\n%s\n",input); /* Show a message if abort command in IRL was parsed */ if (abort_flag) { printf("\nAbort program parsed.\n%d\n", abort_flag); /* Clear the abort flag */ abort_flag = 0; } } while (input[0] != 'Q'
&& input[0] != 'q' );
/* Clear abort call back notification hook */ im_clear_abort_callback(); /* Switch the Reader Wedge back to virtual Wedge mode im_set_input_mode(IM_WEDGE);
*/
} /* ************************************************************************** * PURPOSE: callback function for abort program reader command detection * * NOTE: Need enable interrupt for this callback function, because * abort program is disable interrupt when it call callback function. ************************************************************************** */ void _loadds Abort_Callback(IM_USHORT arg1, IM_USHORT arg2) { /* Enable interrupt since the caller is disable the interrupt */ _enable(); /* Set the abort flag */ abort_flag = arg1; /**********************************************************************/ /* Note: In Borlandc "C" compiler, printf() routine works */ /* In Microsoft "C" compiler, all routines referring __iob */ /* variable won't work. using routine (like putch()) or */ /* directly output to console routine will work */ /**********************************************************************/ printf("\nabort arg:%d, %d\n", arg1, arg2); /* Does not work in Microsoft "C"*/ }
2-121
Page 148
im_set_contrast im_set_contrast Purpose:
This function sets the reader’s LCD display contrast level. There are eight levels of contrast (0 to 7) from very light to very dark, which are the most frequently used contrast settings.
Syntax:
#include <im20lib.h> IM_STATUS im_set_contrast (IM_UCHAR display_contrast_level);
IN Parameters:
The display_contrast_level parameter is one of these constants: IM_MIN_CONTRAST IM_AVE_CONTRAST IM_MAX_CONTRAST
Level 0 Level 4 Level 7
OUT Parameters:
None.
Return Value:
This function returns one of the standard status codes defined in Appendix A, “Status Codes.”
Notes:
The functions im_set_contrast and im_get_contrast use a scale of 0 to 7 that is related to the scale of 0 to 31 used by im_increase_contrast and im_decrease_contrast. The following table compares the two scales. This Value on Scale 0 to 7
Equates to This Value on Scale 0 to 31
Contrast Level
0 1 2 3 4 5 6 7
10 12 14 16 18 20 22 24
Very light
Very dark
This function has no effect on the JANUS 2050. See Also:
2-122 im_get_contrast, im_decrease_contrast, im_increase_contrast
Page 149
im_set_contrast
2
Example /******************** im_set_contrast *******************************/ /* Also with: im_get_contrast */ #include <stdio.h> #include <conio.h> #include "im20lib.h" #include "immsg.h" void main (void) { IM_STATUS status; IM_UCHAR contrast; IM_UCHAR level; clrscr(); for (level = 0; level < 10; level++) { status = im_set_contrast(level); /* If the most significant bit is set, there is an error */ if (IM_ISERROR(status)) printf("\nSet Contrast error = %x\n", status); else printf("\nContrast set to %d\n", level); status = im_get_contrast(&contrast); /* If the most significant bit is set, there is an error */ if (IM_ISERROR(status)) printf("\nGet Contrast error = %x\n", status); else printf("\nContrast is %d\n", level); /* Pause to see result */ printf("\nAny key to continue"); getch(); } }
2-123
Page 150
im_set_control_key im_set_control_key Purpose:
This function enables or disables the Ctrl key setting. When disabled, none of the key combinations that use the Ctrl key will work. For example, the warm boot key sequence Ctrl-Alt-Del will not work.
Syntax:
#include "im20lib.h" IM_STATUS im_set_control_key (IM_CONTROL control_key);
IN Parameters:
The control_key parameter is one of these constants: IM_ENABLE IM_DISABLE
Enable the Ctrl key Disable the Ctrl key
OUT Parameters:
None.
Return Value:
This function returns one of the standard status codes defined in Appendix A, “Status Codes.”
See Also:
im_get_control_key
Example See example for im_get_control_key.
2-124