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 01:33 PM.
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.
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.
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 .
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 .
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.
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.
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;
}
}
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 01:01 PM.
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.
Bookmarks