public bool funOpenMPLC(ref string errMsg) { try { aeiPLC = new ActEasyIF(); aeiPLC.ActLogicalStationNumber = intStationNumber; if (aeiPLC.Open() == 0) { InitSys.funWriteLog("MPLC_" + intStationNumber + "_Trace", "Open Success!"); return(bolIsConnection = true); } else { InitSys.funWriteLog("MPLC_" + intStationNumber + "_Trace", "Open Fail!|" + errMsg); return(bolIsConnection = false); } } catch (Exception ex) { errMsg = ex.Message; MethodBase methodBase = MethodBase.GetCurrentMethod(); InitSys.funWriteLog("Exception", methodBase.DeclaringType.FullName + "|" + methodBase.Name + "|" + ex.Message); return(bolIsConnection = false); } }
private static bool InitPLC() { try { int.Parse(Globals.sFCJPLC); } catch (Exception) { Log.WriteLog(cLog.InitErr, "PLC Logical Station Number为数字"); return(false); } try { plcFCJPLC = new ActEasyIF(); plcFCJPLC.ActLogicalStationNumber = int.Parse(Globals.sFCJPLC); } catch (Exception ex) { Log.WriteLog(ex); } hPlcTable = new Hashtable(); //hPlcTable.Add(Plcs.FHPPLC, plcFHPPLC); //hPlcTable.Add(Plcs.FOPPLC, plcFOPPLC); hPlcTable.Add(Plcs.FCJPLC, plcFCJPLC); return(true); }
private void button1_Click(object sender, EventArgs e) { PLC = new ActEasyIF(); PLC.ActLogicalStationNumber = 1; PLC.Open(); timer1.Enabled = true; }
public Form1() { InitializeComponent(); easyIF = new ActEasyIF(); easyIF.ActLogicalStationNumber = 0; _textAppender = new AppendTextDelegate(AppendText); PLCOpen(); }
public static void ClosePlc(object sPlc) { try { ActEasyIF hPlc = getPlc(sPlc); if (hPlc == null) { return; } hPlc.Close(); } catch (Exception) { } }
public static int ReadDevice(object sPlc, object sDevice) { int nValue = 0; ActEasyIF hPlc = getPlc(sPlc); try { Monitor.Enter(hPlc); hPlc.GetDevice(sDevice.ToString(), out nValue); Monitor.Exit(hPlc); } catch (Exception) { Monitor.Exit(hPlc); } return(nValue); }
public void funClose() { try { if (aeiPLC != null) { aeiPLC.Close(); aeiPLC = null; bolIsConnection = false; InitSys.funWriteLog("MPLC_" + intStationNumber + "_Trace", "Close!"); } } catch (Exception ex) { MethodBase methodBase = MethodBase.GetCurrentMethod(); InitSys.funWriteLog("Exception", methodBase.DeclaringType.FullName + "|" + methodBase.Name + "|" + ex.Message); bolIsConnection = false; } }
public static int ReadPlc(string sPlc, string sDevice, int nLen, out int lpData) { int nRead = 0; ActEasyIF hPlc = getPlc(sPlc); try { Monitor.Enter(hPlc); nRead = hPlc.ReadDeviceBlock(sDevice, nLen, out lpData); Monitor.Exit(hPlc); return(nRead); } catch (Exception) { Monitor.Exit(hPlc); lpData = 0; return(1); } }
public static bool ConnectPlc(object sPlc) { try { ActEasyIF hPlc = getPlc(sPlc); if (hPlc == null) { return(false); } if (hPlc.Connect() == 0) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
public static bool WriteBlock(object sPlc, object sDevice, int nLen, int[] pValues) { int nRec = 0; ActEasyIF hPlc = getPlc(sPlc); try { Monitor.Enter(hPlc); nRec = hPlc.WriteDeviceBlock(sDevice.ToString(), nLen, ref pValues[0]); Monitor.Exit(hPlc); } catch (Exception) { Monitor.Exit(hPlc); } if (nRec == 0) { return(true); } else { return(false); } }
public static bool WriteDevice(object sPlc, object sDevice, int nValue) { int nRec = 0; ActEasyIF hPlc = getPlc(sPlc); try { Monitor.Enter(hPlc); nRec = hPlc.SetDevice(sDevice.ToString(), nValue); Monitor.Exit(hPlc); } catch (Exception) { Monitor.Exit(hPlc); } if (nValue == nRec) { return(true); } else { return(false); } }
/// <summary> /// 初始化 Mirle.WinPLCCommu.clsPLC 類別的新執行個體 /// </summary> public clsPLC() { bolConnectionFlag = false; gobjPLC = new ActEasyIF(); }
private void Form1_Load(object sender, EventArgs e) { PLC = new ActEasyIF(); PLC.ActLogicalStationNumber = 1; PLC.Open(); }