Hi Dennis,
This may be of interest to you. It's a little Perl script which sends text to an LCD display. It actually displays the curent IP address of the ppp0 interface. The principle is the same as for your robot arm. Where it gets interesting (complicated) is reading and writing the serial port at the same time. If you're interested I have a script which responds to text messages, which cause the computer to bring the modem up.
/dev/ttyS0 = COM1 in Windows
Sorry for the poor coding style... but it works :-)
#!/usr/bin/perl -w
# Set serial port ttyS0 to 9600 baud system("/bin/stty -F /dev/ttyS0 9600");
# Open ttyS0 for writing open (LCD,">/dev/ttyS0");
# Get IP address of ppp0
$ip =`/sbin/ifconfig ppp0|grep inet`;
# Removes everything except ip address
$ip =~ s/\s+\D+addr:(\d+.\d+.\d+.\d+).*?\n/$1/;
# Hopefully write data to LCD # \xFE (254d) tells LCD to accept a control character # \x01 (1d) Clears LCD display # \x0 (0d) Move cursor to home posistion # \xC0 (192) Move cursor to start of second line
print LCD "\xFE","\x01","\xFE","\x0","Modem Connected"; print LCD "\xFE","\xC0","IP: ",$ip;
close (LCD);
Hope that helps
Chris
Chris *************************************************************************** E Mail Chris@glovercc.clara.co.uk WWW http://www.glovercc.clara.co.uk ICQ 18054759 Someday, we'll look back on this, laugh nervously and change the subject. -Anon
On Fri, 19 Apr 2002, Dryden wrote:
What would be the best way to send char's and strings to a serial port?
My problem is that i would like to send commands to a robotic arm that ive played about with a few months ago. At the moment the electronics teacher is using QBASIC to work it... I used to love QBASIC but I don't have a Linux equivalent and to be really honest I don't want one (BASIC == S...L...O...O...O...W...W...). In his current program he's opening the serial port and then using the print statement to send the strings to the robotic arm. How would I do this on Linux in c?
Would I use the file handling commands and open /dev/S0 (what ever the Comm ports are called under Linux) and then use fprintf(serial_port, "command")??? Would i have any problems doing this f5rom a normal user account on my system or would I need to be root?
It would be nice if anyone could give me some example code or give me the address of a good web site on the subject:). I'm Not so hot on file handling in c so even some examples of this would be nice.
Thanx for the help :)
Dennis Dryden
IMPORTANT: This email and its attachments are intended for the addressee only and may be confidential. If they have come to you in error you must take no action based on them nor must you copy or show them to anyone; please telephone us immediately.
The contents of this email and attachments represent the views of the sender and are not necessarily the representative of the views of The College of West Anglia
main@lists.alug.org.uk http://www.anglian.lug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!