|
|
Hi Jassim,
You can make use of DispatcherTimer to act like an stopwatch with trigger, to do some action after some elapsed time.
Code:
var timer = new DispatcherTimer
{
Interval = new TimeSpan(0, 0, 3)
};
timer.Tick += timer_Tick;
void timer_Tick(object sender, object e)
{
}
Now you can Start/Stop this timer from the place as per requirement as in below snippet.(say after scan/read complete start the timer)
timer.Start();
So after 3 seconds, your timer_Tick method will invoke.
Thanks,
Raj
|
|
|
|
|
Hi,
When i am trying to read long string like more that 5 characters then characters are splitting.
EX: Q2345456
output - Q2345
public void RecievedData(object sender, SerialDataReceivedEventArgs e)
{
try
{
_RCVData = _SetSerialPort.ReadExisting();
if (SerialDataEvent != null)
{
SerialDataEvent(_RCVData);
}
}
catch (Exception ex)
{
_RCVData = null;
_PortLog.LogHandler("RFIO", Assembly.GetEntryAssembly().GetName().Version.ToString(), 1, this.ToString(), "RecievedData()", ex.ToString());
}
}
modified 17-Feb-14 1:46am.
|
|
|
|
|
Probably, the problem is that serial data is just that: serial. Which means that it arrives one character after another (in reality, one bit after another, but for your purposes you can ignore that), not as a solid "block" of data as it does when you deal with internet or LAN packets.
With serial data, you will get a DataReceived event fired when there is one of more characters received by the computer: it will not wait until they have all been read, because it does not know when the message ends.
So if you want to acquire a complete message, it may take a number of events to get it all - or it might take just one, depending on the load on your PC at that time.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Thanks for your valuable reply, I am not able to find out that how many times event got fired. Can you give any idea.
Thanks
|
|
|
|
|
Keep a class level variable and increment it by one each time?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
OriginalGriff wrote: With serial data, you will get a DataReceived event fired when there is one of more characters received by the computer: it will not wait until they have all been read, because it does not know when the message ends.
Not plain right - The SerialPort class has properties to either fire the event after a certain number of bytes was received, or after a certain character was read (which is essentially why the ASCII code contains stuff like STX and ETX chars).
Women are waiting for love and men are waiting for women. - Wolf Wondratschek
|
|
|
|
|
Um...you might find ASCII predates .NET a bit - I was using STX/ETX and so forth back in the 70's...
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I wasn't saying that these characters where introduced for .Net - These characters were introduced to know when a sequence of unknown size ends, and since this has proven it is adapted within .Net.
Women are waiting for love and men are waiting for women. - Wolf Wondratschek
|
|
|
|
|
Instead of ReadExisting() you can also use ReadTo :
void arduinoBoard_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string data = arduinoBoard.ReadTo("\x03");
string[] dataArray = data.Split(new string[]
{"\x02", "$" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string dataItem in dataArray.ToList())
{
WeatherDataItem weatherDataItem = new WeatherDataItem();
weatherDataItem.FromString(dataItem);
weatherDataItems.Add(weatherDataItem);
}
if(NewWeatherDataReceived != null)
{
NewWeatherDataReceived(this, new EventArgs());
}
}
I used the byte 0x03 in my example because I know that a command always ends with 0x03, but this depends on the communication partner. Depending on your communication protocol you may need to replace 0x03 with something else, but in general you should either know the length of the message you receive, or with which byte it is going to end (In case you only know the message length you'd need to use SerialPort.ReadBytes ).
The reason for that was stated correctly by OriginalGriff: Serial communication means that the information (text) is transmitted byte by byte, and therefore ReadExisting may not grab all the available bytes in the input buffer, because they were not transmitted yet.
I recommend you to read this article[^], it may help your understanding of serial communication and serial ports.
Women are waiting for love and men are waiting for women. - Wolf Wondratschek
|
|
|
|
|
Hello everyone,
I';m trying to learn c# and would like to start a project doing a desktop application. The problem is I don't know where or how to start.
Ive been doing online courses and watch alot of videos on the subject that have given me a understaning of how C# works but when I want to create something new im just clueless what to do.
it almost feels that programming is not for me but im not ready to give up just yet!!
So for my question: Does anyone have any suggestion how to continue ? how do I get the right midset to acually getting started with a project? Is there any course, video or book that you think would be a good idea for me ?
I would be so grateful for any help I can get.
Also i'm sorry if this post has any errors in the placment, structure or there are any information I left out in the question.
This is the first time im trying to learn to code and first time asking any kind of question programing wise and feel abit lost. please be kind despite my ignorance
Thank you for your time and have a good day!
|
|
|
|
|
Unless you are going to work through a tutorial/example then the first thing you need is an IDEA! What are you going to build, what is it going to achieve, why and how.
Once you have that it will define your research scope.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I was thinking something like a shopping system of some kind. Where you can register as a customer browser items and make orders.
if I google this kind of project I find lods of diffrent people doing them but I can seem to find one where there is an easy explanation of whats going on and why.
thanks for the reply !
|
|
|
|
|
You are in trouble already, you start off by wanting to build a desktop application and then want to build a shopping system which is a web based application. You need to clarify your thinking!
The stuff you are looking at are probably fully fledged applications and you will struggle trying to swallow the lot in one go. Decide on your platform/application and break it down to small jobs.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Okay, I thought maybe a desktop application was a bit easier to work with then a web based one when learning, but I guess i was wrong. ill do that! thanks for the advice!
|
|
|
|
|
No you are correct that a desktop app will be easier to build, it is just that Shopping is not a desktop application. Think of single user or networked applications.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Okay, I just wanted to do it for training purposes not really implement a "real" shop. but I guess you are right. ill figure something else out! but as someone else said Im overthinking what I can do. Im better doing some really simple small projects first to get my mind going in the right way of thinking! and then build from there thanks
|
|
|
|
|
Im my humble opinion, computer programming comprises two parts: the language part and the implementation part.
1. Learning the language is relatively easier as the syntax and scope are static, specific, and limited. This can be achieved through reading books, attending courses, or self-study.
2. Implementation is harder as it involves analysis of problems, formulation of problem solving strategies/algorithms into computer programs that are executable by a computer to produce desired outcomes effectively and efficiently. Implementation skills are generic, that is they are independent of programming languages.
In a nut shell, programming languages are just media of implementation for a computer program, the real challenge lies in their effective and efficient utilization in problem solving and this can only be achieve through hands-on practices.
Can you claim to be a swimmer after reading some manuals and watching some video on swimming lessons? Most likely not. The real learning only happens when you get yourself wet in the pool.
So, shift yourself into hands-on mode, start with a simple problem (e.g. number sorting, fibonacci series), formulate the problem solving logic and translate it into a computer program. Do not afraid of making mistakes as mistakes help your learn correctly.
When you are stuck, do not too quick to ask for help, try to find the solution by yourself first. You immediate help-line should be Google, next CP.
When you become more confident and experienced, you may then embark on some serious project.
Wish you success.
|
|
|
|
|
Thank you so much for writing this it puts things in another perspective. Ill follow your advice and some some simple things first !
Thanks again!
|
|
|
|
|
You need an IDEA as someone mentioned. I would go for something like a movie database or CD collection database.
Then you immediately come up with some problems. You've hopefully read about n-tier design. Let's start with that.
Problem #1: How am I going to store the data? ASCII files, Excel, XML or a database (MySQL, PostgreSQL are free as is SQL Server Express) Start with choosing the type of storage.
Problem #2: Storage structure. Probably something you haven't read. Start here[^]
Problem #3: DAL: You'll need to talk to the database, whatever type you choose you'll need to find out how to do that. here's where the coding starts. Start with reading out the data and check if it works by debugging or doing an output to the cmd window (no UI yet!)
Problem #4: DAL: You can talk to the database, can you write to it? Make a unit test or something that adds and updates entries.
Problem #5: BL: Setup constraints and check of your input and output. Create objects you'll need to use and business rules to follow. You can create objects within objects. So eg you can have a DVD object that contains title, duration, ... but also an Actor object that in turn contains lastname, firstname, age, ... For those objects I would use Load and Save functions (save = insert or update depending if the object already existed).
Problem #6: GUI: How would you like to represent the data? With covers and pictures, without? In a grid or with "cards" (or both) will it be web or winforms or wpf? Can you print it?
This is just high level, but the point is to tackle each problem at a time.
If you want to build CRUD applications a DVD/CD collection is a good example. If you want to go into gaming, you'll need GDI+ and keyboard/mouse input/output. In that case snake, mastermind or a card game or something like that is a better option.
Hope this helps.
|
|
|
|
|
Thank you so much for taking the time to write this! This is some really good information and made it a bit more clear how to do start!
This might be another stupid question but Im currently using Visual studio and I have the option to add an Service-based Database, is that a good option? Ive done some googleing and from what I understand they are ok when working on smaller projects.
|
|
|
|
|
FilipJ wrote: Service-based Database
doesn't really matter. Actually if what I read I've read is correct a service based database is a more "real-life" database, where a compact database will be more used for home projects .
|
|
|
|
|
Okay, thank you for helping me !
|
|
|
|
|
FilipJ wrote: This is the first time im trying to learn to code I have good news and bad news for you.
First the good news: you're embarking on a path that is likely to prove interesting, satisfying and rewarding, and will hopefully open the door to a great new career.
Next, the bad news: you seem to have bitten off more than you can chew. I suggest you take small steps first - learn programming (and C#) by building small, very focused console applications. A console app runs in a command window and has no GUI. The purpose of this multi-month long exercise is to become familiar with programming in general, as well as the rich .NET framework.
- Start by building trivial applications that perform simple math calculations (e.g. addition, multiplication, identifying unique numbers in a collection, etc.)
- Next, get to know how to process character strings.
- Along the way, introduce yourself to the different types of collections (lists, arrays, dictionaries, sets) and see how and where they're used.
- Then, take a step into LINQ (Language Integrate Query Language) and see how LINQ makes it easy to do the things you did manually when you started working with collections.
- Get to know to read and write files (text files, binary files and compressed files).
- Then, introduce yourself to XML serialization and learn how to store and retrieved structured data from an XML file.
- Next, discover simple data access from a database and introduce yourself to the basics of SQL.
- Dip your toes into the wonderful world of fetching data from the internet and learn how to use the
HttpClient class.
By this time, you'll have enough under your belt to move from a command line app to building one with a GUI. I recommend starting out with Windows Forms - although an older technology, it offers an easy way to learn event driven programming, which is different from sequential user-directed programming.
I guarantee you hours of frustration, punctuated with moments of sheer joy. Feel free to ask questions of the CP community. We're a helpful bunch of guys and gals and will try our best to assist whenever we can.
/ravi
|
|
|
|
|
My first project (Not too long ago) was a utility to organize files on my disk. it was a console application. all it did was create a folder for each Document file type pdf doc txt in my documents folder and then search my hard drive and move the files to the respective folders.
It doesn't have to be a hard project to see if you like doing this kind of stuff.
Hope this gives you a few Idea's.
David
|
|
|
|
|