in reply to Re^2: How to get right data from COM1 using Win32::SerialPort
in thread How to get right data from COM1 using Win32::SerialPort
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to get right data from COM1 using Win32::SerialPort
by BrowserUk (Patriarch) on Mar 22, 2006 at 03:29 UTC | |
Sorry, no. The symptoms you describe look, feel, smell and taste like the classic win32 textmode conversion. If the module is ensuring that none of Perl's IO layers, nor the C runtime layers are exercising an influence upon the datastream, then I cannot see where the problem would lie. My instinct says that the OS, CRT or PerlIO layers *must* be getting involved somewhere in the chain and treating the datastream as text instead of binary. Not that it isn't possible for a different explanation, but the obvious one is usually right. A few thoughts. Basically, you need to track down where the datastream is being modified. If this is a real serial port, then I'd try attaching a Serial Port analyser to the connection. I used to have a blue cable with a built-in patch box and LEDs that could latch on byte at a time. It's probably in the loft somewhere, but I cannot remember the brand name. Alternatively, you could try monitoring the port with on of the many free software analysers that are available on the net. Once you are convinced that the same data that is leaving the device is being received, then you move up to the module itself. Try enabling debug on the module. If that shows the data being received from the device driver correctly, then make a copy of the module for backup and then go in and add some trace statements and see if you can find where the modifications are being made. If the problem is in the DD, you're faced with trying contact the supplier and find out if there is a later version, or some IOctl that you can set to disable it. And so on. Sorry that's not much help. I last used the module on my old laptop under NT4. It seems to have moved on quite a bit since. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
by Chenny (Initiate) on Mar 22, 2006 at 06:37 UTC | |
Yes, I have sent email to the author: wcbirthisel@alum.mit.edu . But I still have no answer.
I have tried ($countIn, $binData) = $portCom1->read (1); In fact, I can get right txt data from COM using Win32::SerialPort. And I also can sent right txt data to COM. Such as $ComLine = <FH>;But when I get a bin data block(such as 15K or more), I get 0D0A (not initial 0A)! I have used "SUDT SerialTrace" to trace the serial Port. It also shows 0D0A (not initial 0A)! Then, I try to get 2 characters at one time and delete "0D" if I get "0D0A". It can get right data. But I don't know how to do if the initial data block contains "0D0A".! The code:
I will go on! Thank you very much.
| [reply] [d/l] [select] |
by Chenny (Initiate) on Mar 22, 2006 at 06:35 UTC | |
Yes, I have sent email to the author: wcbirthisel@alum.mit.edu . But I still have no answer. I have tried ($countIn, $binData) = $portCom1->read (1); But get the same result! In fact, I can get right txt data from COM using Win32::SerialPort. And I also can sent right txt data to COM. But when I get a bin data block(such as 15K or more), I get 0D0A (not initial 0A).! I have used "SUDT SerialTrace" to trace the serial Port. It also shows 0D0A (not initial 0A). ! Then, I try to get 2 characters at one time and delete "0D" if I get "0D0A". It can get right data. But I don't know how to do if the initial data block contains "0D0A".! The code:! <code> #*****************************************************************************# # Function: # GetFileFromCom # Description: # Get data from serial port. Chenny--2006-2-27. # Argument: # 1. Saved file name # 2. Max size of data block # Return: # #*****************************************************************************# sub GetFileFromCom($$) { print "Run into GetFileFromCom!\n"; my ($fileName, $maxDataSize) = @_; my( $binData, $binData1, $binData2 ); my $tempX = 0; my $tempY = 0; my $tempI = 0; my $tempCSCal = 0; my $tempCS = 0; open (BINFILE, ">>$fileName") ||print "$!\nCannot write to bin file $fileName\n"; binmode (BINFILE); $portCom1->lookclear; # Clear buffers usleep (10000); syswrite (FH, 'Y', length('Y'), 0); #Send 'Y' to com to start send data to PC usleep (10000); #delete extr char. for ( $tempI = 0; $tempI < 2; $tempI++ ) { # read(FH, $binData, 1); $binData = getc FH; $binData = ord($binData); printf "0 $tempI: %02X\n", $binData; printf "0 $tempI: %d\n", $binData; } #Get Data header for data begin check. my $decimalData; for ( $tempI = 0; $tempI < 15; $tempI++ ) { $binData = getc FH; $binData = ord($binData); # printf "$tempI: %02X\n", $binData; $decimalData = sprintf ("%d\n", $binData); last if (0 == $decimalData); } #Get Data length. $tempX = $binData; # if ($decimalData > 0 ) { return -1; } # 16M bytes is the Max file size. printf "1: %02X\n", $tempX; printf "1: %d\n", $tempX; $tempY = getc FH; $tempY = ord($tempY); printf "2: %02X\n", $tempY; printf "2: %d\n", $tempY; $tempX = ($tempX << 24)+ ($tempY << 16); $tempY = getc FH; $tempY = ord($tempY); printf "3: %02X\n", $tempY; printf "3: %d\n", $tempY; $tempX = $tempX+ ($tempY << 8); # read(FH, $tempY, 1); $tempY = getc FH; $tempY = ord($tempY); printf "4: %02X\n", $tempY; printf "4: %d\n", $tempY; $tempX = $tempX + $tempY; printf("\nBlock size is %d bytes", $tempX); if ($tempX > $maxDataSize) # if ($tempX > 8*1024) { printf("\nFile size is too big. size = %d", $tempX); return;# -2; } #Get data byte by byte. $binData1 = getc FH; #Read 2 ch and compare to delete "0D0A" $tempX = $tempX-1; for ( $tempI = 0; $tempI < $tempX; $tempI++) { $binData2 = getc FH; # printf BINFILE ("%02X", ord($binData)); if ( (ord($binData1) == 13) && (ord($binData2) == 10) ) { $binData1 = $binData2; #Delete "0D" Chenny--2006-3-10 $tempI = $tempI-1; } else { print BINFILE $binData1; # printf "%X:%02X ", $tempI, ord($binData1); $binData = ord($binData1); $tempCSCal += $binData; $binData1 = $binData2; } } print BINFILE $binData1; # printf "%X:%02X ", $tempI, ord($binData1); $binData = ord($binData1); $tempCSCal += $binData; $tempX++; print ("\nGet $tempX bytes\n\n"); #Get CS check data--The last two bytes. $tempCS = getc FH; $tempCS = ord($tempCS); # printf("CS condition: ORG1 = %02X\n", $tempCS); $tempY = getc FH; $tempY = ord($tempY); $tempCS = ($tempCS << 8) + $tempY; # printf("CS condition: ORG2 = %X\n", $tempY); # printf("CS CAL condition: CAL = %d, CAL = %X\n", $tempCSCal, $tempCSCal); $tempCSCal &= 0xffff; #printf("CS CAL condition: CAL = %d, CAL = %X\n", $tempCSCal, $tempCSCal); printf("\nCS condition: ORG = %04X, CAL = %04X\n\n", $tempCS, $tempCSCal); if ($tempCS != $tempCSCal) { printf("\n\nCS Error. ORG = %04X, CAL = %04X!!!\n\n\n", $tempCS, $tempCSCal); #return;# -1; } close (BINFILE); return; } <code> I will go on! Thank you very much.
| [reply] |
by Anonymous Monk on Sep 20, 2017 at 13:19 UTC | |
I had the same pb. solution: suppress 0D0A when appears : As the problem does not appear when 0D is sent, there is no risk to destroy "good" 0D bye | [reply] [d/l] |