Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) PC/SC Async Wait for Smart Card Status Change (Inserted, Removed from Reader, etc.)See more SCard ExamplesDemonstrates how to start an asynchronous Chilkat task to wait for a status change, such as for a smart card to be inserted into a reader, or removed from a reader. After starting the background task, the code loops to check on the status of your task. Note: Instead of writing a loop to wait for the status change, your application might periodically check the task status via a timer event or something similar. The purpose of this example is to show (1) how to start the async task, and (2) how to periodically check the status of the task. Note: This functionality was introduced in Chilkat v9.5.0.87.
load ./chilkat.dll # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set scard [new_CkSCard] # First establish a context to the PC/SC Resource Manager set success [CkSCard_EstablishContext $scard "user"] if {$success == 0} then { puts [CkSCard_lastErrorText $scard] delete_CkSCard $scard exit } # Get the list of all readers. set stReaders [new_CkStringTable] set success [CkSCard_ListReaders $scard $stReaders] if {$success == 0} then { puts [CkSCard_lastErrorText $scard] delete_CkSCard $scard delete_CkStringTable $stReaders exit } # Create a Chilkat task to wait for a max of 1 hour (3600 seconds, or 3600000 milliseconds) for any smart card reader status change. set json [new_CkJsonObject] # task is a CkTask set task [CkSCard_GetStatusChangeAsync $scard 3600000 $stReaders $json] if {[CkSCard_get_LastMethodSuccess $scard] == 0} then { puts [CkSCard_lastErrorText $scard] delete_CkSCard $scard delete_CkStringTable $stReaders delete_CkJsonObject $json exit } # Start the task in a background thread. set success [CkTask_Run $task] if {!$success} then { puts [CkTask_lastErrorText $task] } # Loop until the task is finished, which happens when any reader's status changes. # Instead of looping here, your application could periodically check on the task status in some other way, # such as in a periodic timer event.. while {[CkTask_get_Finished $task] != 1} { # Sleep 100 ms. CkTask_SleepMs $task 100 } # When we call GetStatusChangeAsync, what's really happening is that GetStatusChange is being called in a background thread. # It returns a boolean (success/failure). Therefore, we call task.GetResultBool to get the boolean returned by GetStatusChange # in the background thread. set success [CkTask_GetResultBool $task] if {$success == 0} then { # The call to GetStatusChange in the background thread failed. Let's find out why by getting the LastErrorText # for the background synchronous call. puts [CkTask_resultErrorText $task] } delete_CkTask $task # If the background call to GetStatusChange succeeded, then the result was placed in the last arg, # which was our variable named "json". if {$success == 0} then { delete_CkSCard $scard delete_CkStringTable $stReaders delete_CkJsonObject $json exit } # Let's see what happened... CkJsonObject_put_EmitCompact $json 0 puts [CkJsonObject_emit $json] puts " " # See the Wait for Smart Card Insertion/Removal Example for details about parsing the returned JSON. # Applications should always release the context when finished. set success [CkSCard_ReleaseContext $scard] if {$success == 0} then { puts [CkSCard_lastErrorText $scard] } # Note: It may be necessary to call FinalizeThreadPool in some programming environments just before your program exits. # (Not after every async function call, but only before program exit.) # See Call FinalizeThreadPool before program exit delete_CkSCard $scard delete_CkStringTable $stReaders delete_CkJsonObject $json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.