Moshe,

Moshe Okman wrote, On 07/05/2010 09:23 AM:
> I have a problem with using a serial port and I hope that someone 
> will be able to help me here.

"PortMon" is your friend ( 
http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx ).
Don't try any serial communication on Windows without it.

It will help you pin-point the problem, whether data gets transmitted/received 
correctly (and then it's a perl problem) or if the data simply didn't arrive.
Don't forget to switch to "hex" mode, and always save to log to disk.

> 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.

It should work, but verify what happens with Portmon (i.e. on the sending 
machine, you'll see if the NT-kernel function even got this write call or not).

Make sure you're not using any kind of flow control: $ob->handshake("none");

> 
> 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…”
> 
> }

Very strange.
could it be that you're actually sending the string representation of those 
numbers ( e.g. three characters '1', '3', '1', etc. ) ?
Again, portmon will show you that immediately.
To force sending bytes, use pack:

my $raw_byte_data =  pack("C*", 131, 149, 23, ... ) ;
$ob->write($raw_byte_data);

Once again, portmon in hex mode (on the sending machine) will tell you how the 
OS sees your data.
Portmon on the receiving machine will tell you how the OS got your raw data 
(before Perl grabs it).

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

Timing can be tricky in windows. Generally, it's best to avoid tinkering with 
it.
If (after debugging with Portmon) you're still losing information, try changing 
the read timeouts, some information available here:
 http://www.ewoodruff.us/CUJArticle/CUJArticle.html
 http://www.codeproject.com/KB/system/chaiyasit_t.aspx

Also,
 try to have one end a non-perl program (e.g. the sample from CodeProject 
above) to check if it's a perl issue or a transmission issue.

If you look at the "Timeouts" section in the CPAN POD:
http://search.cpan.org/~bbirth/Win32-SerialPort-0.22/lib/Win32/SerialPort.pm
It mentions the possibility of setting "read_interval" to 0xFFFFFFFF and then 
go into non-blocking mode. Might be worth a try.

-gordon

_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to