I have an older serial based LCD display (2x16char) and a mini-ssc (serial servo controller by Scott Edward) connected together. To move the servos I need to send the following 5 bytes:
\xFE\x90 #This moves the LCD 'cursor' off screen \xFF\x00\x05 #This tells the SSC to move the first servo to #position 5 (range of 0-254 acceptable, but I #will limit that to 253 to avoid the LCD #display).
I am using the Device::SerialPort module from CPAN and am confused by what appears to be magic type casting.
Here's my test code. The first section works, the loop does not. Why?
#!/usr/bin/perl use Device::SerialPort 0.12; $ob = Device::SerialPort->new ("/dev/ttyS1") || die "S1 dead"; $ob->datatype("raw") || die "raw"; $ob->baudrate(2400) || die "baudrate"; $ob->parity("none") || die "parity"; $ob->databits(8) || die "databits"; $ob->handshake("none") || die "handshake"; $ob->write_settings || die "write settings"; #write to both lines of the LCD display #clear screen $ob->write("\xFE\x01"); $ob->write("Hello"); $ob->write_drain; #second line $ob->write("\xFE\xC0"); $ob->write("World"); $ob->write_drain; # These lines move the servo to 5 different positions sleep(1); $ob->write("\xFE\x90\xFF\x00\x01"); $ob->write_drain; sleep(1); $ob->write("\xFE\x90\xFF\x00\x11"); $ob->write_drain; sleep(1); $ob->write("\xFE\x90\xFF\x00\x21"); $ob->write_drain; sleep(1); $ob->write("\xFE\x90\xFF\x00\x31"); $ob->write_drain; sleep(1); $ob->write("\xFE\x90\xFF\x00\x41"); $ob->write_drain; #This loop should move the servo #nearly full range in 25 step #it doesn't. $x = 25; while ($x>0) { sleep(1); $ob->write("\xFE\x90\xFF\x00"); $ob->write(int($x*10)); $ob->write_drain; $x--; } #end
I have tried a couple of variations for sending the value.
$fs = sprintf "\\xFE\\x90\\xFF\\x00\\x%X", int($x*10); $ob->write($fs); # does not appear to work
In reply to Casting magic - how to write numbers to the serial port by ehud42
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |