0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FelicaのIDmをAutoHotkeyで取得する

Posted at

AutoHotkeyでFelicaのIDmを取得するというのをfelicalib.dllを使って行うソースです。

公式サンプルをAutoHotkeyで動作するようにしたものです。

単純にIDmを確認する用途の他、
小規模事務所でのログ記録(PCの利用履歴を個人ごと)など、ちょっとした履歴作成のサポートになるかと思います。

一応、AutoHotkeyのこの機能を利用して、Felicaを置いている間だけ利用できる業務アプリ、という使い方をしています。

Felica.ahk
; FelicaのIDmを返します。   (16進8バイト(文字数では半角16文字)の文字列)
; エラー等では 空欄 を返します。
get_FelicaIDm()
{
    Global DebugMode		; 0:エラーを表示しない。   1:エラーを表示する
    Global Error_text		; エラー発生時、その内容をセットします。
    Error_text =

    ; Felica DLLとの接続処理
    ;
    DLL_path = %A_ScriptDir%\felicalib.dll
	if(FileExist(DLL_path)=="")
    {
        Error_text = felicalib.dllが見つからない。(A)
        Goto ExitProc
    }

    hModule := DllCall("LoadLibrary", str, DLL_path)  ;DLLをロードする

    tmp_NULL = 
    DLL_pasori_open_path = %A_ScriptDir%\felicalib\pasori_open
    pasorip := DllCall(DLL_pasori_open_path, "Str", tmp_NULL)	; pasori = flib.pasori_open() # PaSoRi と接続
    ;msgbox, pasorip:%pasorip%
    if(pasorip==0)
    {
        Error_text = felicalib.dllが見つからない。(B)
        Goto ExitProc
    }

    ; Felicaリーダーとの接続処理
    ;
    DLL_pasori_init_path = %A_ScriptDir%\felicalib\pasori_init
    ret_link := DllCall(DLL_pasori_init_path, "Int", pasorip)
    ;msgbox, ret_link:%ret_link%
    if(ret_link!=0)		; Felicaリーダー側との関係でのエラー。  接続無し、など。
    {
        Error_text = Felicaリーダー側との関係でのエラー。  接続無し、など。
        Goto ExitProc
    }


    ;
    ; Felicaリーダーとの接続オッケーのケース
    ;


    DLL_felica_free_path = %A_ScriptDir%\felicalib\felica_free
    DllCall(DLL_felica_free_path, "Ptr", felicap)


    ; ポーリング処理
    ;
    SystemCode_Any := 0xffff
    DLL_felica_polling_path = %A_ScriptDir%\felicalib\felica_polling
    felicap := DllCall(DLL_felica_polling_path, "Ptr", pasorip, "UShort", SystemCode_Any, "UChar", 0, "UChar", 0)	; felica = flib.felica_polling(pasori, 0xFFFF, 0, 0) # FelCa を読む
    ;msgbox, felicap:%felicap%
    if(felicap==0)		; Felicaが置いてないケースなど、ポーリング不可の状態
    {
        Error_text = Felicaが置いてないケースなど、ポーリング不可の状態
        Goto ExitProc
    }


    ;IDm読み取り処理
    ;
    VarSetCapacity(idm_bytes, 64, 0)	; 変数 idm_bytes に、64バイトの大きさを確保します
    DLL_felica_getidm_path = %A_ScriptDir%\felicalib\felica_getidm
    DllCall(DLL_felica_getidm_path, "Ptr", felicap, "Ptr", &idm_bytes)

    Idm_text =
    Loop, 8
    {
        tmp_no := A_Index - 1
        tmp_Idm_byte := NumGet( idm_bytes, tmp_no, "UChar")
        tmp_16text := "00" . Format("00{1:X}", tmp_Idm_byte)
        StringRight, tmp_text, tmp_16text, 2
        Idm_text .= tmp_text
        ;msgbox, Idm_text : %Idm_text%     tmp_Idm_byte : %tmp_Idm_byte%
    }

    if(DebugMode==1)
    {
        msgbox, Idm_text : %Idm_text%
    }
    Goto ExitProc





    ExitProc:
        DLL_pasori_close_path = %A_ScriptDir%\felicalib\pasori_close
        DllCall(DLL_pasori_close_path, "Ptr", pasorip)	; flib.pasori_close(pasori) # PaSoRi と切断
        DllCall("FreeLibrary", UInt, hModule)  ;開放する

        if(DebugMode==1 && Error_text!="")
            msgbox, エラー : %Error_text%

		Return, %Idm_text%
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?