2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-29 11:27:08 +00:00

DevIo.pm: DevIo_writeBaudrate function from chri.jaes (Forum #139055)

git-svn-id: https://svn.fhem.de/fhem/trunk@29109 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2024-08-26 13:38:19 +00:00
parent 4937ad21da
commit 1801681f29

View File

@ -634,40 +634,54 @@ DevIo_OpenDev($$$;$)
$selectlist{"$name.$dev"} = $hash;
}
if($baudrate) {
$po->reset_error();
DevIo_writeBaudrate($hash, $baudrate, $databits, $parity, $stopbits);
}
return &$doCb(&$doTailWork());
}
#139055
sub
DevIo_writeBaudrate($$;$$$)
{
my ($hash, $baudrate, $databits, $parity, $stopbits) = @_;
my $po = $hash->{USBDev};
my $name= $hash->{NAME};
if ($baudrate) {
$po->reset_error();
if (defined($databits)) {
my $p = ($parity eq "none" ? "N" : ($parity eq "odd" ? "O" : "E"));
Log3 $name, 3, "Setting $name serial parameters to ".
"$baudrate,$databits,$p,$stopbits" if(!$hash->{DevioText});
$po->baudrate($baudrate);
$po->databits($databits);
$po->parity($parity);
$po->stopbits($stopbits);
$po->handshake('none');
# This part is for some Linux kernel versions whih has strange default
# settings. Device::SerialPort is nice: if the flag is not defined for
# your OS then it will be ignored.
$po->stty_icanon(0);
#$po->stty_parmrk(0); # The debian standard install does not have it
$po->stty_icrnl(0);
$po->stty_echoe(0);
$po->stty_echok(0);
$po->stty_echoctl(0);
# Needed for some strange distros
$po->stty_echo(0);
$po->stty_icanon(0);
$po->stty_isig(0);
$po->stty_opost(0);
$po->stty_icrnl(0);
} else {
Log3 $name, 3, "Setting $name serial baudrate to ".
"$baudrate" if(!$hash->{DevioText});
}
$po->write_settings;
$po->baudrate($baudrate);
# This part is for some Linux kernel versions which has strange default
# settings. Device::SerialPort is nice: if the flag is not defined for
# your OS then it will be ignored.
$po->stty_icanon(0);
#$po->stty_parmrk(0); # The debian standard install does not have it
$po->stty_icrnl(0);
$po->stty_echoe(0);
$po->stty_echok(0);
$po->stty_echoctl(0);
# Needed for some strange distros
$po->stty_echo(0);
$po->stty_icanon(0);
$po->stty_isig(0);
$po->stty_opost(0);
$po->stty_icrnl(0);
}
return &$doCb(&$doTailWork());
$po->write_settings;
}
sub