Hi Friends,

I have a problem with using a serial port and I hope that someone will be
able to help me here.

I am new to Perl and I wrote two scripts as a tutorial that uses the serial
link for communication.

 

The first script gets some info from the keyboard (represented as HEX
values) converts it to integer values

and then transmits it toward the serial port. 

The peer script is expected to get these values, to printf them and to echo
it back to the first script.

 

I am using Win32::SerialPort, both my ports are configured as 115200 Baud, 8
data bits, 1 stop bit, no parity and no handshake signals.

 

I face two main problems:

1) When the value I try to transmit is 0x00 the script will get stuck.   

            Assuming that   $ch = 0;

                                    $ob->write($ch); ====> This will cause
the script to freeze.

    From my point of view the 0x00 value is a valid data byte and I must be
able to pass it through.

 

 

2) When I send successively several values, the peer side will get a problem
to distinguish between these values.

            Consider the following lines:

                                    @txArray = (0x83, 0x95, 0x17, 0x2A,
0xB2);

                                    foreach $k (@txArray) {

            $ob->write($k);

}

            The required values are sent to the peer side and are
temporarily stored into a system buffer that serves the $ob.

            When my script there does:

                                    If ($inBuffer = $ob->input) {

                                                printf $inBuffer;
===> This will show that $inBuffer == "1311492342."

                                    }

            I need to be able to distinguish between the unique transmitted
values and I don't know how the peer should be able to

            do so (e.g. 131 , 149, 23, .)

 

  Inserting a delay in the transmitting side helps to solve this problem
since it lets the peer enough time to handle each transmitted byte

  but this is no way to deal with this problem, I can't impose such
constraints on the transmitting side.

                                    @txArray = (0x83, 0x95, 0x17, 0x2A,
0xB2);

                                    foreach $k (@txArray) {

            $ob->write($k);

            sleep(1);

}

 

My question here is if there is a way to solve both these problems by
configuring the serial port differently or by any other way.

Currently I am using:

 

sub InitSerialPort()

{

$ob = Win32::SerialPort->new ($SelectedPort) || die "Can't open
$SelectedPort: $!";

$ob->baudrate($BaudrateVal)                  || die "fail setting baudrate";

$ob->parity($ParityVal)                           || die "fail setting
parity";

$ob->databits($DataBitsVal)                   || die "fail setting
databits";

$ob->stopbits($StopBitsVal)                   || die "fail setting
stopbits";

$ob->handshake($HandshakeVal)           || die "fail setting handshake";

$ob->buffers(32768,4096);

 

$ob->write_settings                                || die "no settings";

$ob->error_msg(1);                     # use built-in error messages

$ob->user_msg(1);

} # End of "SerialInit".

 

 

 

_______________________________________________
Perl mailing list
Perl@perl.org.il
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to