using namespace System;
using namespace System::Runtime::InteropServices; 

[DllImport("TUSBSCN2.DLL", CallingConvention = CallingConvention::Cdecl)]
extern short Tusbs03cn2_Device_Open(short id);
[DllImport("TUSBSCN2.DLL", CallingConvention = CallingConvention::Cdecl)]
extern void Tusbs03cn2_Device_Close(short id);
[DllImport("TUSBSCN2.DLL", CallingConvention = CallingConvention::Cdecl)]
extern short Tusbs03cn2_Counter_Read(short id, unsigned char ch, int *xData, unsigned char *Valid);
[DllImport("TUSBSCN2.DLL", CallingConvention = CallingConvention::Cdecl)]
extern short Tusbs03cn2_Ext_Input_Set(short id, unsigned char ch, unsigned char UpDown);
[DllImport("TUSBSCN2.DLL", CallingConvention = CallingConvention::Cdecl)]
extern short Tusbs03cn2_Counter_Mode(short id, unsigned char ch, unsigned char mode);
[DllImport("TUSBSCN2.DLL", CallingConvention = CallingConvention::Cdecl)]
extern short Tusbs03cn2_Gate_Time(short id, unsigned char ch, unsigned char time);
[DllImport("TUSBSCN2.DLL", CallingConvention = CallingConvention::Cdecl)]
extern short Tusbs03cn2_Cnt_Clock_Set(short id, unsigned char ch, unsigned char clk);
[DllImport("TUSBSCN2.DLL", CallingConvention = CallingConvention::Cdecl)]
extern short Tusbs03cn2_Divider_Set(short id, unsigned char ch, unsigned char div);

static String^ Tusbs03cn2_GetErrMessage(short retcode)
{
    switch (retcode)
    {
        case 0:
            return "正常終了しました";
        case 1:
            return "ID番号が不正です";
        case 2:
            return "ドライバがインストールされていません";
        case 3:
            return "すでにデバイスはオープンされています";
        case 4:
            return "接続されている台数が多すぎます";
        case 5:
            return "オープンできませんでした";
        case 6:
            return "デバイスがみつかりません";
        case 7:
            return "オープンされていません";
        case 8:
            return "パラメータエラー";
        case 9:
            return "USB通信エラーです";
        default:
            return "不明なエラーです";
    }
}

