Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 19th, 2007, 11:41 AM   #1
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
Remotely changing baud rates.

What is the correct way to remotely change the baud rate of an external device? For example I have an LCD module that can be set to multiple baud rates. It defaults to 9600. I have a software application that allows the user to change the baud rate via serial obviously. I am having trouble reconnecting to the LCD module after this change is made. Here is my logic.

Connect to the LCD module via serial at 9600 bits/second using .Net's SerialPort class.
Send the correct byte to inform the LCD module to change its baud rate to 57600.
Close the connection between the LCD module and the host computer.
Open a new connection between the LCD module and the host computer using a baud rate of 57600.

To me this makes sense, however this logic doesn't seem to work. I can not communicate with the device after this.
hoffmandirt is offline   Reply With Quote
Old Nov 19th, 2007, 11:58 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Remotely changing baud rates.

One would need the docs for the LCD module to say much, but are you getting all the other parts right (stop bits, parity, handshaking, etc.)?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 19th, 2007, 12:04 PM   #3
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
Re: Remotely changing baud rates.

I have all of the other parts right. Does this logic sound correct to you? If so, I am more than likely missing something in my code.
hoffmandirt is offline   Reply With Quote
Old Nov 19th, 2007, 12:17 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Remotely changing baud rates.

It just seems strange to me that you can change the baud rate of the LCD device with a single byte. There are, after only, only 256 of those available. What if it occurs in your normal data stream? I would have thought there would be some sort of AT sequence or escape sequence.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 19th, 2007, 1:28 PM   #5
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
Re: Remotely changing baud rates.

The LCD requires two bytes to change the baud rate. The first byte is a byte that indicates that we want to change the baud rate and the second byte is a specific byte that maps to a specific baud rate, which are defined in the LCD documentation. However, I found my problem. This line is taken from the MSDN documentation on the serialport.Close method.

Quote:
The best practice for any application is to wait for some amount of time after calling the Close method before attempting to call the Open method, as the port may not be closed instantly.
Link Here

Now you would think that you could poll the IsOpen property until the port was closed, however you can't because it is set to false as soon as the Close method is called. I guess the question now is how long does it take to close a serial port? Suspending the thread for 1 second, does not work. Suspending for 5 and 2 seconds does work. I'm assuming the time is variable, so it may be best to stick with 5 or maybe 3 seconds.

Last edited by hoffmandirt; Nov 19th, 2007 at 1:52 PM.
hoffmandirt is offline   Reply With Quote
Old Nov 19th, 2007, 2:50 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Remotely changing baud rates.

Let me repeat: you have not previously given us all the information required, which you have subsequently discovered. In the absence of critical information, you have limited us in the applicability of the responses that we might undertake.

Bad boy. You might want to review the FAQ and the "How to Post" entries that tell you that information is the key. It''s just a suggestion, of course, you are perfectly free to disregard such supposedly important stuff.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 19th, 2007, 3:35 PM   #7
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
Re: Remotely changing baud rates.

I will disregard your last comment. I have given you the information that you asked for in the first line of my previous post. Maybe you did not read my post in its entirety, but I said my logic works if I suspend the thread for two seconds. So what does your last comment have to do with escape sequences? At any rate, the close time will depend on how much data is left in the data output buffer and a second or two to fully close the serial port.

The LCD module expects TWO bytes to change the baud rate. There is no AT or escape sequence. It uses control characters.
Quote:
2Bytes(15Hex or 21Dec.) + Dec191=2400,
Dec95=4800, Dec47 = 9600, Dec31=14,400,
Dec23=19,200, Dec15= 28,800, Dec11= 38,400,
Dec7=57,600
hoffmandirt is offline   Reply With Quote
Old Nov 19th, 2007, 4:02 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Remotely changing baud rates.

You may disregard any comments you care too; certainly if you live in the same country I live in. You may also kiss my butt and solve your own problem, if that is your desire.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 19th, 2007, 5:10 PM   #9
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
Re: Remotely changing baud rates.

I would rather solve my own problem than have to listen to a grouch like yourself. Go back to bed.
hoffmandirt is offline   Reply With Quote
Old Nov 19th, 2007, 8:47 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Remotely changing baud rates.

No, thanks. I'd rather stay up and watch you putter around like the amateur stumbler you are.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Legality of Changing Open Source Licenses? Darkhack Coder's Corner Lounge 3 Jul 3rd, 2007 5:40 PM
Website design rates and fees Prm753 Coder's Corner Lounge 3 May 29th, 2007 2:55 AM
Changing The <title> Tags Sane JavaScript and Client-Side Browser Scripting 2 Jul 16th, 2006 11:44 AM
Code is changing a variable that isn't involved davidguygc C++ 4 Dec 7th, 2005 8:45 PM
ADSI Changing Password - Access Denied bobfox Visual Basic .NET 1 Sep 22nd, 2005 1:22 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:02 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC