void Dispose(bool disposing) { ////////////释放非托管资源 if (disposing)//////////////释放其他托管资源 { CloseDevice(); dio = null; mc = null; cmpTrigs = null; } }
public int OpenDevice() { if (!IsInitOK) return (int)ErrorDef.InitFailedWhenOpenCard; if (IsDeviceOpen) return (int)ErrorDef.Success; // Card(Board) initial,mode bit0(0:By system assigned, 1:By dip switch) int ret = 0; lock (SDKLocker) { if (!IsSDKInitialized) { ret = APS168.APS_initial(ref BoardBitsLinked, 0); //可以获取已连接计算机的控制卡的bits if (ret != 0) return (int)ErrorDef.InvokeFailed; IsSDKInitialized = true; } bool isBoardIDExist = false; //检查总线中是否连接有指定BoardID的卡 for (int i = 0; i < 32; i++) if ((BoardBitsLinked & (1 << i)) != 0 && _boardID == (i)) { isBoardIDExist = true; break; } if (!isBoardIDExist) return (int)ErrorDef.BoardIDNotExist; if ((BoardBitsLoaded & (1 << (_boardID ))) == 0) //从Flash中载入参数 { ret = APS168.APS_load_parameter_from_flash(_boardID); //从Flash中载入参数 if (0 != ret) return (int)ErrorDef.InvokeFailed; BoardBitsLoaded |= (1 << (_boardID )); } BoardOpened++; //if(!mdCfg.ContainsItem("Card_" + _boardID)) // mdCfg.AddItem("Card"+ _boardID ,new JFXM) dio = new JFAps168DIO(_boardID); mc = new JFAps168MC(_boardID, mdCfg,this); cmpTrigs = new JFAps168CompareTrigger(_boardID, mdCfg, this); dio.Open(); mc.Open(); cmpTrigs.Open(); AioCount = 0; McCount = 1; DioCount = 1; CompareTriggerCount = 1; IsInitOK = true; IsDeviceOpen = true; } return (int)ErrorDef.Success; }