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 10 of 13

TREQ-M4 Mobile Data Terminal Manual: Chapter 6. Application Development, pages 61 to 70

Pages 61 to 70 of 98, from TREQ-M4 Mobile Data Terminal Manual

The original document is the PDF (2.4 MB). 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 QSI Corp TREQ-M4, Beijer TREQ-M4 and Micronet TREQ-M4

Page 61

Application Development

Software Drivers

// set key mapping and repeat DeviceIoControl(hDevice, IOCTL_KEYPAD_SET_KEY, &keyIn, sizeof(keyIn), NULL, 0, NULL, NULL); // get key mapping and repeat DeviceIoControl(hDevice, IOCTL_KEYPAD_GET_KEY, &key, sizeof(key), &keyCode, sizeof(keyCode), NULL, NULL); BOOL bRepeat = (keyCode & TREQ_KEY_REPEAT) != 0; // get repeat state // Set shift state to "on" to access shifted key set // Once in shift mode, set and get key will access the shifted set int shift = 1; DeviceIoControl(hDevice, IOCTL_KEYPAD_SET_SHIFT, &shift, sizeof(shift), NULL, 0, NULL, NULL); // get shift state DeviceIoControl(hDevice, IOCTL_KEYPAD_GET_SHIFT, NULL, 0, &shift, sizeof(shift), NULL, NULL); // set cursor key acceleration // applies only when mouse cursor key codes are used int accel = 5; // 0 to TREQ_KEY_MAX_ACCEL, defined in TreqGLPublic.h DeviceIoControl(hDevice, IOCTL_KEYPAD_SET_ACCEL, &accel, sizeof(accel), NULL, 0, NULL, NULL); // get cursor key acceleration DeviceIoControl(hDevice, IOCTL_KEYPAD_GET_ACCEL, NULL, 0, &accel, sizeof(accel), NULL, NULL); // set and get the path to an executable program or a sequence of keys // executed when the key is pressed (requires a VK_RUN_APP or VK_SEQ keycode) // runApp launches MinTermCE.exe // string initializer includes null terminator WCHAR runApp[] = { TREQ_KEY0, VK_RUN_APP, TEXT("\\HardDisk\\bin\\MinTermCE.exe") }; // VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) enum { VK_0=0x30, VK_1, VK_2, VK_3, VK_4, VK_5, VK_6, VK_7, VK_8, VK_9 }; // VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) enum { VK_A=0x41, VK_B, VK_C, VK_D, VK_E, VK_F, VK_G, VK_H, VK_I, VK_J, VK_K, VK_L, VK_M, VK_N, VK_O, VK_P, VK_Q, VK_R, VK_S, VK_T, VK_U, VK_V, VK_W, VK_X, VK_Y, VK_Z }; // runSeq launches MinTermCE.exe, then types "done" // Can't use string initializer when data follows the path in // the sequence (compiler limitation) WCHAR runSeq[] = { TREQ_KEY1, VK_SEQ | TREQ_KEY_REPEAT, VK_RUN_APP, '\\', 'H', 'a', 'r', 'd', 'D', 'i', 's', 'k', '\\', 'b', 'i', 'n', '\\', 'M', 'i', 'n', 'T', 'e', 'r', 'm', 'C', 'E', '.', 'e', 'x', 'e', 0, // must null terminate! VK_D, VK_O, VK_N, VK_E | TREQ_KEY_RELEASE }; // otherSeq types "Hello World" followed by a return, and repeats WCHAR otherSeq[] = { TREQ_KEY2, VK_SEQ | TREQ_KEY_REPEAT, VK_LSHIFT, VK_H | TREQ_KEY_RELEASE, VK_E, VK_L, VK_L, VK_O, VK_SPACE, VK_LSHIFT, VK_W | TREQ_KEY_RELEASE, VK_O, VK_R, VK_L, VK_D, VK_RETURN | TREQ_KEY_RELEASE } DWORD seqNumBytes = sizeof(runApp); // num bytes, including NULL terminator DeviceIoControl(hDevice, IOCTL_KEYPAD_SET_KEY, runApp, seqNumBytes, NULL, 0, NULL, NULL); seqNumBytes = sizeof(runSeq); DeviceIoControl(hDevice, IOCTL_KEYPAD_SET_KEY, runSeq, seqNumBytes, NULL, 0, NULL, NULL);

TREQ-M4 Mobile Data Terminal

51

Page 62

Software Drivers

Application Development seqNumBytes = sizeof(otherSeq); DeviceIoControl(hDevice, IOCTL_KEYPAD_SET_KEY, otherSeq, seqNumBytes, NULL, 0, NULL, NULL); // find length of key data sequence for key 1 // To get returned length: retDataNumBytes/sizeof(WCHAR) // Must pass at least a WORD to the output buffer to get the initial code: // keyCode will be set to VK_SEQ if it is a sequence key = TREQ_KEY1; DWORD retDataNumBytes = 0; DeviceIoControl(hDevice, IOCTL_KEYPAD_GET_KEY, &key, sizeof(key), &keyCode, sizeof(keyCode), &retDataNumBytes, NULL); // sequence string returned in retData // num bytes in retData returned in retPathNumBytes // To get returned length: retDataNumBytes/sizeof(WCHAR) WCHAR *retData = new WCHAR[retDataNumBytes/sizeof(WCHAR)]; DeviceIoControl(hDevice, IOCTL_KEYPAD_GET_KEY, &key, sizeof(key), retData, retDataNumBytes, NULL, NULL); // set auto repeat delay and rate (global) #include <keybd.h> // from SDK, for struct defn // all int32 struct members, only first 2 matter // delay is in ms // repeat rate is in keys/sec KBDI_AUTOREPEAT_INFO ai = { delay, repeatRate, 0, 0 }; DeviceIoControl(hDevice, IOCTL_KBD_SET_AUTOREPEAT, &ai, sizeof(ai), NULL, 0, NULL, NULL); CloseHandle(hDevice);

Example registry settings: This example shows the registry key settings for key 0 and cursor acceleration. To adjust another key, change the 0 to the number of the desired key (0 through 3). [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\KEYPAD] "CursorAccel" = dword:5 "Key0" = dword:200 ; VK_RUN_APP "Key0Shift" = dword:201 ; VK_SEQ "Key0Repeat" = dword:0 "Key0ShiftRepeat"= dword:0 "Key0Ext" = hex: 65,00, 78,00, 70,00, 6c,00, 6f,00, 72,00, 65,00, 72,00, 2e,00, 65,00, 78,00, 65,00, 00,00 ; run explorer.exe "Key0ShiftExt"= hex: 45,00, 58,00, 50,00, 4c,00, 4f,00, 52,00, 45,00, 52,00, 6e,00, 45,00, 58,00, 45,80 ; type explorer.exe (key release at end)

Changes to these registry settings take effect only after a reboot.

6.3.2 Backlight The backlight driver is responsible for enabling/disabling and setting the intensity levels of the display and keypad backlights. The user may control these operations programmatically or via a user interface.

52

TREQ-M4 Mobile Data Terminal

Page 63

Application Development

Software Drivers

The intensities of the display and keypad can be independently controlled via driver DeviceIoControl calls. The TREQ Panel application also includes slider controls for these settings (refer to section 4.2, “TREQ Panel”). The Windows CE power manager contains timers that can be used to enable power-down and/or power-off modes for the display and keypad backlight after a specified time has elapsed. The power-down and power-off modes correspond to User Idle and System Idle system power states. Set timers for User Idle and System Idle state transitions via driver DeviceIoControl calls, the TREQ Panel application (refer to section 4.2.5, “Power States” for more information on TREQ Panel power state controls), or registry values. Set the power state timer values to 0 to disable transition to User Idle and/or System Idle states. Disabling transition to User Idle also prevents transition to System Idle. To retain the System Idle transition, set the User Idle timer to one second. The state transition timers are cumulative; in other words, the System Idle transition will occur only after both the User Idle and System Idle timers expire. A transition to User Idle causes both the display and keypad backlights to dim to the specified intensity. This intensity level can be set via a DeviceIoControl call. Any user activity will cause the power manager to transition out of User Idle to a full on state, and thus restore the prior backlight intensity levels. Examples of user activity are pressing the touch screen or keypad, or using a USB mouse or keyboard (specifically, when the event defined in the [HKLM\System\GWE\ActivityEvent] registry key is signaled). A transition to System Idle causes the display backlight, keypad backlight, and the LCD display to be disabled. Any user activity will cause the power manager to transition out of System Idle to a full on state, and thus restore the prior backlight intensity levels. API, described via code examples: HANDLE hDevice; hDevice = CreateFile(TEXT("BLT1:"), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); // set/get backlight intensity int intensity = 80; // 0 to 100% DeviceIoControl(hDevice, IOCTL_BACKLIGHT_SET_INTENSITY, &intensity, sizeof(intensity), NULL, 0, NULL, NULL); DeviceIoControl(hDevice, IOCTL_BACKLIGHT_GET_INTENSITY, NULL, 0, &intensity, sizeof(intensity), NULL, NULL); // set/get keypad backlight intensity intensity = 80; // 0 to 100% DeviceIoControl(hDevice, IOCTL_BACKLIGHT_KEYPAD_SET_INTENSITY, &intensity, sizeof(intensity), NULL, 0, NULL, NULL); DeviceIoControl(hDevice, IOCTL_BACKLIGHT_KEYPAD_GET_INTENSITY, NULL, 0, &intensity, sizeof(intensity), NULL, NULL); // set/get keypad AND display backlight power-down intensity intensity = 15; // 0 to 100% DeviceIoControl(hDevice, IOCTL_BACKLIGHT_POWERDOWN_SET_INTENSITY, &intensity, sizeof(intensity), NULL, 0, NULL, NULL); DeviceIoControl(hDevice, IOCTL_BACKLIGHT_POWERDOWN_GET_INTENSITY, NULL, 0, &intensity, sizeof(intensity), NULL, NULL);

