mikebuss / MTBBarcodeScanner

A lightweight, easy-to-use barcode scanning library for iOS 8+
MIT License
1.09k stars 196 forks source link

When reading VIN barcodes, an extra letter is added to the beginning #27

Closed Daltron closed 9 years ago

Daltron commented 9 years ago

First off, great library!

The problem I am having is that when I read VIN barcodes from vehicles that are not in the QR format, it wants to throw a l in front of each vin at the very beginning. Everything after that is read in correctly but I'm not sure why it is throwing that l in at the beginning.

Here is a sample that it does it on: 68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3437393830322f323337343932392f32626135376634382d613836362d313165332d386264372d6334306438306639313931342e6a706567 jpeg_360

I have also did it on a vehicle that is owned by my family that is also not in the QR format and it did the exact same thing.

Any help would be appreciated!

Thanks

mikebuss commented 9 years ago

Hey @dhint4. I did some research, and it looks like the leading I character stands for "import". I think you posted a capital L, but I believe it's actually a capital i. At least that's what I found after digging.

From a VIN-scanner manufacturers website:

Worth Data provides special support for reading the VIN's, including through the windshield. Our readers also allow suppressing the "I" on imports' VINs.

There's also a SourceForge thread with people discussing the issue.

It looks like the general consensus is that you should strip the I character if and only if the VIN number is longer than 17 characters. If you do that, you should be able to parse all of the codes correctly.

Since this most likely happens in all barcode scanners, I'm going to close this for now. If you test this with other scanners and find MTBBarcodeScanner is producing different results, I would suggest reporting back.

Thanks!

Daltron commented 9 years ago

Thanks for such a quick response and your input!

Keep up the great work! :+1:

stephenfeather commented 6 years ago

I know it is a little late, apologize, but some additional info for folks that might come by: Code39 barcode for vins can have 17,18,19, and 20 chrs depending on the manufacturer. 17 - good to go 18 - strip first chr 19 - strip first & last chr 20 - strip first 2 & last chr

Swift 4 code snippet:

var vin: String?
let stringValue = code.stringValue!
if code.type.rawValue == "org.iso.Code39" {
  if stringValue.count == 18 {
    vin = String(stringValue.suffix(17))
  } else if stringValue.count == 19 {
    vin = String(stringValue.suffix(18).prefix(17))
  } else if stringValue.count == 20 {
    vin = String(stringValue.suffix(18).prefix(17))
  } else {
    vin = stringValue
  }
  print("Adjusted Vin: \(vin ?? "")")
}
AdrianBinDC commented 6 years ago

@stephenfeather Even later. This RegEx string has worked well for me:

struct RegexString {
  static let vin = "[A-HJ-NPR-Z0-9]{17}"
}

And usage:

    let range = vinString.range(of: RegexString.vin, options: [.regularExpression, .caseInsensitive])
    var extractedVin: String?
    if let matchRange = range {
      extractedVin = String(vinString[matchRange.lowerBound..<matchRange.upperBound])
    } else {
      return
    }
ptsteward commented 5 years ago

@stephenfeather I know I'm late to this party but thank you for that detailed run down of possible codes. Do you have any supporting docs for that? I can't find anything that details VIN's with with more than 17 characters encoded, even though there's obviously cases where the barcode contains more than 17 characters.

stephenfeather commented 5 years ago

USG: https://www.nhtsa.gov/DOT/NHTSA/Rulemaking/Rules/Associated%20Files/VIN_Final_Rule_April_08.pdf

This is how the 17 spaces are to be used to create a valid VIN. Any chars outside those 17 are extraneous and can be dropped.

mijcon commented 5 years ago

Just wanted to add a recent discovery: I have been finding Hyundai VINs including a trailing hyphen, so yet another variant to watch out for that does not comply with @stephenfeather's Swift snippet.

EEaglehouse commented 5 years ago

I just ran into a Hyundai VIN that includes a slash (/) in position 18. According to standards, that is not a legal US VIN.

EEaglehouse commented 5 years ago

I just ran into a Hyundai VIN that includes a slash (/) in position 18. According to the Wiki page Vehicle Identification Numbers (VIN codes)/Hyundai/VIN Codes -- at least as of 2016 -- they add positions 18 and 19, position 19 being used to encode Manufacturing Month.

The 49 CFR Part 565 regulations dictating VIN requirements specifies how a Vehicle Identification Number must be structured, but does not address anything about the content of an associated barcode. From what I have been able to ferret out, neither does ISO 3779:2009 standards specify it for international VINs.

So the printed VIN must comply with standard but apparently anything goes as far as what the barcode contains :-/.

stephenfeather commented 4 years ago

Thats just lovely. :(