public void Open(ref ActUtlTypeClass api, int stationNumber, string cName) { api.ActLogicalStationNumber = stationNumber; int iReturnCode; iReturnCode = api.Open(); if (iReturnCode != 0) { throw new Exception(string.Format("打开{2:s}站号{0:d}错误 0x{1:x8}", stationNumber, iReturnCode, cName)); } }
//打开通信接口 public override bool OpenPLC(out string error) { error = ""; try { #if MIT //如果为Null,实例化对象 if (lpcom_ReferencesUtlType == null) { lpcom_ReferencesUtlType = new ActUtlTypeClass(); lpcom_ReferencesProgType = new ActProgTypeClass(); } lpcom_ReferencesUtlType.ActLogicalStationNumber = 01; //逻辑站号 int intState = lpcom_ReferencesUtlType.Open(); if (intState == 0) { return(true); } else { Log.L_I.WriteError(NameClass, intState.ToString()); } //如果打开失败,重新打开一次 intState = lpcom_ReferencesUtlType.Open(); if (intState == 0) { return(true); } #endif return(false); } catch (Exception ex) { error = ex.Message; Log.L_I.WriteError(NameClass, ex); return(false); } }