use strict;
use warnings;
use Device::SerialPort;
+use IO::Socket;
+use IO::Handle;
+use Fcntl;
+
use feature 'state';
use URI::Escape;
use Data::Dumper;
'device|d=s' => \$ser_dev,
) ;
+my $isEthernet = 0;
my $mode = 0;
my $ch;
my $uC;
sub PrintAnswerNice {
my ($s) = @_;
my $FSR = 0.002; #Full Sclae Range is set to +-4.096V; LSB Size is 2mV
- if (substr($s,0,1) ne 'A') {die 'not an correct Answer from DCDC board'}
+ if (substr($s,0,1) ne 'A') {die 'not a correct Answer from DCDC board'}
my $command = hex(substr($s,5,1));
my $ch = hex(substr($s,4,1));
my $uC = hex(substr($s,1,2));
my $uC = $ARGV[1];
if (substr($uC,0,2) eq "0x") {$uC = hex(substr($uC,2));}
if ($uC >= $num) {
- die "This microcontroller Number is not allowed! \n";
+ die "This microcontroller number is not allowed! \n";
}
# channel number
#print $cmd."\n";
PrintAnswerNice(Cmd($cmd)) #Answer without \n
} else {
- die "Not all arguements were specified!\n";
+ die "Not all arguments were specified!\n";
}
}
sub Cmd {
- my ($c) = @_;
+ my ($c) = @_;
+ $c .= "\n";
+ if($isEthernet == 0) {
for my $i (0..0) {
- $port->write($c."\n");
+ $port->write($c);
my $a = "";
for my $j (0..16) {
my ($l,$s) = $port->read(12);
usleep(50000);
#print '.';
}
+ }
+ if($isEthernet == 1) {
+ print $port "$c";
+ my $x = "";
+ for my $i (0..10) {
+ $x .= <$port>;
+ if($x && ($x =~ /\n/ || $x =~ /\r/) ) {
+ chomp $x;
+ return $x;
+ }
+ usleep(1000);
+ }
+ }
return ;
}
if ($help || (defined $ARGV[0] && $ARGV[0] =~ /help/)) {
print "dcdc.pl [-d DEVICE] reg [uC [CHANNEL [OPERATION [REGISTER [VALUE]]]]]\n";
print "dcdc.pl [-d DEVICE] CMD [uC [CHANNEL [VALUE]]]\n\n";
+ print "DEVICE: Either a serial device or an IP number.\n";
print "CMD: s: set DCDC setting, g: get DCDC setting,\n";
print " t: temperature, v: input voltage, c: input current;\n";
print "uC: number of Microcontrolle rin chain. As Hex or Dec\n";
exit;
}
+if ($ser_dev =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
+ $isEthernet = 1;
+ $port = IO::Socket::INET->new(PeerAddr => $ser_dev, PeerPort => 23, Proto => "tcp", Type => SOCK_STREAM, Timeout => 1)
+ or (print("Device not found") && return);
+ }
+else {
$port = new Device::SerialPort($ser_dev);
unless ($port) {
print "can't open serial interface $ser_dev\n";
$port->read_char_time(0);
$port->read_const_time(50);
$port->write_settings;
-
+ }
#Scan for number of Microcontrolles.
$num = Cmd("S");