witam.
mam krotki skrypt w perlu napisany pod linuxa...
odczytuje on dane z portu com (miernik podlaczany do komputera) a nastepnie przerabia na bardziej czytelna postac.
chce napisac (w delphi) program, ktory zrobi to samo, tylko bedzie bardziej rozbudowany.
problem polega na tym, ze nie mam zielonego pojecia co ten skrypt robi z danymi wyjsciowymi :/

byl by ktos tak mily i wyjasnil mi jakie operacje na bajtach/bitach zachodza w tym skrypcie? [browar]

#
# Read next (complete) binary string from the optocoupler
#
sub next_bin_str {
	my $bin_str;
	while (!eof(USB_TTY) and length($bin_str) != 14 * 4) {
		my $byte = getc(USB_TTY);
		my $nibble_number = ord($byte) >> 4 & 0xf;
		
		$bin_str .= substr(unpack("B*", $byte), 4);
		length($bin_str) == $nibble_number * 4 or $bin_str = "";
	}
	$bin_str;
}


#
# Decode the measured data from the binary string
#
sub decode_bin_str {


	my ($AC, $DC, $auto, $unknown1,
	    $minus, $digi1, $dot1, $digi2, $dot2, $digi3, $dot3, $digi4,
	    $micro, $unknown2, $kilo, $diode_test,
	    $milli, $percent, $mega, $cont_check,
	    $unknown3, $ohm, $rel, $hold,
	    $amp, $volt, $hz, $unknown4,
	    $min, $unknown5, $celsius, $max) = shift =~
    	   /^(.)(.)(.)(.)(.)(.{7})(.)(.{7})(.)(.{7})(.)(.{7})
	    (.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) *$/x;
	
	my %digi = (
		"1111101" => 0,
		"0000101" => 1,
		"1011011" => 2,
		"0011111" => 3,
		"0100111" => 4,
		"0111110" => 5,
		"1111110" => 6,
		"0010101" => 7,
		"1111111" => 8,
		"0111111" => 9,
	);

	my $val = ($minus ? "-" : "") . $digi{$digi1} . ($dot1 ? "." : "") .
					$digi{$digi2} . ($dot2 ? "." : "") .
					$digi{$digi3} . ($dot3 ? "." : "") .
					$digi{$digi4};
	
	my $flags = join(" ", $AC         ? "AC"         : (),
			      $DC         ? "DC"         : (),
			      $auto       ? "auto"       : (),
			      $diode_test ? "diode_test" : (),
			      $cont_check ? "cont_check" : (),
			      $rel        ? "rel"        : (),
			      $hold       ? "hold"       : (),
			      $min        ? "min"        : (),
			      $max        ? "max"        : ());
	
	my $unit = ($micro   ? "u"   : "") .
		   ($kilo    ? "k"   : "") .
		   ($milli   ? "m"   : "") .
		   ($mega    ? "M"   : "") .
		   ($percent ? "%"   : "") .
		   ($ohm     ? "Ohm" : "") .
		   ($amp     ? "A"   : "") .
		   ($volt    ? "V"   : "") .
		   ($hz      ? "Hz"  : "") .
		   ($celsius ? "C"   : "");

	$val, $flags, $unit;
}


################################################################################


$dev = shift || "/dev/ttyUSB0";
open USB_TTY, $dev or die "Can't open $dev";
init_tty(\*USB_TTY);

# force immediate flushing to stdout
$| = 1;

my $last_timestamp;

while ($bin_str = next_bin_str) {
	my ($val, $flags, $unit) = decode_bin_str($bin_str);

	$last_timestamp ||= gettimeofday;
	my $timestamp = gettimeofday;

	printf "%7.2f\t%9.3f\t%s\t%s\n", $timestamp - $last_timestamp,
					 $val, $unit, $flags;
	# $last_timestamp = $timestamp;
}

pozdrawiam [browar]