コード例 #1
0
        private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp     = (SerialPort)sender;
            string     indata = sp.ReadExisting();

            Debug.Print(indata);
            indata = indata.Trim();
            string[] inDataArray = indata.Split(',');

            DylosGraphiteConnection dylos = sender as DylosGraphiteConnection;

            if (inDataArray.Count <string>() > 1)
            {
                Console.WriteLine("---Data Received--- ");
                Console.WriteLine("Small Particle Count = " + inDataArray[0]);
                Console.WriteLine("Large Particle Count = " + inDataArray[1]);

                Socket sendingSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                sendingSocket.Connect(graphiteAddress, graphitePort);

                TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
                int      currentEpochTime = (int)t.TotalSeconds;
                mainForm.smallParticleMessage = string.Format("lwells.dylos.small_particle {0} {1}\n", inDataArray[0], currentEpochTime);
                mainForm.largeParticleMessage = string.Format("lwells.dylos.large_particle {0} {1}\n", inDataArray[1], currentEpochTime);

                Debug.Print(mainForm.smallParticleMessage);
                Debug.Print(mainForm.largeParticleMessage);

                mainForm.SetLogBoxText(mainForm.smallParticleMessage);
                mainForm.SetLogBoxText(mainForm.largeParticleMessage);

                sendingSocket.Send(Encoding.UTF8.GetBytes(mainForm.smallParticleMessage));
                sendingSocket.Send(Encoding.UTF8.GetBytes(mainForm.largeParticleMessage));

                sendingSocket.Close();

                SendHandshake();
            }
            else if (inDataArray.Count <string>() == 1)
            {
                mainForm.SetLogBoxText(inDataArray[0]);
            }
        }
コード例 #2
0
 public MainForm()
 {
     InitializeComponent();
     dylos = new DylosGraphiteConnection(logBox);
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: Polymistis/DylosLogger
 public MainForm()
 {
     InitializeComponent();
     dylos = new DylosGraphiteConnection(this);
 }