Beispiel #1
0
 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);
     }
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            PLC = new ActEasyIF();
            PLC.ActLogicalStationNumber = 1;
            PLC.Open();

            timer1.Enabled = true;
        }
Beispiel #4
0
 public Form1()
 {
     InitializeComponent();
     easyIF = new ActEasyIF();
     easyIF.ActLogicalStationNumber = 0;
     _textAppender = new AppendTextDelegate(AppendText);
     PLCOpen();
 }
Beispiel #5
0
 public static void ClosePlc(object sPlc)
 {
     try
     {
         ActEasyIF hPlc = getPlc(sPlc);
         if (hPlc == null)
         {
             return;
         }
         hPlc.Close();
     }
     catch (Exception)
     {
     }
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 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;
     }
 }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
 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);
     }
 }
Beispiel #10
0
        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);
            }
        }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
 /// <summary>
 /// 初始化 Mirle.WinPLCCommu.clsPLC 類別的新執行個體
 /// </summary>
 public clsPLC()
 {
     bolConnectionFlag = false;
     gobjPLC           = new ActEasyIF();
 }
Beispiel #13
0
 private void Form1_Load(object sender, EventArgs e)
 {
     PLC = new ActEasyIF();
     PLC.ActLogicalStationNumber = 1;
     PLC.Open();
 }