-
December 26th, 2012, 02:31 PM
#1
SerialPort Issue
Hi Friends, the following code showing the Message at Customer Display System Which is on COM1 Port with Pc.
the problem is that each time i am running the following code . it overwrites in the same line .is there any
way to clear the Screen the again Display the Message at Customer Display Lcd ? .and Formating the size at Customer Display System. let me know please .any help would be highly appreciated .
Code:
private void SerialPortTest_Load(object sender, EventArgs e){
SerialPort port = new SerialPort();
port.PortName = "COM1";
port.Parity = Parity.None;
port.DataBits = 8;
port.StopBits = StopBits.One;
if (port.IsOpen ){
port.Close();
}
port.Open();
port.ReadExisting();
port.WriteLine("WELCOME TO ALHOKAIR IT ");
port.Close();
port.Dispose();
}
}
Last edited by firoz.raj; December 26th, 2012 at 02:33 PM.
-
December 28th, 2012, 01:54 PM
#2
Re: SerialPort Issue
Your use of the serial port seems OK in this case. What type of data does the hardware device expect (probably will need to look through the data sheet)? Use of hyper terminal (or Putty??) might help in debugging or understanding the protocol.
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
December 29th, 2012, 03:51 PM
#3
Re: SerialPort Issue
Check that there is a CR at the end of the data coming in, if there isn't you will need to set one up, or add one to your code.
-
December 30th, 2012, 02:02 AM
#4
Re: SerialPort Issue
You can avoid the new-line encoding issue by using port.Write(...) and instead using \r and \n for CR and NL characters respectively. If your device is unix-like, the newline would be like:
Code:
port.Write("WELCOME TO ALHOKAIR IT \n");
Or if Windows-like:
Code:
port.Write("WELCOME TO ALHOKAIR IT \r\n");
Or the newline character might be totally ignored (for example, your device might simply expect a string of length N where N is the number of display elements in your sign).
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
January 2nd, 2013, 01:55 AM
#5
Re: SerialPort Issue
Hi Friends, problem is that . i simple want . it needs to print the Text in one line .why it is breaking in Second Line ?.
let me know please . any help would be highly appreciated .
-
January 2nd, 2013, 03:38 AM
#6
Re: SerialPort Issue
Hi Friends, problem is that . i simple want . it needs to print the Text in one line .why it is breaking in Second Line ?.let me know please . any help would be highly appreciated .
-
January 2nd, 2013, 04:59 AM
#7
Re: SerialPort Issue
I think there is insufficient information to answer your question.
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
January 2nd, 2013, 07:52 AM
#8
Re: SerialPort Issue
You are sending 23 characters of data to a 2 line, 20 characters display. I don't understand what else you expect it do?
-
January 2nd, 2013, 08:12 AM
#9
Re: SerialPort Issue
i want to display 23 character in one line .i don't want to display the following text in two line . let me know please .
Code:
"WELCOME TO SILICONSOFT IT"
Last edited by firoz.raj; January 5th, 2013 at 01:44 PM.
-
January 3rd, 2013, 12:51 AM
#10
Re: SerialPort Issue
Since it's (obviously) impossible to display 23 characters simultaneously on a single line of the display, I guess you could scroll the message then. Something along the lines of:
Code:
string message = "WELCOME TO ALHOKAIR IT "; //Padded with some spaces at the end for better readability
const int SINGLE_LINE_WIDTH = 20;
// Probably want to be running this whole loop in a seperate thread to avoid halting the main thread;
int offset = 0;
while( true )
{
//Calculate a wrapped version of the string
string curString = "";
int wrapIndex = 0;
while( curString.Length < 20 )
{
curString = curString + curString.Substring(wrapIndex, Math.Min(SINGLE_LINE_WIDTH, curString.Length - wrapIndex));
wrapIndex = 0;
}
//Pad the string out to 40 characters (seems prudent to always fully-specify the display out)
curString = curString.PadRight(40, ' ');
port.Write(curString);
Thread.Sleep(500); //Wait 500 milliseconds
//Update the offset
offset = (offset + 1) % message.Length;
}
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
January 5th, 2013, 02:33 PM
#11
Re: SerialPort Issue
Still it is showing the same Result . let me know some more idea . it needs to show in one line .any help would be highly appreciated .
Code:
private void SerialPortTest_Load(object sender, EventArgs e){
port.PortName = "COM1";
port.Parity = Parity.None;
port.DataBits = 8;
port.StopBits = StopBits.One;
if (port.IsOpen ){
port.Close();
}
port.Open();
//port.WriteLine("WELCOME TO ALHOKAIR IT ");
// port.Write(DisplayMessage());
DisplayMessage();
port.Close();
port.Dispose();
}
public string DisplayMessage() {
string message = "WELCOME TO ALHOKAIR IT "; //Padded with some spaces at the end for better readability
const int SINGLE_LINE_WIDTH = 20;
// Probably want to be running this whole loop in a seperate thread to avoid halting the main thread;
int offset = 0;
while (true)
{
//Calculate a wrapped version of the string
string curString = "Welcome to Alhokair IT";
int wrapIndex = 0;
while (curString.Length < 20)
{
curString = curString + curString.Substring(wrapIndex, Math.Min(SINGLE_LINE_WIDTH, curString.Length - wrapIndex));
wrapIndex = 0;
}
//Pad the string out to 40 characters (seems prudent to always fully-specify the display out)
curString = curString.PadRight(40, ' ');
port.Write(curString);
Thread.Sleep(500); //Wait 500 milliseconds
//Update the offset
offset = (offset + 1) % message.Length;
}
}
-
February 4th, 2013, 01:59 PM
#12
Re: SerialPort Issue
If you want all your text to be in one line, try using .Write method istead of .WriteLine
He doesn't need a code to scroll the message, the display already has a built in function for that. He just needs to turn on this option using his microcontroller.
Last edited by blacblu; February 4th, 2013 at 02:01 PM.
-
February 4th, 2013, 08:27 PM
#13
Re: SerialPort Issue
Write or WriteLine will make no difference.
This is a piece of hardware that has a FIXED display of 2 lines of 20 characters. Like a calculator, you cannot make the characters bigger or smaller, or place 23 characters in 20 spaces. Please trust me, I have worked with POS for over 20 years.
The idea of scrolling the text, either all the way through the line, or back and forth is actually a very elegant solution, however this does mean that any other working code will have to branch from this loop. The only other option is to LF and show part of the data on the 2nd line, but I guess this is not desirable either.
If none of the above is acceptable then decide to change what you want to display, or buy different hardware.
-
February 5th, 2013, 09:55 PM
#14
Re: SerialPort Issue
You are trying to cram 2 pounds of beans into a 1 pound bag.
Obviously if the hardware display is only xx characters long and you are trying to set xx + nn characters, it isn't going to fit on the same line.
You're kind of lucky that your display wraps at all. Many displays would either truncate or throw an error.
Here are your options:
1) Reduce the length of the string.
2) Let it wrap
3) Write it in multiple lines
Good luck
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|