コード例 #1
0
ファイル: Program.cs プロジェクト: rhoninn11/Scada_Projekt
        private void GenerateSignal()
        {
            while (!this.powerOffFlag)
            {
                SignalData data = new SignalData();
                data.timeSpan = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;
                data.value    = Math.Sin(data.timeSpan / 1000.0 * 2 * Math.PI * frequency);
                dataQueue.Enqueue(data);

                System.Console.Clear();
                System.Console.WriteLine($"Pomiar czujnika id:{this.id}\n-dla procesu {this.processId} wynosi: {data.value}");
                Thread.Sleep(10);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: rhoninn11/Scada_Projekt
        static void Main(string[] args)
        {
            IPAddress address;
            int       portNumber, sensorId, processId;

            if (ChcekArgs(args, out address, out portNumber, out sensorId, out processId) < 0)
            {
                return;
            }

            IPHostEntry entryPoint     = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress   ipAddress      = entryPoint.AddressList[0];
            IPEndPoint  serverEndPoint = new IPEndPoint(address, portNumber);


            Socket sensorSocket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            Sensor sensor       = new Sensor(sensorId, processId);

            try
            {
                sensorSocket.Connect(serverEndPoint);
                while (true)
                {
                    if (sensor.dataQueue.Count == 0)
                    {
                        continue;
                    }

                    SignalData data  = sensor.dataQueue.Dequeue();
                    byte[]     frame = data.ToBytes();

                    sensorSocket.Send(frame);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }