38.9.5.6 Prohibit Double Calling API

API double calling

WinGP SDK prohibits calling another device access API during a call to one device access API (Double calling). However, the device access API is operating the message pump in the API, so if an event happens, the user program starts.

In the course of the message processing routine, double calling might occur when API is called.

The following shows a case resulting in double calling:

  1. Double calling by touching two buttons
    There are two buttons, A and B. If you press A, it calls the device read API. If you press B, it calls the device write API.
    In this case, if you press B button while calling the device read API while pressing A button, the device write API is also called, which leads to API double calling and an error results.

  2. Double calling with a timer
    A timer event is often used for cyclic processing in Windows program. Program carefully for programs using the timer event; otherwise, API double calling might result.
    The following situations will cause errors when using the timer event.

    1. Call, read, and display the device read API cyclically once every second.

    2. Pressing the button calls the device write API and writes the value into the device.

    During reading triggered by a timer event in 1), the 2) button is pressed and the 2) processing starts.
    During the 2) writing, a timer event occurs and the 1) reading is performed.

Solutions to avoid API double calling

The following shows solutions to avoid API double calling.

  1. In the user program, improve the algorithm to prevent API double calling.
    For example,

  1. Do not process messages in the API
    Call EasySetWaitType() with the argument 2. In this case, other messages than that causing double calling are not processed either, which may lead to other problems such as the applications performing unintended operations.