#299636 - 23/06/2007 07:32
VB.NET problem
|
addict
Registered: 27/10/2002
Posts: 568
|
Hi, all.
I have a problem with Visual Studio 2005 that I hope someone can help me with.
I have a Passat 2006 which I, of course, have installed my Empeg in. It also has a display in the dashboard where radio info and such shows up, and it's controlled with CAN messages. I'd like to get the info from the Empeg up there and since I haven't found much info on the Internet about addresses and protocols for doing that, I figured I would try to reverse-engineer the info from the radio. The problem is that the radio gives out some information and then expects some answers before it gives out more info. So I made a small program that would listen to the radio (the CAN messages, that is... :-) ) and answer it so that I could get some more info out of it and eventually, hopefully, be able to get the info to the display.
So, to my problem... I have managed to listen to the messages from the radio and print them out in a textbox, but I haven't been able to get timers to trigger. Can anyone help me with that? I have enclosed the source, but I have to warn you: I'm not a programmer...! So it's probably a lot of bad code and bad programming there. There's also left-over code from when I started to make it in VB6.
TIA, Stig
Attachments
300756-VS2005.zip (55 downloads)
Edited by Roger (23/06/2007 08:08)
|
Top
|
|
|
|
#299637 - 23/06/2007 18:57
Re: VB.NET problem
[Re: StigOE]
|
carpal tunnel
Registered: 10/06/1999
Posts: 5916
Loc: Wivenhoe, Essex, UK
|
I'm finding it hard to follow the code, I more used to C# nowadays, but I think your timers are just never getting enabled.
The timers only ever seem to get enabled in Check, which only gets called by OnDataReceived, which would only get called if DataReceived was called, which will only get called if you successfully receive some data.
If I put this in the cmdConnect_Click code:
tmrOut439.Enabled = True
Then the timer fires successfully.
_________________________
Remind me to change my signature to something more interesting someday
|
Top
|
|
|
|
#299638 - 23/06/2007 20:19
Re: VB.NET problem
[Re: andy]
|
addict
Registered: 27/10/2002
Posts: 568
|
Quote: I'm finding it hard to follow the code <snip>
He he, I did warn you...
To me it also seems like the timers don't get enabled, and yes, they are only enabled in Check, but if I set a breakpoint in Check where the timers are (or should be...) enabled, it breaks there when I receive data. I have tried to google for answers and to me it looks like it should work, but still it doesn't... I also get a lot of warnings in the Immidiate Window about Invalidcast or something. I don't know if that could be some of the problem. I'll check them tomorrow to get the correct text...
Edit: Here's the error messages I get when I run the program.
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
There are several of each of them and I think they are from the build process.
Oh yes, another 'problem'. How can I get the textbox to stay at the last 'entry'? Now it jumps to the beginning of the text. Is this because the way I add text to the textbox, is by setting the text to be the old text & new text? Would it be better to use a richtextbox instead?
Stig
Edited by StigOE (24/06/2007 07:20)
|
Top
|
|
|
|
#299639 - 25/06/2007 09:51
Re: VB.NET problem
[Re: StigOE]
|
new poster
Registered: 07/04/2001
Posts: 23
Loc: Lancs UK
|
Quote: Oh yes, another 'problem'. How can I get the textbox to stay at the last 'entry'? Now it jumps to the beginning of the text. Is this because the way I add text to the textbox, is by setting the text to be the old text & new text? Would it be better to use a richtextbox instead?
If you update the text in the textbox using:
textbox1.selectedtext = "new text"
with this method there is no need set the textbox equal to what is already there + the new text.
then use:
textbox1.scrolltocaret()
this will leave the textbox displaying the last entry you added, you will also need vertical scrollbars enabled too.
Mark.
|
Top
|
|
|
|
#299640 - 26/06/2007 07:22
Re: VB.NET problem
[Re: Rufus]
|
addict
Registered: 27/10/2002
Posts: 568
|
Thanks, Mark. That worked.
And I found the problem with the error messages. They're not from the build process, but from when the data coming in isn't a full string, so it fails when I try to chop it up, and the Immidiate window isn't clearing for each time I run the program...
Now, for the timers, I put in a 'Console.write' line in the check routine, writing the interval and whether Enabled is true or false, and they're getting set. Could the problem be that since the Check routine is called from the 'data-received-from-serialport' routine, which is running in a different thread and the timers should be running in the GUI thread, be why they aren't firing?
Stig
|
Top
|
|
|
|
#299641 - 26/06/2007 08:22
Re: VB.NET problem
[Re: StigOE]
|
old hand
Registered: 14/04/2002
Posts: 1172
Loc: Hants, UK
|
I haven't used VB.NET much, but are the timer handlers actually linked to the timer object? Occasionally often in .NET projects I find the handlers get deleted or unlinked.
|
Top
|
|
|
|
#299642 - 26/06/2007 13:22
Re: VB.NET problem
[Re: StigOE]
|
carpal tunnel
Registered: 10/06/1999
Posts: 5916
Loc: Wivenhoe, Essex, UK
|
Don't think it is a threading issue, that only really affects controls that have a user interface, I have used timers perfectly successfully in similar threaded cases (and the timer component doesn't have an Invoke method, which it would have if it was affected).
_________________________
Remind me to change my signature to something more interesting someday
|
Top
|
|
|
|
#299643 - 26/06/2007 13:40
Re: VB.NET problem
[Re: andy]
|
addict
Registered: 27/10/2002
Posts: 568
|
g_attrill: I have absolutely no idea... But it works if I enable them in a button-click routine.
Andy: Ok, thanks. I'll try to modify the code some and see if I can get it working some other way...
Stig
|
Top
|
|
|
|
#299644 - 26/06/2007 19:26
Re: VB.NET problem
[Re: StigOE]
|
addict
Registered: 27/10/2002
Posts: 568
|
I managed to get the timers sort of working by setting a flag for the timers in the Check routine and then start another timer when I click the Connect button which fires every ms which in turn checks the flags and starts the other timers as needed... Now I just have to get some more data out of the radio and see if I can find out how to emulate the radio...
Stig
|
Top
|
|
|
|
|
|