Close() public method

Disonnects from the plc and close the socket
public Close ( ) : void
return void
Example #1
0
 public override void DisConnect()
 {
     if (_plcReader != null && _plcWriter != null)
     {
         _plcReader.Close();
         _plcWriter.Close();
         // _plcReadTimer.Stop();
     }
     ComState = ComState.DisConnected;
     ComState = ComState.DisConnected;
 }
Example #2
0
        static void Main(string[] args)
        {
            S7.Net.Plc plc     = new Plc(cpu: CpuType.S71200, ip: "10.1.10.142", rack: 0, slot: 1);
            ErrorCode  errCode = plc.Open();

            var       b1    = (UInt16)plc.Read("MW100");
            ErrorCode write = plc.Write("MW102", 100);

            plc.Close();

            System.Console.WriteLine(b1);
            Console.ReadLine();
        }
Example #3
0
        //public string LastError { get; private set; }
        public override async Task ConnectAsync()
        {
            ComState = ComState.Connecting;

            await DelayAsync(1000);

            S7.Net.CpuType S7NetCpuType = ConvertCpuType(Config.CpuType);

            try
            {
                string ip = "100.67.165.113";
                _plcReader = new Plc(S7NetCpuType, ip /*Config.Ip*/, (short)Config.Rack, (short)Config.Slot);
                _plcWriter = new Plc(S7NetCpuType, ip /*Config.Ip*/, (short)Config.Rack, (short)Config.Slot);
                await _plcReader.OpenAsync();

                await _plcWriter.OpenAsync();

                if (_plcReader.IsConnected && _plcWriter.IsConnected)
                {
                    ComState = ComState.Connected;
                }
                else
                {
                    ComState = ComState.ConnectFailed;
                    if (_plcReader.IsConnected)
                    {
                        _plcReader.Close();
                    }
                    if (_plcWriter.IsConnected)
                    {
                        _plcWriter.Close();
                    }
                }
            }
            catch (Exception)
            {
                //LastError = ex.Message;
                ComState = ComState.ConnectFailed;
            }
        }