Page 1 of 1

Linux and perl problem

Posted: Thu Dec 05, 2002 10:46 pm
by unstabl1
I'm having trouble sending the command codes to my display with perl. Everything seemed to be working fine until I re-did my system (wipe and re-install).
I found a bunch of examples and now they are not working.

here it an example...

open(LCD,">/dev/lcd")||die "ERROR: can not write to /dev/lcd\n";
$|=1;
my $i=0;
while(1){
$i++;
print LCD "\xFE",chr(0x58); # clear the display
print LCD "Count $i\n";
sleep(1);
}
close LCD;

Before runnuning the script, a c++ program is run to set the baud rate, turn on backlight, etc ... and it is working fine. With the script instead of clearing the screen, I get 2 weird chars, an X and the the Count # part.

System - RedHat 8.0 (was v7.3 when everything worked...)
Matrix Orbital BLK202A-4BR

This is my first experience with perl, so thanks for any help.

Posted: Fri Dec 06, 2002 12:30 am
by Henry
I'm no perl expert, but I'll try. If you are getting the 'X' displayed on the LCD, that means the command prefix didn't work, meaneing it was not sent, or sent incorectly to the LCD. If the command prefix worked, the LCD would have been expecting a command and you would not have seen the 'X' on the LCD...

Posted: Fri Dec 06, 2002 2:15 am
by Mat-Moo
Or the baud rate is wrong on the port...

Posted: Fri Dec 06, 2002 8:38 am
by linear
I'd try using the MOperl.zip perl module that Anders Bronworth wrote. It's really nice--it takes care of all that crap for you, while still being really lightweight and well-written.

At minimum, if you don't wanna use it, the way he handled commands is pretty slick (I thought anyhow).

Posted: Fri Dec 06, 2002 9:27 am
by ctimmer
Also check the tty settings (stty -a < /dev/lcd, I think) after the c++ application has run. The character size may be set to cs7. This would cause any character above x7F to be sent incorrectly.

Posted: Fri Dec 06, 2002 11:33 pm
by unstabl1
Thanks for the help. I checked the settings after the c++ app runs. It is set at cs8.
The MO-perl is nice. It almost works for me. For some reason, the display is still not being cleared if I use the text_example as is. The display does not clear, and I get an X at pos (1,1) and 'Hi there!' is displayed at (1,7). If I edit the script and add a display_clear after the init, all is well.
Is it possible that there could be some 'data' or something sitting in a buffer of sorts that is interfering? or another app I don't know about that is accessing my com port? I'm just guessing here and have no idea if this is plausible, but I have tried rearranging the order of the line in the display_init function:

print DISPLAY "$on$repeat$noblink$dim$clear";

and I am seeing different chars on the display eg, X or B and they seem to relate to the last value in the statement...
now it works. What the hell. I'm calling it a night. Again, any help or guidance is greatly appreciated.

Posted: Sat Dec 07, 2002 9:29 am
by ctimmer
One more thing to try, change the lcd open to:
open(LCD,">-")||die "ERROR: can not write to /dev/lcd\n";

This will cause the LDC output to go to stdout.

Run the test script capturing the output:
lcdtest.pl > lcd.out

Then, dump the output in hex:
od -h lcd.out # hex only
od -hc lcd.out # hex and character out

Check the output against the manual for validity on your LCD. You may find the output is not what you expected.

It sure would be nice if MO LCDs had a hex dump mode so you could see exactly what it is receiving. Henry???

Enjoy,
Curt