TREQ-M4 Mobile Data Terminal

53

Page 64

Software Drivers

Application Development

// set or get the backlight power down or power off timeout value int pwrTime; // seconds // set power down (User Idle transition timer) DeviceIoControl(hDevice, IOCTL_BACKLIGHT_SET_POWERDOWN, &pwrTime, sizeof(pwrTime), NULL, 0, NULL, NULL); DeviceIoControl(hDevice, IOCTL_BACKLIGHT_GET_POWERDOWN, NULL, 0, &pwrTime, sizeof(pwrTime), NULL, NULL); // set power off (System Idle transition timer) DeviceIoControl(hDevice, IOCTL_BACKLIGHT_SET_POWEROFF, &pwrTime, sizeof(pwrTime), NULL, 0, NULL, NULL); DeviceIoControl(hDevice, IOCTL_BACKLIGHT_GET_POWEROFF, NULL, 0, &pwrTime, sizeof(pwrTime), NULL, NULL); CloseHandle(hDevice);

Example registry settings: Following are the defaults for the prototype unit. [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Backlight] "BacklightIntensity"=dword:00000064 ; 100% "BacklightKeypadIntensity"=dword:00000064 ; 100% "BacklightPowerDownIntensity"=dword:2 ; 2% ; used for UserIdle [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\Timeouts] "ACUserIdle"=dword:3C ; sec from last user activity 0x3c=60s "ACSystemIdle"=dword:12C ; sec from start of UserIdle 0x12c=300s=5min

Changes to these registry settings take effect only after a reboot.

6.3.3 EMP (Emergency Power) The EMP driver is responsible for responding to low input voltage and voltage recovery events from the TREQ-M4’s input voltage detection circuitry and reporting them to the system (refer to section 2.1.8, “Power Supply”). The USB and audio (internal and external) functions will be disabled while the TREQ-M4’s input voltage is too low Applications listening to EMP driver events can respond to the loss of these functions and can be notified when the voltage returns to normal operating range. There are two voltage thresholds and two corresponding operating system events generated, as follows:

• Main Power Low – the input voltage drops below a threshold that is typically between six and seven volts.

• Main Power High – the input voltage has risen above the Main Power Low threshold plus an additional hysteresis band of about one volt (i.e., the event will be triggered when the voltage rises above about eight volts). NOTE

54

☞

The Main Power High event is not generated during boot as the system powers up.

TREQ-M4 Mobile Data Terminal

Page 65

Application Development

Software Drivers

In order to avoid race conditions with regulated voltage supplies, the Main Power High event can be signaled no sooner than a minimum wait time after a preceding Main Power Low event, provided that the voltage has increased past the threshold. The minimum wait time is 500 milliseconds by default and is configurable with a registry setting (StableTimeForUp; see “Example registry setting” below). After a Main Power Low event occurs, a check is made every 100 milliseconds to determine whether the input voltage has satisfied the conditions for signaling a Main Power High event. The Main Power High event is signaled if this check is positive for the minimum wait time (e.g., five times for 500 ms). The EMP driver may take measures to reduce power consumption as the input voltage drops. In response to a Main Power Low event, the EMP driver causes the keypad and display backlight to dim, depending on the value of a registry setting (LowPowerState; see “Example registry setting” below). The dimmed intensity can be set via a DeviceIoControl call to the backlight driver for power down intensity (refer to section 6.3.2, “Backlight”). Audio and USB host functions will be reset when the input voltage level is too low to maintain regulated power to these circuits. Only a Main Power High event will return the unit to its state prior to experiencing power failure events. Windows CE power notifications are generated to signal the occurrence of the Main Power Low and Main Power High events. The RequestPowerNotifications function can be used with a message queue to register to receive EMP event notifications. The EMP driver generates messages of type PBT_TRANSITION in a POWER_BROADCAST structure. The Flags member of this structure is set to a power state enumeration defined in TreqPublic.h. The Power Manager knows nothing of these custom states; they are only used in the power notification process (e.g., GetSystemPowerState() will never return POWER_STATE_MAIN_PWR_LOW). API, described via code examples: // Sample code to be run from a separate thread for // monitoring power failure events UCHAR buf[QUEUE_SIZE]; HANDLE hNotifications = NULL, hReadMsgQ = NULL; MSGQUEUEOPTIONS msgOptions = { 0 }; DWORD dwBytesInQueue, dwFlags; PPOWER_BROADCAST pB = (PPOWER_BROADCAST)buf; // Create a message queue for Power Manager notifications. msgOptions.dwSize = sizeof(MSGQUEUEOPTIONS); msgOptions.dwFlags = 0; msgOptions.dwMaxMessages = QUEUE_ENTRIES; msgOptions.cbMaxMessage = sizeof(POWER_BROADCAST) + MAX_NAMELEN; msgOptions.bReadAccess = TRUE; // Check return value for NULL hReadMsgQ = CreateMsgQueue(NULL, &msgOptions); // Request Power notifications, check return value for NULL hNotifications = RequestPowerNotifications(hReadMsgQ, PBT_TRANSITION); while (TRUE) {

TREQ-M4 Mobile Data Terminal

55

Page 66

Software Drivers

Application Development dwBytesInQueue = dwFlags = 0; memset(buf, 0, QUEUE_SIZE); // Read message from queue. Check for 0 return value if (!ReadMsgQueue(hReadMsgQ, buf, QUEUE_SIZE, &dwBytesInQueue, INFINITE, &dwFlags)) { break; // error with ReadMsgQueue } if (dwBytesInQueue < sizeof(POWER_BROADCAST)) { // error: not enough bytes received break; } if (PBT_TRANSITION == pB->Message) { switch (POWER_STATE(pB->Flags)) { case POWER_STATE_MAIN_PWR_LOW: // Main Power Low event received break; case POWER_STATE_MAIN_PWR_HIGH: // Main Power High event received break; default: break; } break; } } // while(TRUE) StopPowerNotifications(hNotifications); CloseMsgQueue(hReadMsgQ);

Example registry setting: Following are the defaults for the prototype unit. [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\EMP] "LowPowerState" = dword:0 ; Backlight driver state: D0:0, D1:1,..., D4 ; For Backlight driver: D0=on D1=dim D2=D3=D4=off "StableTimeForUp" = dword:1F4 ; 500ms -- time before re-enabling devices

Changes to these registry settings take effect only after a reboot.

6.3.4

Power The Power Management driver can be used to control power state transitions for the TREQ-M4 system or for specific peripherals. User applications may use the Windows CE Power Management API (e.g., the SetSystemPowerState, SetDevicePower, and DevicePowerNotify functions) to control and set system or device power states. The power states for the system are specified via specific strings, for example, "useridle." The power states for peripherals are specified with the Windows CE power state enumerations D0 – D4. Refer to the Power Management functions documentation on MSDN (http://msdn.microsoft.com/en-us/library/aa909892.aspx), the pm.h header file that is included

56

TREQ-M4 Mobile Data Terminal

Page 67

Application Development

Software Drivers in the SDK (\Program Files\Windows CE Tools\wce600\TREQ-M4\Include \Armv4i\pm.h), and the CEDEVICE_POWER_STATE enumeration at http://msdn.microsoft.com/en-us/library/bb201981.aspx. The following table shows the available TREQ-M4 system power states, specified as both strings and enumerations (when available). State “on”, POWER_STATE_ON

Description Full power mode. All peripherals fully powered and enabled. The power manager may still cause the system to transition to a low power idle mode during periods of reduced and no activity.

Reduced/low power mode. Display backlight and keypad “useridle”, backlight are dimmed. The TREQ-M4 consumes about POWER_STATE_USERIDLE one-half the power required when in the “on” state. “systemidle”, POWER_STATE_IDLE

Reduced/low power mode. LCD, display backlight, and keypad backlight are disabled. The TREQ-M4 consumes about one-third to one-half the power required when in the “on” state.

“suspend”, “resuming”, POWER_STATE_SUPEND

Not supported. Using this parameter with the SetSystemPowerState function will have no effect and will return failure.

“off”, “shutdown”, POWER_STATE_OFF

Causes an orderly shutdown of the TREQ-M4, followed by a soft reboot.

“reboot”, “coldreboot”, POWER_STATE_RESET

Causes an orderly shutdown of the TREQ-M4, followed by a soft reboot.

The following are examples illustrating how to put the system and backlight, display, and USB peripheral devices into a specific power state. // Be sure to check return values for Power Management functions #include <pm.h> #define BACKLIGHT_DEVICE_NAME PMCLASS_GENERIC_DEVICE TEXT("\\BLT1:") #define DISPLAY_DEVICE_NAME PMCLASS_DISPLAY TEXT("\\zylonite_lcd") #define USB_DEVICE_NAME PMCLASS_GENERIC_DEVICE TEXT("\\HCD1:") DWORD dwDummy; CEDEVICE_POWER_STATE cps; TCHAR buf[50]; ///////// // System // Get system power state GetSystemPowerState(buf, 50, &dwDummy); // buf contains the current power state string, e.g. "on"

TREQ-M4 Mobile Data Terminal

57

Page 68

Software Drivers

Application Development

// Perform a soft reset using the Power Manager API // These two calls do the same thing SetSystemPowerState("reboot", 0, 0x0); SetSystemPowerState(NULL, POWER_STATE_RESET, 0x0); // Put the TREQ-M4 system in the system idle state, then // go back to the on state SetSystemPowerState("systemidle", 0, 0x0); SetSystemPowerState("on", 0, 0x0); /////////////// // Peripherals // Backlight // cps will have the current state GetDevicePower(BACKLIGHT_DEVICE_NAME, POWER_NAME, &cps) // Set the backlight driver's power state to D2 "standby" state. // The backlight is dimmed, but not off in D2 SetDevicePower(BACKLIGHT_DEVICE_NAME, POWER_NAME, D2); // Display // cps will have the current state GetDevicePower(DISPLAY_DEVICE_NAME, POWER_NAME, &cps) // Set the display driver's power state to D4 "off" state, // which turns the display off. SetDevicePower(DISPLAY_DEVICE_NAME, POWER_NAME, D4); // USB // cps will have the current state GetDevicePower(USB_DEVICE_NAME, POWER_NAME, &cps) // Set the USB driver's power state to D4 "off" state, // which disables bus power to any connected USB devices. SetDevicePower(USB_DEVICE_NAME, POWER_NAME, D0);

6.3.5

Serial Ports Refer to the following MSDN website regarding programming serial connections for information about and examples of the Windows CE serial port API: http://msdn.microsoft.com/en-us/library/aa913128.aspx. The serial port driver uses the stream driver interface. COM1, COM2, and COM5 drivers have port names of COM1:, COM2:, and COM5:, which can be passed to the CreateFile function to open these ports. COM5 is a virtual COM port that is available when a USB-to-serial converter is attached. The MinTermCE.exe is a simple terminal program (refer to section 4.7.2) that can be used to test communications over the TREQ-M4 serial ports.

6.3.6

Network Windows CE provides a standard API called Winsock for programming with TCP/IP-based network connections. Network connections are available for multiple interfaces and peripherals on the TREQ-M4, such as internal 10/100Base-T wired Ethernet, external USB-to-wired

58

TREQ-M4 Mobile Data Terminal

Page 69

Application Development

Software Drivers

Ethernet adapter, external USB to WiFi adapter, and internal Bluetooth Personal Area Network adapter. Refer to section 4.1.6, “Network and Dial-up Connections” and Chapter 7, “Optional Peripherals” for additional information on these interfaces and peripherals. Refer to the following MSDN articles for detailed information and programming reference for the Winsock Windows CE API: http://msdn.microsoft.com/en-us/library/aa926807.aspx http://msdn.microsoft.com/en-us/library/aa925696.aspx Refer to the following MSDN article for Winsock programming samples: http://msdn.microsoft.com/en-us/library/aa916375.aspx Following are some MSDN articles describing networking, connectivity, and using sockets with the .NET Compact Framework: http://msdn.microsoft.com/en-us/library/8y3swehx.aspx http://msdn.microsoft.com/en-us/library/b6xa24z5.aspx

TREQ-M4 Mobile Data Terminal

59

Page 70

Software Drivers

Application Development

Notes

60

TREQ-M4 Mobile Data Terminal