Author Topic: Interfase/driver for windows xp  (Read 2222 times)

Offline ronyto141947

  • Guppy
  • *
  • Posts: 1
  • Post quality +0/-0
  • Gender: Male
  • Acidmods User
Interfase/driver for windows xp
« on: June 12, 2013, 07:47:24 AM »
Please, how do to write this program for run in Windows XP
Tks.




#!/C:\perl\bin\perl.exe
#===============================================================================
#
#         FILE:  interfaz1.pl
#
#        USAGE:  ./interfaz1.pl 
#
#  DESCRIPTION:  Interfaz para el frecuencĂ­metro 1.
#                Recoge los datos por el puerto serie (o el conversor USB) y los
#                presenta.
#
# REQUIREMENTS:  ---
#       AUTHOR:  Reinoso Guzman
#      VERSION:  1.0
#      CREATED:  07/01/11 00:53:21
#===============================================================================

use strict;
use warnings;

require 5.003;
use Win32::SerialPort;

$| = 1;

# Abrir el puerto
  my $Port    = "COM1";
$PortObj = new Win32::SerialPort ($PortName, $quiet)
|| die "Can't open $PortName: $^E\n"; # $quiet is optional

$PortObj->baudrate(9600);
  $PortObj->parity("odd");
  $PortObj->databits(8);
  $PortObj->stopbits(1);



$PortObj->handshake("none");
$PortObj->write_settings;
$PortObj->purge_all();
$PortObj->purge_rx;
open( DEV, "<$PORT" ) || die "Error abriendo $PORT: $_\n";

# Crear la interfaz
my $freq_txt = " No Conectado";
my $mw=tkinit;
$mw->title("Frecuencimetro");
my $freq_lbl = $mw->Label(
 -textvariable => \$freq_txt,
 -font         => "LEDBOARDREVERSED 20",
 -anchor       => 'e',
 -foreground   => 'green',
 -background   => 'black');
$freq_lbl->pack(-expand => 1);
$mw->fileevent(\*DEV, 'readable', [\&update_freq, $freq_lbl]);
$mw->withdraw; # avoid the jumping window bug (perlmonks)
$mw->Popup;    # centrar la ventana

# Si nos pasamos un segundo sin recibir, mostramos "no conectado"
$SIG{ALRM} = sub { $freq_txt = " No Conectado"; };
alarm 1;
MainLoop;



# Rutina para actualizar la frecuencia
sub update_freq {
 alarm 1;
 my $linea = <DEV>;
 
 # Error si no se pudo leer (hemos desconectado el USB)
 if (not $linea) {
  die "Error de lectura: USB desconectado.\n";
 };

 my ($valor) = $linea =~ /F:(\d+)/;
 if (not defined $valor) {
  $freq_txt = "      0.0 kHz";
  return;
 };

 # Redondeo
 $valor = int($valor/100 + 0.5); # Redondeo hasta 100Hz
 $valor = $valor / 10;   # Decimales a partir de kHz
 
 # Lo quitamos si es cero (menos de 100Hz).
 if ($valor <= 0) {
  $freq_txt = "      0.0 kHz";
  return;
 };

 # Hasta 100Hz, que es un lugar decimal
 $valor = sprintf("%.1f", $valor);
 # Expresarlo con separador de miles
 # (esta linea es de 'Mastering regular expressions')
 1 while ($valor =~ s/^(-?\d+)(\d{3})/$1 $2/);

 $freq_txt = sprintf("% 13s", "$valor kHz");
}

Offline Modded Matt

  • Site Owner
  • Administrator
  • Around the block
  • *
  • Posts: 4649
  • Post quality +65/-3
  • Gender: Male
Re: Interfase/driver for windows xp
« Reply #1 on: June 12, 2013, 09:23:28 AM »
its a pearl script written in Spanish, if you convert it to English you may have better luck understanding it, I am a little rusty, but it appears to be a driver for a serial to usb converter.  Do you have a clue what that means?

I can stop you right here by saying if you are trying to use a serial to usb adapter for a IC programmer, that wont work.
« Last Edit: June 12, 2013, 09:23:55 AM by Modded Matt »

 

SMF spam blocked by CleanTalk
SimplePortal 2.3.5 © 2008-2012, SimplePortal