|
This would suggest that the PositionReceived event is not being fired.
|
|
|
|
|
Greetings,
Yes. But why? Whats wrong? The
public class NmeaInterpreter is a well known one, written by Jon Person, author of "GPS.NET" (www.gpsdotnet.com).
Rgds
Jose
|
|
|
|
|
How the heck would I know? Why not ask the author? He's the best placed person to answer questions about his code. He should be able to tell you why his code is not raising this event.
|
|
|
|
|
It has nothing to do with the author code. It's something I did wrong and now can not uncover. The author has done much sharing. Anyway, thank you for your reply.
Rgds
Jose
|
|
|
|
|
If you think about it, your code will be receiving this event because you have subscribed to it (tick, you have done that) and there is something in the component itself that is triggering the event. Now, this may be raised due to a combination of things that you need to set; the author is the best person to tell you under what circumstances this event is raised, and what else you need to do. As far as I can see in your code, there is absolutely nothing wrong with your syntax.
|
|
|
|
|
Nevermind, the syntax that you should be using to hook up your event is:
GPS.PositionReceived += new EventHandler(OnPositionReceived);
|
|
|
|
|
Or simply:
GPS.PositionReceived += OnPositionReceived;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Greetings,
Just want to add the following:
If you handle events in the Form() where you have the Serial Port, and creating new TextBox on the same Form() where you have the SerialPort, I get no problem and I can read the values in the TextBox. But if you create a new Form2(), and you try to call events on this new Form2(), nothing happens when you open. Should we need to do some more when we open a new Form ()?
Rgds
Jose
|
|
|
|
|
Your code and your questions indicate to me you really need to get a good basic book on C#, and review the fundamentals of the language. Remember: that we were all confused ... once
You need to understand how you subscribe to multi-cast delegates by "hooking them up" using the += operator.
CodeProject has two articles by Jon Person, himself, on his NMEA library, and he gives working examples, like this one, of how to use his code: [^]:
public class HighPrecisionTest
{
private NmeaInterpreter MyInterpreter = new NmeaInterpreter();
private int MaximumDOPAllowed = 6;
private double CurrentHDOP;
public HighPrecisionTest()
{
MyInterpreter.HDOPReceived += new System.EventHandler(OnHDOPReceived);
MyInterpreter.PositionReceived += new System.EventHandler(OnPositionReceived);
}
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Greetings,
In fact I really need to have this book. But did you read the code I posted? It is exactly the same what you post, much more that I can get it working. My problem is on the following question, which apparently is not so easy, and I repeat:
If you handle events in the - lets call Form1() - where you have the Serial Port, and creating new TextBox on the same Form1() where you have the SerialPort, I get no problem and I can read the values in the TextBox (in Form1()). But if you create a new - lets call Form2()-, and you try to call events on this new Form2(), nothing happens when you open. Should we need to do some more when we open a new Form2()?
Any way to "force" the new created Form2() to run the methods?
Rgds and Thank you.
Jose
|
|
|
|
|
If you want a Form you create to have access to, and be able to use, an instance of a Class created outside the Form, you must take action to give the created Form a valid reference to the instance of the Class.
There are several ways to do that; here's an example of one way:
In the Form(s) you create define a Public Property that will hold a valid reference to the NMEA Class:
// in created Forms
// enable access
using NmeaInterpreter;
// to hold reference to instance of NmeaInterpreter
Public NmeaInterpreter theNMEAInterpreter { get; set; }
In the Form that creates the instance of the NmeaInterpreter, at the point where you have a valid reference to an instance of the NmeaInterpreter called 'myInterpreter, and you create the new Form:
// rough sketch of code
NMEAUsingForm newNMEAUsingForm = new NMEAUsingForm();
// insert the reference to the instance of NmeaInterpreter
newNMEAUsingForm.theNMEAInterpreter = myInterpreter;
At this point any method in the created Form(s) can access, and use, the instance of the NmeaInterpreter.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Greetings BillWoodruff,
Thanks for the reply. I am learning.
The question here is slightly different than is proposed.
Please See:
I have a class : public class NmeaInterpreter (well known);
I have a Form2() : where dealing with Serial Ports , and sending NMEA sentences from the GPS module to the class NmeaInterpreter ;
Now I have the main Form1() : where I should get the values (Lat, Longit, North, South, etc.), in TextBoxs ;
How it works:
1. After configuring the Serial Ports, I go out/hide the Form2(Serial Port) , and return to Form1 (main)
2. In main - Form1() - , I should receive sentences formatted sentences in the TextBox .
- Problems:
a) If I create in the Form2(Serial Port), a TextBox to test, I can easily receive, for example " Latitude ", etc.
b) But in Form1(main), where I should deal with events, I cannot do this (and I should receive direct formatted sentences from Class NmeaInterpreter).
Through the "Step Into", I noticed that I get the values in the constructor - public Form1() - but then leaves without sweeping methods. This is what the problem is!
c ) Why it works on Form2(Serial Ports ) and not on Form1(main)?
d ) Any error in the structure built ?
Well, I would like to thank the patience and your support
Jose
|
|
|
|
|
I assume your problem is, that you send the NMEA sentences to a different instance of the NmeaInterpreter than you hooked up your event handler to.
- You should create only one NmeaInterpreter instance in Form1.
- Hook up your event handler there.
- Pass a reference of the NmeaInterpreter instance to Form2 either as constructor parameter or by using a property as already demonstrated by someone else.
- Then you can further adapt the settings and pass the NMEA sentences in Form two.
- Now you should receive the result in the event handler in Form1.
If that doesn't work, you could still consider storing the NMEA sentences in some List and passing them back to Form1. Then you can can send them to the NmeaInterpreter instance from Form1 and receive the result.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Are you the same person, named Jose, who is also Member jfxdasilva [^], and who previously posted an almost identical question: [^] ?
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
I am so sorry for that. I do not understand what's happening. I'm Jose and jxfdasilva is abbreviation of my name. If there is a way we can delete the duplicated post, thanking, but the strange thing is I'm posted once.
Thank you.
Rgds
Jose
|
|
|
|
|
Don't worry, I'm not "accusing" you of anything; I'm just curious. It's possible a server error happened.
Did you find the answer about how to make the NMEA Class instance available to other Forms was useful ?
yours, Bill
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
From what I understand of your post:
You have 2 forms each doing some seperate work with the NmeaInterpreter? I'm curious how that would work based on your code in the post. You just create a new NmeaInterpreter instance and hook up an event. (I assume by now you are using += to hook the event up) Don't you need to define some properties of the receiver (port, type, ...) should the class be "started" (just like a timer object needs the "Start" call to actually launch).
In case you do have 2 seperate forms each doing some part of the work, take out the NmeaInterpreter in another class and pass along the data from that class. You can use new delegates/events for that, and it keeps your send/receive logic in one place, which makes more sense.
I have never seen this construct:
TestBox.Text latitude.ToString = ();
And I'm not sure why you'ld call the ToString on latitude other than a creating a good chance in an exception being thrown.
What's wrong with
TestBox.Text = latitude; ?
hope this helps.
|
|
|
|
|
Greetings V
Thank you for your explanation. I don't know why, but when a post the code, it changed. I had already rectified in other post.
Please See:
I have a class : public class NmeaInterpreter (well known);
I have a Form2() : where dealing with Serial Ports , and sending NMEA sentences from the GPS module to the class NmeaInterpreter ;
Now I have the main Form1() : where I should get the values (Lat, Longit, North, South, etc.), in TextBoxs ;
How it works:
1. After configuring the Serial Ports, I go out/hide the Form2(Serial Port) , and return to Form1 (main)
2. In main - Form1() - , I should receive sentences formatted sentences in the TextBox .
- Problems:
a) If I create in the Form2(Serial Port), a TextBox to test and I could easily receive, for example " Latitude ", etc.
b) But in Form1(main), where I should deal with events, I cannot do this (and I should receive direct formatted sentences from Class NmeaInterpreter).
Through the "Step Into", I noticed that I get the values in the constructor - public Form1() - but then leaves without sweeping methods. This is what the problem is!
c ) Why it works on Form2(Serial Ports ) and not on Form1(main)?
d ) Any error in the structure built ?
Well, I would like to thank the patience and your support
|
|
|
|
|
I'm still not sure how your setup is.
But in Form 2 you set some info (like serial port), how does Form 1 know about it?
You say yourself in a) Putting everything in one class works. I think you might have an NmeaInterpreter instance in form1 and another (different) one in form2
Here's what you should do:
1. Write a wrapper for the NmeaInterpreter class.
2. create delegates/events in that wrapper like "info_received" or something.
3. Setup the properties like serial port, etc in form 2 and pass it to the wrapper.
4. The wrapper should receive the message. in the handler, fire the event made in step 2.
5. make sure form 1 is subscribed to the event "info_received".
Note: depending on how the delegate/event is created you can get the latitude/longitude information. I prefer events with no arguments and just setting the properties before firing the event in the wrapper. When the handler from form 1 launches it just reads out the properties of the wrapper class.
I would encourage you to use the wrapper method, because that will be the single point of entry for your project concerning the third party library (the NmeaInterpreter)
If this does not answer your question, try to go back to your original post and try to rephrase the actual problem and what your trying to achieve. It is very hard for us to understand.
|
|
|
|
|
Thanks for the help V.
I'll try and then inform you of the results.
I apologize for not being explicit in my explanation but tried my best. I'll try to take a snapshot if it helps.
I would like to understand in the academic point of view, why despite generate trigger events in NmeaInterpreter class (this is a fact because I can receive data in Form() Serial Port), cannot directly receive in other created Forms(), despite instantiate, create methods, etc... Only in Form() where is the Serial Port that is possible. Is this means that I cannot receive events generated in Class NmeaInterpreter, in 2 or more Forms() simultaneously?
However, if you use the example (GPS - Deriving British Ordnance Survey Grid Reference from NMEA data), and create another Form(), and in this created Form() attempt to receive events directly from NmeaInterpreter class, instantiating, creating methods, etc... you will see. This example is the closest I can give.
Finally, I wish to inform you that this is purely academic, because I like to intrinsically understand how things work, and these challenges are very helpful.
Kind regards
Jose
|
|
|
|
|
Good evening everyone
although still not understanding why it cannot receive events directly out from the Form() that deals with the Serial Port, got it working using some advice left here. Now a problem arises and I would like to count on your collaboration.
I created a variable in the Form (Serial Port), and get its value in Form (main). From the main, it sends the string to the Class that handles the data, and consequently I can see the textBox no the Form(main).
To do this I created a button that when clicked, sends a stream of data, but then it Stops! Thus, I have always to update by click. Any way to have continues receiving the data stream?
P.S: without using a Timer.
Thank you for the support.
Jose
modified 18-Dec-13 16:24pm.
|
|
|
|
|
hi,
i want to create a menustrip in right hand side like treeview.
i am using visual studio 2010, i drag and drop the menustrip, its automatically going upside of the window and i am check all properties there is no chance to display in right hand side...
i want to create like..
window have two sides ( left and right )
right side have the menu strip like treeview,that is have click event
and click the particular menu corresponding window shows the left side
Regards
Anand Rajan
|
|
|
|
|
look for the Dock property of the control or the HorizontalAlignment if you are using WPF
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
thanks
actually the sub menu are not visible that is inside id the menu...that is my problem i want show all sub menus with menu like tree view...
that is possible..
|
|
|
|
|
|