|
Sry for the wierd title. I made a simple program to dump data from a serial COM port. My question is how to wire the device to the serial female port so that the computer can recive the data. I am using a parallax Ping))) sensor that is already programmed to a basic stamp microcontroller. If i run the signal wire to the serial port pin 2, will I need to attach serial port pin 5 (signal ground) to the ground on the microcontroller in orderto recive a signal in the com port? The ping has an onboard A/D converter so the data is digital. P.S. If analog "data" is sent into the serial port raw, will it be converted by to computer or will bad things happen (i.e. nothing).
|
|
|
|
|
The subject line was quite OK. However this is not a C# question, so you're in the wrong forum.
yes, you must connect the GND pin of the PC serial port to the GND potential of your peripheral.
no, you can't feed analog signals into your PC's serial port.
yes, you can cause permanent damage when treating your serial port pins badly.
since you feel the need to ask, don't try this on your motherboard's serial port, as repairing it would be expensive; use either a plug-in serial card or a USB-to-RS232C cable instead.
PS: there are several CodeProject articles that discuss the use of serial ports.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
|
Hello,
I have a project for school and I need it finished a in a few days.
What the project does is reads data from a txt file. Each row of the txt file contains a timestamp hh:mm:ss,mmm (example: 00:05:33,141).
Whenever the system time is equal to one of the records, I need to send data to a tcp client.
What I did is created a thread with a while(true) in it and verified if a row contains the current time, than send the data.
That is not good because it's not efficient.
I would need something like a timestamp event (not using Timer).
Any suggestions/code samples? I would appreciate some help here a lot. Unfortunately I am not good with writing custom events
So for example I would need an event that will occur on a given time. Example:
event(double time,DoThis) . If time is equal to timestamp, than execute function DoThis.
In this way I would avoid a while(true) that will eat all processor.
Also, System.Threading.Seep is not an alternative because I need this to be precise.
Can someone help?
Thanks!
|
|
|
|
|
here are a few things for starters:
1.
you need to get your jobs sorted chronologically, so if your file isn't, sort it first.
2.
Windows timing has limited accuracy. You may want to read Timer surprises, and how to avoid them[^] to get the picture.
3.
if you want both good performance and good accuracy (1 second or better), you'll need something clever, probably a combination of some of these: a general timer, a multi-media timer, a stopwatch, a busy loop.
4.
if consecutive events are close together, you'll need to take extra care.
Now study, and work on your project.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hello,
Thanks for the reply. I don't want to be rude, but it does not help to much.
1. It's sorted chronologically
2. I am already using multimedia timer, and I don't need 1000000 millisecond precission. The time is like : hh:mm:ss,mmm (first 3 digits from milliseconds).
3. This is what I don't know how to do. As I said, I tried in a while(true) loop, and it worked perfectly, but that's not efficient. That's why I was thinking of a custom event. The windows forms timer is similar to what I want, but it's not good. The windows forms timer receives an interval and you call start. Instead of this, I would need something like SetFinalTime(time,WhatToDo). When time equals the system time, than execute the function WhatToDo . That would be my idea, but I don't know how to implement it.
Believe me,I did my reading
4. They are close, yes, but I will figure that out on the way. First I need point 3 solved ... the event (or any other suggestion).
Thanks!
Vlad
|
|
|
|
|
So you have the necessary tools in your tool box. Switch on the brain cells.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I really tried, believe me, but I have no ideas how to do it. SImply no ideas. If I had ideas, I wouldn't have posted here
|
|
|
|
|
If (as you say to Luc) the data is sorted in date time order then why not work out the number of seconds between now and the next message being due, and set up a timer for that interval. Start the timer as a single-shot, and when it fires...
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
It's true that while running through a loop constantly is not very efficient it is going to be the most accurate for you. What you really need to decide is how accurate you really need this to be.
You say that when you match up with one of the times you have you will send data to a TCP client, sending data over the network (unless the destination is actually your own machine) will have a small delay of some milliseconds to actually get sent and then it will be a little longer before it arrives at where it needs to be. That being the case you may be able to set up a standard System.Timers.Timer and use a reasonably small Tick (say 50 milliseconds or something).
All you'd need to do then is know the current time and check to see if there are any times in your list that you have gone past since the last time you checked. In this case there would be a maximum delay of 50ms since the time in your list but of course you could lower it for a little more accuracy (Keeping in mind that at the best of times the standard timer will only get called every 20ms) or indeed make the gap larger which would save some of your precious CPU time.
There's no way you're going be able to set up any kind of event that will be fired accurately down to the millisecond, even with a while loop and a performance counter it's easily possible that you may skip past a time (and therefore miss the event or fire it 'late'). So like I said you need to decide how much delay you can tolerate if the answer is 'None' then you will have to stick with your while loop because that is as accurate as it's going to get
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
I think I have a decent solution to your problem which would give the accuracy you want without killing the CPU:
class bleh
{
List<DateTime> times;
DateTime next;
bool quit = false;
void main()
{
while(!quit)
{
bool resting = false;
next = ...;
do
{
resting = false;
TimeSpan diff = next - DateTime.Now;
if(diff > someVal)
{
resting = true;
sleep;
}
}
while(resting);
while( true )
{
if(DateTime.Now >= next)
{
fire event;
break;
}
}
}
}
}
You'd want to be running this in a separate thread so it doesn't interfere with your main application and you'll want to replace DateTime.Now and whatnot with queries to your multimedia timer and you may also have to add some stuff for events that are very close together.
Basically if there is a large enough gap in time before the next event you should be able to afford to put the thread to sleep and when you get close to the event you will have to go into the while loop to make sure that the event is fired as close to the specified time as possible. What amount of time you use to switch between sleeping and looping is entirely up to you and I imagine will involve some experimentation.
Well, I hope that gives you some idea on what you could do to improve performance, without (hopefully) sacrificing too much accuracy.
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
example ebout style button
|
|
|
|
|
question
See how annoying that is?
Do you have a question?
Read the instructions at the top of the page "how to get an answer to your question".
Then edit your post to comply. Then, maybe, you will get help.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
See here. This will help you ask a question so that you can get an answer.
My signature "sucks" today
|
|
|
|
|
Don't you know, how to phrase a complete sentence?
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Hello,
I have developed an point of sale desktop application. I have integrated the Customer Display too with this app. Now i am facing a little issue, When ever Customer display writes some thing on it, it takes around 3 seconds to write always whatever i write, 3 Seconds is too much and its slowing down the speed of app. ANy suggestions..?
|
|
|
|
|
tell us more about the "Customer Display". Is it a commercial product? what is the interface (hardware and software)? is there a handshake protocol involved? maybe show relevant code (inside PRE tags!).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
The first step is to time the different steps of the process to identify which is taking the most time. Often the bottleneck isn't where you suspect it is.
Only after you know what's slowing down the process can you start to correct it.
|
|
|
|
|
Hello,
When i am trying to copy stringbuilder to string it copies the same string twice or 3 times
for example if i do:
stringbuilder temp=new stringbuilder();
string temp1;
temp1=temp.tostring();
if temp="abc";
then temp1 gets- "abcabcabc"
why is that?
|
|
|
|
|
Try !ispostback
try and try untill reach success..
|
|
|
|
|
|
IsPostback is relevant to ASP.NET. The OP did not say what environment he was using so your answer could be completely irrelevant and worse misleading.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You haven't shown any code that actually adds values to the stringbuilder. Where is that? Are you calling it multiple times perhaps.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I fount my mistake.
I had a method that returns a stringbuilder and receives a stringbuilder.
for example:
private stringbuilder method1(stringbuilder temp)
{
temp.append("abc");
}
private void main_method()
{
stringbuilder main=new stringbuilder();
main.append(method1(main));
}
something like that
|
|
|
|
|
michaelgr1 wrote: if temp="abc";
Hmmmm....
Show us as much of the actual associated code as you can...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|