Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
A

auting82

@auting82
About
Posts
33
Topics
11
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • adding colors css file?
    A auting82

    This is a newbie question, how do I add color only on top of my web page, the rest should remain white..

    Web Development question css json

  • trying to get some measurement data to ASP from Microsoft SQL?
    A auting82

    Hi, I am trying to get some temperature measurement data that I have stored in a SQL data base over on a webpage through asp.net. Instead of getting timestamp with temperature measurement numbers I am getting some code text. Here is my C# code in asp.net This is Measurement.cs file Am working in Microsoft Visual studio:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    using Microsoft.JSInterop.Infrastructure;
    using Microsoft.AspNetCore.Hosting.Server;
    using System.Threading.Tasks;

    namespace AirHeaterControlSystem.Models
    {
    public class Measurement
    {
    public string Timestamp { get; set;}
    public string MeasurementValue { get; set; }
    public string ControlValue { get; set; }

        public List GetMeasurementParameters()
        {
            List measurmentParameterList = new List();
            string connectionString = "DATA SOURCE=LAPTOP-1T8PALVT\\\\CITADEL;UID=LAPTOP-1T8PALVT\\\\AdisP;DATABASE=MEASUREMENTDATA;Integrated Security = True;" ;
            SqlConnection con = new SqlConnection(connectionString);
            string sqlQuery = "Select Timestamp,MeasurementValue,ControlValue from MEASUREMENTDATA";
            con.Open();
    
            SqlCommand cmd = new SqlCommand(sqlQuery, con);
    
            SqlDataReader dr = cmd.ExecuteReader();
    
            if (dr != null)
            {
                while (dr.Read())
                {
                    /\*Measurement ChartValues = new Measurement();
                    ChartValues.ChartYvalue= Convert.ToDouble(dr\[\])\*/
    
                    
                    Measurement measurementParameter = new Measurement();
                    
                    measurementParameter.Timestamp = dr\["TimeStamp"\].ToString();
    
                    measurementParameter.MeasurementValue = dr\["MeasurementValue"\].ToString();
                    measurementParameter.ControlValue = dr\["ControlValue"\].ToString();
    
                    measurmentParameterList.Add(measurementParameter);                  
    
                }
            }
    
            return measurmentParameterList;       
        }
    
    }
    

    }

    Here is my cshtml file,

    @page
    @model AirHeaterControlSystem.Pages.MeasurementModel
    @{
    ViewData["Title"] = "Measurement Parameters";

    }

    Airheater temperature measurement

    ASP.NET csharp database sysadmin asp-net visual-studio

  • Mutlithreading application threading and semaphores?
    A auting82

    This is more of a simulation of a multitask application. The only thing I was trying to do here is to make some slight changes to the code so that I get print outs where Tasks [T1], [T2] and [T3] are not only printing out sequnetally but kind of roandomly in sort of random order. However my C# coding abilites are worse than I would imagine so getting this done anytime soon aitn gonna happen. Furthermore, I couldnt find anything on this Threadclass in C#. I didnt see any examples online where this ThreadClass was used directly in the code.

    C# csharp tutorial question announcement

  • Mutlithreading application threading and semaphores?
    A auting82

    Hi I am trying to develop a multitasking application in C# based on some code I have available that is depicted below. I have tried to do some changes but I am not sure if I put the WaitOne() and Release() methods at the correct places. I am trying to include semaphore for a secure usage of common resources. A semaphore is defined in C# by making a "Semaphore" variable, and use the methods WaitOne() and Release() to access the semaphore services. I want to include name, student number and the semester year in the display information. Sleep(0) statements can be used to test the sharing of common resources. I will use a console application. The print out in console should be something like: [T1]: Student no. [T1]: Student name [T1]: Semester year [T2]: Student no. [T2]: Student name [T2]: Semester year [T1]: Student no. [T3]: Student no. [T1]: Student name [T2]: Student name

    using System;
    using System.Threading;
    //Example in using sleep() and Threads in C#
    namespace ThreadSys
    {
    /// /// Threadclass
    ///
    class ThreadClass
    {
    int loopCnt, loopDelay;
    Thread cThread;
    public string studentname;
    static Semaphore semaphore = new Semaphore(1,1);
    public ThreadClass(string name, int delay)
    {
    loopCnt = 0;
    loopDelay = delay;
    cThread = new Thread(new ThreadStart(this.run));
    cThread.Name = name;

            cThread.Start();
        }
        // The main function in the ThreadClass
        void run()
        {
            Console.WriteLine(" Starting " + cThread.Name);
            do
            {
                loopCnt++;
                Thread.Sleep(loopDelay);
                Console.Write(" ");
                semaphore.WaitOne();
                Console.Write(cThread.Name);
                
                Console.Write(": ");
                Console.WriteLine("Loop=" + loopCnt);
                
                semaphore.Release();
    
            } while (loopCnt < 5);
            // Ending of the thread
            Console.WriteLine(" Ending " + cThread.Name);
    
        }
    }
    
    // The application
    class ThreadSys
    {
        /// /// Start of the main program
        /// 
        static void Main(string\[\] args)
        {
            Console.WriteLine(" Start of main program ");
            // Making 3 threads ..
            ThreadClass ct1 = new
    
    C# csharp tutorial question announcement

  • time requirements in real-times systems?
    A auting82

    Hi Original Griff, the question here is to analyze the system based on real-time requirements. The requirements will be any factor that may affect the running time of the tasks.The real-time involve tasks running in parallel, any common resources used by the system that will affect the timing and the time used by the application. You are saying here that windows is not a real time system, but this is an app created to simulate a real time system that has some tasks running. That's a different thing inst it :confused:? If one disregards the CPU and computer memory which other resources are these tasks sharing when running?

    C# business question workspace

  • time requirements in real-times systems?
    A auting82

    Hi, I am having a hard time understanding some basic concepts in real time systems. I have tried reading up on it but when viewing a concrete system I can't really understand it. The application prints the time, student name, student number and semester year as given in the setup in the program runs a certain amount of loops for all tasks. Scheduler set up: Name Delay Thread#1 95ms Thread#3 187ms Thread#5 463ms When code is executed it looks like this. Print Out: [T1]:11:30:45:808[T3]:11:30:45:825[T5]:11:30:45:825[T1]:Mark Johnson[T1]:152585[T3]:Mark Johnson[T1]:2020 [T5]:Mark Johnson[T1]:2020 [T5]:Mark Johnson[T1]:11:30:45:949[T3]:152585[T1]:Mark Johnson[T1]:2020 [T3]:2020[T5]:152585[T1]:2020[T3]:2020 What are the real time requirements of this application?

    C# business question workspace

  • continuous PING application ?
    A auting82

    Ok thanks. If you would write pseudocode for it, how would it look like based on my initial code?

    C# csharp linq testing beta-testing tutorial

  • continuous PING application ?
    A auting82

    Thanks :) Is there a way I can check all the nodes in the network and also get the number of the nodes in my network segment?

    C# csharp linq testing beta-testing tutorial

  • continuous PING application ?
    A auting82

    Hi , I have here an ping application implemented as a console application. I want to turn this into a continuous ping application. Can someone give me a tip how to change this code so it runs continuously.

    ///////////////////////////////////////////////////////////////////////////////////////////
    ///
    /// PingAppConsile: application testing the ping() connection to a node
    ///
    /// Based on code form Microsoft MSDN about the ping() command
    ///
    /// Version: 1.0: 8-JAN-17: NOS
    ///
    ///////////////////////////////////////////////////////////////////////////////////////////
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Threading;
    using System.Net;
    using System.Net.NetworkInformation;
    //
    namespace PingAppConsole
    {
    class Program
    {
    /// /// //////////////////////////////////////////////////////////////////////////////
    static void Main(string[] args)
    ///
    /// Purpose: the main function in the application handling the ping()communication
    ///
    /// Version: 1.0: 09-FEB-20: Adis Pipic
    ///
    {
    string host, data;
    byte[] buffer;
    int timeout;
    Ping pingSender = new Ping();
    PingOptions options = new PingOptions();
    // Use the default Ttl value which is 128,
    // but change the fragmentation behavior.
    options.DontFragment = true;
    // Create a buffer of 32 bytes of data to be transmitted.
    data = "Rodham street";
    buffer = Encoding.ASCII.GetBytes(data);
    timeout = 120;
    // Name or address of node to access
    host = "www.google.no";
    PingReply reply = pingSender.Send(host, timeout, buffer, options);
    if (reply.Status == IPStatus.Success)
    {
    Console.WriteLine(" Ping communication status for {0}:", host);
    Console.WriteLine(" ------------------------------------------");
    Console.WriteLine(" Address: {0}", reply.Address.ToString());
    Console.WriteLine(" RoundTrip time (mSec): {0}", reply.RoundtripTime);
    Console.WriteLine(" Time to live: {0}", reply.Options.Ttl);
    Console.WriteLine(" Dont fragment: {0}", reply.Options.DontFragment);
    Console.WriteLine(" Buffer size: {0}", reply.Buffer.Length);

    C# csharp linq testing beta-testing tutorial

  • recieveing and splitting serial data from Arduino in C#
    A auting82

    Wow, that's a lot of things :sigh: Have no clue how to transform that into code :confused:. Thanks for the reply anyways

    C# csharp css database linq graphics

  • recieveing and splitting serial data from Arduino in C#
    A auting82

    I have solved this problem and the code is as follows:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.IO.Ports;
    using System.Diagnostics;

    namespace PlantMonitoringApp
    {
    public partial class Form1 : Form
    {

        public SerialPort myport;
        private DateTime datetime;
         string in\_data;
    
        public Form1()
        {
            Sensor newSensor;
            newSensor = new Sensor();
            InitializeComponent();
        }
    
        private void start\_btn\_Click(object sender, EventArgs e)
        {
    
            
            myport = new SerialPort();
            myport.BaudRate = 9600;
            myport.PortName = "COM3";//port\_name\_tb.Text;
            myport.Parity = Parity.None;
            myport.DataBits = 8;
            myport.StopBits = StopBits.One;
            myport.DataReceived += Myport\_DataReceived1;
    
            try
            {
                myport.Open();
                time\_text\_box.Text = "";
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
            
    
            time\_text\_box.Text = "";
    
        }
        void Myport\_DataReceived1(object sender, SerialDataReceivedEventArgs e)
        {
    
            in\_data = myport.ReadLine();
    
            this.Invoke(new EventHandler(displaydata\_event));
            
        }
        private void displaydata\_event(object sender, EventArgs e)
        {
            datetime = DateTime.Now;
            string time = datetime.Hour + ":" + datetime.Minute + ":" + datetime.Second;
            time\_text\_box.Text = time;
    
            string\[\] sensorData = in\_data.Split(new char\[\] { ' ', ' ' });
            List tokens = new List();
           // int tmp1 = int.Parse(tokens\[0\]);
            try
            {
                
                foreach (string s in sensorData)
                {
                    if (s.Length != 0)
                    {
                        tokens.Add(s);
                    }
                }
    
    
                txtTemperature.Text = tokens\[0\];
                txtHumidity.Text = tokens\[1\];
                txtSoil\_moisture.Text = tokens\[2\];
    
               // int tmp1 = int.Parse(tokens\[0\]);
    
    C# csharp css database linq graphics

  • recieveing and splitting serial data from Arduino in C#
    A auting82

    Well you just made me realize how much I don't know :doh: . Where specifically in my code can I put this delay?

    Thread.Sleep(100);

    I really appreciate your effort ,but it would be way more helpful if you could comment on where in my code I can implement this?

    C# csharp css database linq graphics

  • recieveing and splitting serial data from Arduino in C#
    A auting82

    Why is there no guarantee? Sometimes it works, that's the strange part . Any suggestions? :confused:

    C# csharp css database linq graphics

  • recieveing and splitting serial data from Arduino in C#
    A auting82

    Hi, I am fairly new to C# coding so be gentle :laugh: I am trying to receive measurement data from a two sensors DHT11 and soimoisture sensor connected to my Arduino. At this stage I just want to receive the raw measurement data and represent them in separate text boxes. I have almost managed it but I am getting some errors. More specifically I get this error: System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index' Here is my code:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.IO.Ports;

    namespace PlantMonitoringApp
    {
    public partial class Form1 : Form
    {

        private SerialPort myport;
        private DateTime datetime;
        private string in\_data;
    
        public Form1()
        {
            InitializeComponent();
        }
    
        private void start\_btn\_Click(object sender, EventArgs e)
        {
            myport = new SerialPort();
            myport.BaudRate = 9600;
            myport.PortName = port\_name\_tb.Text;
            myport.Parity = Parity.None;
            myport.DataBits = 8;
            myport.StopBits = StopBits.One;
            myport.DataReceived += Myport\_DataReceived1;
            try
            {
                myport.Open();
                time\_text\_box.Text = "";
    
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
    
            // timer1.Start();
    
    
        }
        void Myport\_DataReceived1(object sender, SerialDataReceivedEventArgs e)
        {
    
            in\_data = myport.ReadLine();
    
            this.Invoke(new EventHandler(displaydata\_event));
            /\*String dataFromArduino = myport.ReadLine();
            String\[\] dataTempHumidMoisture = dataFromArduino.Split();
            int Temperature = (int)(Math.Round(Convert.ToDecimal(dataTempHumidMoisture\[0\]), 0));
            //int Humidity = (int)(Math.Round(Convert.ToDecimal(dataTempHumidMoisture\[1\]), 0));
           // int SoilMoisture= (int)(Math.Round(Convert.ToDecimal(dataTempHumidMoisture\[2\]), 0));
            txtTemperature.Text = Temperature.ToString() + "C";
           // txtHumidity.Text = Humidity.ToString() + "%";
            //txtHumidity.Text = SoilMoistu
    
    C# csharp css database linq graphics

  • recieveing and splitting serial data from Arduino in C#
    A auting82

    Hi, I am fairly new to C# coding so be gentle :laugh: I am trying to receive measurement data from a two sensors DHT11 and soimoisture sensor connected to my Arduino. At this stage I just want to receive the raw measurement data and represent them in separate text boxes. I have almost managed it but I am getting some errors. More specifically I get this error: System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index' Here is my code:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.IO.Ports;

    namespace PlantMonitoringApp
    {
    public partial class Form1 : Form
    {

        private SerialPort myport;
        private DateTime datetime;
        private string in\_data;
    
        public Form1()
        {
            InitializeComponent();
        }
    
        private void start\_btn\_Click(object sender, EventArgs e)
        {
            myport = new SerialPort();
            myport.BaudRate = 9600;
            myport.PortName = port\_name\_tb.Text;
            myport.Parity = Parity.None;
            myport.DataBits = 8;
            myport.StopBits = StopBits.One;
            myport.DataReceived += Myport\_DataReceived1;
            try
            {
                myport.Open();
                time\_text\_box.Text = "";
    
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
    
            // timer1.Start();
    
    
        }
        void Myport\_DataReceived1(object sender, SerialDataReceivedEventArgs e)
        {
    
            in\_data = myport.ReadLine();
    
            this.Invoke(new EventHandler(displaydata\_event));
            /\*String dataFromArduino = myport.ReadLine();
            String\[\] dataTempHumidMoisture = dataFromArduino.Split();
            int Temperature = (int)(Math.Round(Convert.ToDecimal(dataTempHumidMoisture\[0\]), 0));
            //int Humidity = (int)(Math.Round(Convert.ToDecimal(dataTempHumidMoisture\[1\]), 0));
           // int SoilMoisture= (int)(Math.Round(Convert.ToDecimal(dataTempHumidMoisture\[2\]), 0));
            txtTemperature.Text = Temperature.ToString() + "C";
           // txtHumidity.Text = Humidity.ToString() + "%";
            //txtHumidity.Text = SoilMoistu
    
    C# csharp css database linq graphics

  • Implementing a moving average
    A auting82

    I just did an assignment for a specific course I am doing at the Uni.This was just meant as a simulation so there really is no further goal behind this. Sensors were suppose to simulate signals from field instruments I guess. Thanks for the help Ralf Maier.

    C# tutorial csharp linq graphics iot

  • Implementing a moving average
    A auting82

    Hi Ralf, I think I have solved the problem now. I created a class for MovingAverageFilter. The only little problem I have left is implementing an automatic sampling by ticking off check box. Struggling with that at the moment. Also I guess I do not have proper Random numbers as I always start off from the same Seed No., would be great to Randomize that properly, so that it creates completely new numbers next time I run the app. See my code: Main Form1.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    using System.Xml.Linq;
    using System.Windows.Forms;
    using System.Globalization;
    using System.Linq;
    using System.Collections.Generic;
    using System.Collections;

    namespace DAQ_Simulator
    {
    public partial class Form1 : Form
    {
    int counter;
    int count_lines;
    System.Timers.Timer t;
    //Log time varibles
    int LoggingTime=56;
    int LogTimeLeft;

        //Sampling variables
        float SamplingTime = 5.9f;        
        private int clickcounterSampling;
        private DateTime datetime;
        private DateTime datetime2;
        private DateTime NextLoggingTime;
        int maxAI = 7;
        int maxDI = 3;
        int maxSid = 9;
        String SensorText;
        String sTxt1;
        String fTxt;
        // Create an array of 10 sensor objects
        Sensor\[\] SensorObject = new Sensor\[10\];
        MA\_Filter\[\] FilterObject = new MA\_Filter\[10\];
        
        public Form1()
        {
            InitializeComponent();
    
            for (counter = 0; counter < maxSid; counter++)
            {
                SensorObject\[counter\] = new Sensor(counter);
               FilterObject\[counter\] = new MA\_Filter(counter); //Create filters
            }        
        }
        private void displaySensorData(object sender, EventArgs e)
        {
        }
        private void groupSampl\_Enter(object sender, EventArgs e)
        {
    
        }
        private void textSampling\_TextChanged(object sender, EventArgs e)
        {
    
    
    
        }
        private void btnSampling\_Click(object sender, EventArgs e)
        {
            txtNextSamplingTime.Text = "5.9sec";
            clickcounterSampling++;
            if (clickcounterSampling == 1)
            {
                txtSensorValues.Text = "TimeStamp        AI.1,      AI.2,
    
    C# tutorial csharp linq graphics iot

  • Implementing a moving average
    A auting82

    Thanks a lot.Have some questions. Trying to understand your code. You are running 5 cycles to save 5 sensor values? What is the measuring value you are referring to?:confused: Are you talking about:

    Analogsensorvalues=sObj[id].GetDigitalValue();

    Because this is where and how I actually enter or get the randomly generated sensor values from the Sensor.cs class.

    // take the samples
    for (int cycle = 1; cycle <= 5; cycle++)
    {
    for (int sensor = 0; sensor <= 6; sensor++)
    {
    AnalogSensorValue[sensor, cycle] = AnalogSensorValues; // <- assign your meassurering-value here instead of 1234
    txtNumberWritings.Text += sensor.ToString(); // do your Textbox-Assignment here as you need
    }
    }

    I tired something here, but not really sure if I understood how I am suppose to store my values.:~ I am just getting 0,1,2,3,4,5,6 in the text box If the code works as intended I should be getting values I have for each sensor?

    C# tutorial csharp linq graphics iot

  • Implementing a moving average
    A auting82

    Hi Ralf, see the links from my GUI, perhaps its easier to understand what I want and what I currently get: Link1: Moving average applied — imgbb.com[^] Link2: What happens — imgbb.com[^] In the filter textbooks I need to see moving averaged filtered values for each sensor A1 up to A7.

    C# tutorial csharp linq graphics iot

  • Implementing a moving average
    A auting82

    Hi again Ralf and thanks for the patience. I understood what OG's method does in terms of the result I got. My problem is now how do I make this list to store my numbers that get generated by the GetAnalog Method. I would need to have historical analog values for each Sensor and then apply OG's method on each sensor array or list , whatever is made. Here is the GetAnalogMethod() from the Sensor.cs class,

    public double GetAnalogValue(double minAnalogVolt=0.00F,double maxAnalogVolt=1.00F)
    {
    if(minAnalogVolt <= AnalogVal && AnalogVal<= maxAnalogVolt) //defines measurement interval for sensor

                 AnalogVal = rSensVal.NextDouble(); //generates values between 0-1
                 return AnalogVal; //return a value        
        }
    

    In here I call this GetAnalogValue() method to generate "random" analog values for each of my sensor IDs:

    for (int id = 0; id < maxAI; id++)
    {
    double AnalogSensorValues = sObj[id].GetAnalogValue(); //for loops runs through the loop and inserts random number between 0-1 for each sensors ID
    sTxt = AnalogSensorValues.ToString("F3");//defines a string variable in order to print out sensor values
    textSensorValues.Text += sTxt + " ";//prints out sesnor values in text box
    txtFilterValues.Text = fTx1;//defines a string variable for moving average filtered values
    txtFilterValues.Text = GetMovingAverage(AnalogSensorValues).ToString("F3");//applies GetMoving Average method and prints the last fuive values in the textbox
    }

    If you see above I store all my sensor ID values in a double variable I call AnalogSensorValues.I should have ideally have had a list so that each value gets stored and can be accessed so that GetMoving Average() method can be applied to it. So yes, that is my problem. Basically sorting these values in a List. This may sound silly, but I don't know how to do it :~

    C# tutorial csharp linq graphics iot
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups