コード例 #1
0
ファイル: CAS140.cs プロジェクト: sanmengxishui/162
        private int OpenDevices()
        {
            dev.Clear();

            int iface = CAS4DLL.InterfaceUSB;
            int dvCnt = CAS4DLL.casGetDeviceTypeOptions(iface);
            int option;
            int res = -1;

            for (int i = 0; i < dvCnt; i++)
            {
                CAS140Mod dv = new CAS140Mod();

                option = CAS4DLL.casGetDeviceTypeOption(iface, i);
                CAS4DLL.casGetDeviceTypeOptionName(iface, i, sb, sb.Capacity);
                dv.serial = sb.ToString();

                dv.devHandle = CAS4DLL.casCreateDeviceEx(iface, option);

                if (dv.devHandle < 0)
                {
                    continue;
                }

                if (!File.Exists(ConfigPathFolder + dv.serial + ".ini"))
                {
                    MessageBox.Show("Error. CAS140 " + dv.serial + " config file Not Found. " + ConfigPathFolder + dv.serial + ".ini");
                    continue;
                }

                if (!File.Exists(ConfigPathFolder + dv.serial + ".isc"))
                {
                    MessageBox.Show("Error. CAS140 " + dv.serial + " calibrate file Not Found. " + ConfigPathFolder + dv.serial + ".isc");
                    continue;
                }

                //setup config, calib
                res = CAS4DLL.casSetDeviceParameterString(dv.devHandle, CAS4DLL.dpidConfigFileName, ConfigPathFolder + dv.serial + ".ini");//"8560142E1"
                if (res < 0)
                {
                    MessageBox.Show("Error. CAS140 " + dv.serial + " config file Not Found. " + ConfigPathFolder + dv.serial + ".ini");
                    continue;
                }
                res = CAS4DLL.casSetDeviceParameterString(dv.devHandle, CAS4DLL.dpidCalibFileName, ConfigPathFolder + dv.serial + ".isc");
                if (res < 0)
                {
                    MessageBox.Show("Error. CAS140 " + dv.serial + " calibrate file Not Found. " + ConfigPathFolder + dv.serial + ".isc");
                    continue;
                }
                res = CAS4DLL.casInitialize(dv.devHandle, CAS4DLL.InitForced);
                if (res < 0)
                {
                    continue;
                }

                dev.Add(dv);
            }
            return(dev.Count());
        }