Constructor
new MaxiCodeCodetextMode2()
- Source:
Examples
This sample shows how to encode and decode MaxiCode codetext for mode 2.
//Mode 2 with standart second message
let maxiCodeCodetext = new MaxiCodeCodetextMode2();
maxiCodeCodetext.setPostalCode("524032140");
maxiCodeCodetext.setCountryCode(056);
maxiCodeCodetext.setServiceCategory(999);
let maxiCodeStandartSecondMessage = new MaxiCodeStandartSecondMessage();
maxiCodeStandartSecondMessage.setMessage("Test message");
maxiCodeCodetext.setSecondMessage(maxiCodeStandartSecondMessage);
let complexGenerator = new ComplexBarcodeGenerator(maxiCodeCodetext);
complexGenerator.generateBarCodeImage(BarcodeImageFormat.PNG);
//Mode 2 with structured second message
let maxiCodeCodetext = new MaxiCodeCodetextMode2();
maxiCodeCodetext.setPostalCode("524032140");
maxiCodeCodetext.setCountryCode(056);
maxiCodeCodetext.setServiceCategory(999);
let maxiCodeStructuredSecondMessage = new MaxiCodeStructuredSecondMessage();
maxiCodeStructuredSecondMessage.add("634 ALPHA DRIVE");
maxiCodeStructuredSecondMessage.add("PITTSBURGH");
maxiCodeStructuredSecondMessage.add("PA");
maxiCodeStructuredSecondMessage.setYear(99);
maxiCodeCodetext.setSecondMessage(maxiCodeStructuredSecondMessage);
let complexGenerator = new ComplexBarcodeGenerator(maxiCodeCodetext);
complexGenerator.generateBarCodeImage(BarcodeImageFormat.PNG);
//Decoding raw codetext with standart second message
let reader = new BarCodeReader("c:\\test.png", null, DecodeType.MAXI_CODE);
reader.readBarCodes().forEach(function(result, i, results)
{
let resultMaxiCodeCodetext = ComplexCodetextReader.tryDecodeMaxiCode(result.getExtended().getMaxiCode().getMaxiCodeMode(), result.getCodeText());
if (resultMaxiCodeCodetext instanceof MaxiCodeCodetextMode2)
{
let maxiCodeStructuredCodetext = resultMaxiCodeCodetext;
console.log("BarCode Type: " + maxiCodeStructuredCodetext.getPostalCode());
console.log("MaxiCode mode: " + maxiCodeStructuredCodetext.getCountryCode());
console.log("BarCode CodeText: " + maxiCodeStructuredCodetext.getServiceCategory());
if (maxiCodeStructuredCodetext.getSecondMessage() instanceof MaxiCodeStandartSecondMessage)
{
let secondMessage = maxiCodeStructuredCodetext.getSecondMessage();
console.log("Message: " + secondMessage.getMessage());
}
}
});
//Decoding raw codetext with structured second message
let reader = new BarCodeReader("c:\\test.png", null, DecodeType.MAXI_CODE);
reader.readBarCodes().forEach(function(result, i, results)
{
let resultMaxiCodeCodetext = ComplexCodetextReader.tryDecodeMaxiCode(result.getExtended().getMaxiCode().getMaxiCodeMode(), result.getCodeText());
if (resultMaxiCodeCodetext instanceof MaxiCodeCodetextMode2){
let maxiCodeStructuredCodetext = resultMaxiCodeCodetext;
console.log("BarCode Type: " + maxiCodeStructuredCodetext.getPostalCode());
console.log("MaxiCode mode: " + maxiCodeStructuredCodetext.getCountryCode());
console.log("BarCode CodeText: " + maxiCodeStructuredCodetext.getServiceCategory());
if (maxiCodeStructuredCodetext.getSecondMessage() instanceof MaxiCodeStructuredSecondMessage){
let secondMessage = maxiCodeStructuredCodetext.getSecondMessage();
console.log("Message:");
secondMessage.getIdentifiers().forEach(identifier,i, identifiers){
console.log(identifier);
});
}
}
});
Methods
getMode()
Gets MaxiCode mode.
Returns:
Type | Description |
---|---|
MaxiCode mode |
- Source: