You are here:  » How to deal with "serial control characters"


How to deal with "serial control characters"

Submitted by baggagepin on Fri, 2010-10-08 13:28 in

Hi all,

I have a file which contains data drom a serial post. Each record in the file ends with a control character "" which I think is "ASCII 192".

If I run the file in the MagicParser demo page the result is blank. I think it may be the "control character". Is there a way I can run this code using MagicParser.

Many thanks for any help you can give.

The data looks like this:

D00300C0000I05BA7987 O01032F02BOD 032FFFFF57HWILG PFFFFFFFF00000000FFFF0000 DI05FR9852 I04034301ORK 033900AD12MEX PFFFFFFFF00000000FFFF0000 HI05FR9853 O04036601ORK FFFFFFFF WILG PFFFFFFFF00000000FFFF0000 EI05FR9852 I04034301ORK 033900AD12MEX PFFFFFFFF00000000FFFF0000 HI05FR9853 O04036601ORK FFFFFFFF WILG PFFFFFFFF00000000FFFF0000 EI05FR9852 I04034301ORK 033900AD12MEX PFFFFFFFF00000000FFFF0000 HI05FR9853 O04036601ORK FFFFFFFF WILG PFFFFFFFF00000000FFFF0000 EI05FR9852 I04034301ORK 033900AD12MEX PFFFFFFFF00000000FFFF0000 HI05FR9853 O04036601ORK FFFFFFFF WILG PFFFFFFFF00000000FFFF0000 EI05DY1305 O04035701OSL FFFFFFFF WILG PFFFFFFFF00000000FFFF0000 EI05DY1304 I04033901OSL 0322009332MEX PFFFFFFFF00000000FFFF0000 DI05EZY5267O05031B01VCE FFFF009820 BDGA B0300FFFF00000000FFFF0000 CI05DY1305 O04035701OSL FFFFFFFF WILG PFFFFFFFF00000000FFFF0000 EI05FR9853 O04036601ORK FFFFFFFF WILG PFFFFFFFF00000000FFFF0000 EI05BA2689 I01037502GOA 03750072 ES PFFFFFFFF00000000FFFF0000 DI05FR9852 I04034301ORK 033900AD12MEX PFFFFFFFF00000000FFFF0000 HI05FR9853 O04036601ORK FFFFFFFF WILG PFFFFFFFF00000000FFFF0000 EI05TOM4501I02030C02AGP 031700F052MEX PFFFFFFFF00000000FFFF0000 AI05BE7293 A02035701ABZ 03570074 PFFFFFFFF00000000FFFF0000 HI05YM713 O04030C01TGD 030CFFFF34 C02F302FD00000000FFFF00001248EI05YM712 I0402D001TGD 02C2004C34MLDCH C02D802E708000000FFFF00001248 I05YM713 O04030C01TGD 030CFFFF34 C02F302FD00000000FFFF00001248E

Best regards,

Dereck

Submitted by support on Fri, 2010-10-08 13:36

Hi Dereck,

If the records are not separated by new line characters - or if (as it appears to be binary data) new line characters may even appear within each record it's unlikely to be suitable for use with Magic Parser i'm afraid.

However, if the content in your posts represents a complete example it should be straight forward to process using explode() - have a go with something like this:

<?php
  $data 
file_get_contents("filename.dat");
  
$records explode(chr(0x192),$data);
  foreach(
$records as $record)
  {
    
// process each $record here
  
}
?>

Hope this helps!
Cheers,
David.