• 検索結果がありません。

関数個別説明

ドキュメント内 GPC-4161 (ページ 69-76)

第 5 章 リファレンス(通信モジュールイベント)

5.2 関数個別説明

【機能】

監視するイベントを指定します。

【書式】

(x86 専用)の定義は以前のバージョンとの互換性のために残されています。

新たにアプリケーションを作成される場合には、(x86、x64 共用)の定義をご使用下さい。

●C 言語

BOOL SetCommMask(

HANDLE Device, DWORD EvtMask );

●Visual Basic

Declare Function SetCommMask Lib "kernel32" Alias "SetCommMask"( _ ByVal Device As Long, _

ByVal EvtMask As Long _ )As Long

●Delphi

function SetCommMask(

Device: THandle;

EvtMask: DWORD ):BOOL; stdcall;

●Visual C# .NET(x86、x64 共用)

[DllImport(“Kernel32.dll”)]

public static extern uint SetCommMask(

IntPtr Device, uint EvtMask, );

●Visual C# .NET(x86 専用)

[DllImport(“Kernel32.dll”)]

public static extern uint SetCommMask(

uint Device, uint EvtMask, );

●Visual Basic .NET(x86、x64 共用)

© 2002, 2016 Interface Corporation. All rights reserved.

) As Integer

●Visual Basic .NET(x86 専用)

Declare Function SetCommMask Lib “Kernel32.dll” ( _ ByVal Device As Integer, _

ByVal EvtMask As Integer _ ) As Integer

【パラメータ】

Device

Win32API の CreateFile で取得したデバイスハンドルを指定してください。

EvtMask

監視するイベントを指定します。通信モジュールのイベントは下記の 2 つを使用してくだ さい。0 を渡すと、どのイベントも監視しません。

定数 意味

EV_EVENT1 通信モジュールとの切断で割り込みを発生(接続監視イベント)

EV_EVENT2 通信モジュールの電源電圧異常割り込みを発生(電源監視イベント)

【戻り値】

本関数が正常に終了した場合には、0 以外の値が返されます。

失敗した場合には、0 が返されます。

【使用例】

●C 言語

HANDLE DeviceHandle;

BOOL Ret;

Ret = SetCommMask(DeviceHandle, EV_EVENT1);

●Visual Basic

Dim DeviceHandle As Long Dim Ret As Long

Ret = SetCommMask(DeviceHandle, EV_EVENT1)

●Delphi var

DeviceHandle: THandle;

Ret: BOOL;

begin

Ret := SetCommMask(DeviceHandle, EV_EVENT1);

end;

●Visual C# .NET IntPtr DeviceHandle;

uint Ret;

uint EvtMask;

EvtMask = IFCCOM_ANY.EV_EVENT1;

Ret = IFCCOM_ANY.SetCommMask(DeviceHandle, EvtMask);

●Visual Basic .NET

Dim DeviceHandle As IntPtr Dim Ret As Integer

Dim EvtMask As Integer

EvtMask = IFCCOM_ANY.EV_EVENT1

Ret = IFCCOM_ANY.SetCommMask(DeviceHandle, EvtMask) 通信モジュールの接続監視イベントを有効にします。

© 2002, 2016 Interface Corporation. All rights reserved.

2. WaitCommEvent

【機能】

イベントが発生するのを待機します。

【書式】

(x86 専用)の定義は以前のバージョンとの互換性のために残されています。

新たにアプリケーションを作成される場合には、(x86、x64 共用)の定義をご使用下さい。

●C 言語

BOOL WaitCommEvent(

HANDLE Device, LPDWORD EvtMask, LPOVERLAPPED Overlapped );

●Visual Basic

Declare Function WaitCommEvent Lib "kernel32" Alias "WaitCommEvent"( _ ByVal Device As Long _

EvtMask As Long, _ Overlapped As OVERLAPPED _ )As Long

●Delphi

function WaitCommEvent(

Device: Thandle;

var EvtMask: DWORD;

Overlapped: POverlapped ): BOOL; stdcall;

●Visual C# .NET(x86、x64 共用)

[DllImport(“Kernel32.dll”)]

public static extern uint WaitCommEvent(

IntPtr Device, out uint EvtMask, ref OVERLAPPED Overlapped );

[DllImport(“Kernel32.dll”)]

public static extern uint WaitCommEvent(

IntPtr Device, out uint EvtMask, IntPtr Overlapped );

●Visual C# .NET(x86 専用)

[DllImport(“Kernel32.dll”)]

public static extern uint WaitCommEvent(

uint Device, out uint EvtMask, ref OVERLAPPED Overlapped );

[DllImport(“Kernel32.dll”)]

public static extern uint WaitCommEvent(

uint Device, out uint EvtMask, IntPtr Overlapped );

●Visual Basic .NET(x86、x64 共用)

Declare Function WaitCommEvent Lib “Kernel32.dll” ( _ ByVal Device As IntPtr, _

ByRef EvtMask As Integer, _ ByRef Overlapped As OVERLAPPED _ ) As Integer

Declare Function WaitCommEvent Lib “Kernel32.dll” ( _ ByVal Device As IntPtr, _

ByRef EvtMask As Integer, _ ByVal Overlapped As IntPtr _ ) As Integer

●Visual Basic .NET(x86 専用)

Declare Function WaitCommEvent Lib “Kernel32.dll” ( _ ByVal Device As Integer, _

ByRef EvtMask As Integer, _ ByRef Overlapped As OVERLAPPED _ ) As Integer

Declare Function WaitCommEvent Lib “Kernel32.dll” ( _ ByVal Device As Integer, _

ByRef EvtMask As Integer, _ ByVal Overlapped As IntPtr _ ) As Integer

【パラメータ】

Device

© 2002, 2016 Interface Corporation. All rights reserved.

EvtMask

変数には、発生したイベントの種類を示すマスクが格納されます。エラーが発生すると、0 が格納されます。通信モジュールイベントでは下記のいずれかが格納されます。

定数 意味

EV_EVENT1 通信モジュールとの切断を検出(接続監視イベント)

EV_EVENT2 通信モジュールの電源電圧異常を検出(電源監視イベント)

Overlapped

デバイスを FILE_FLAG_OVERLAPPED フラグを指定してオープンした場合、OVERLAPPED 構造体 への参照渡しを指定してください。それ以外の場合は NULL を指定してください。

【戻り値】

本関数が正常に終了した場合には、0 以外の値が返されます。

失敗した場合には、0 が返されます。

【使用例】

●C 言語

HANDLE DeviceHandle;

BOOL Ret;

DWORD GetEvtMask;

Ret = SetCommMask(DeviceHandle, EV_EVENT1);

Ret = WaitCommEvent(DeviceHandle, GetEvtMask, NULL);

●Visual Basic

Dim DeviceHandle As Long Dim Ret As Long

Dim GetEvtMask As Long

Ret = SetCommMask(DeviceHandle, EV_EVENT1) Ret = WaitCommEvent(DeviceHandle, GetEvtMask, 0)

●Delphi var

DeviceHandle: THandle;

Ret: BOOL;

GetEvtMask: DWORD;

begin

Ret := SetCommMask(DeviceHandle, EV_EVENT1);

Ret := WaitCommEvent(DeviceHandle, GetEvtMask, nil);

end;

●Visual C# .NET IntPtr DeviceHandle;

uint Ret;

uint SetEvtMask;

uint GetEvtMask;

SetEvtMask = IFCCOM_ANY.EV_EVENT1;

Ret = IFCCOM_ANY.SetCommMask(DeviceHandle, SetEvtMask);

Ret = IFCCOM_ANY.WaitCommEvent(DeviceHandle, out GetEvtMask, IntPtr.Zero);

●Visual Basic .NET

Dim DeviceHandle As Integer Dim Ret As Integer

Dim SetEvtMask As Integer Dim GetEvtMask As Integer

SetEvtMask = IFCCOM_ANY.EV_EVENT1

Ret = IFCCOM_ANY.SetCommMask(DeviceHandle, SetEvtMask)

Ret = IFCCOM_ANY.WaitCommEvent(DeviceHandle, GetEvtMask, IntPtr.Zero) 通信モジュール切断イベントを監視します。

© 2002, 2016 Interface Corporation. All rights reserved.

ドキュメント内 GPC-4161 (ページ 69-76)

関連したドキュメント