Esempio n. 1
0
        public override async Task ReadSingleAsync(string address)
        {
            VerifyConnectedAndValidateAddress(address);

            (int dbIndex, int signalIndex) = GetIndexFromAddress(address, Datablocks);

            if (dbIndex >= 0 && signalIndex >= 0)
            {
                await _semaphoreSlim.WaitAsync();

                await _plcReader.ReadAsync(address);

                _semaphoreSlim.Release();
            }
            else
            {
                throw new Exception($"Plc Read Error - Unknown error occured while attempting to read from: {address}");
            }
        }
Esempio n. 2
0
        public override async Task ToggleBitAsync(string address)
        {
            VerifyConnected();

            if (!AddressIsBoolType(address))
            {
                throw new Exception($"Plc Write Error - Attempting to toggle a non boolean address: {address}");
            }

            (int dbIndex, int signalIndex) = GetIndexFromAddress(address, Datablocks);

            if (dbIndex >= 0 && signalIndex >= 0)
            {
                // await DelayAsync(5);
                // double val = Datablocks[dbIndex].Signals[signalIndex].Value;

                //_collectedPlcTasks.Add(new PlcToggleTask(address, val));

                Console.WriteLine($"ToggleBitAsync BEG sec {System.DateTime.Now.Second} ms {System.DateTime.Now.Millisecond}");
                await _semaphoreSlim.WaitAsync(5);

                var readVal = await _plcWriter.ReadAsync(address);

                bool r = (bool)readVal;



                await _plcWriter.WriteAsync(address, !r);

                _semaphoreSlim.Release();
                Console.WriteLine($"ToggleBitAsync END sec {System.DateTime.Now.Second} ms {System.DateTime.Now.Millisecond}");
            }
            else
            {
                throw new Exception($"Plc Write Error - Unknown error occured while attempting to toggle: {address}");
            }
        }