Skip to Main Content
Cognex 支持中心
Logo

Script-Multicode Data Formatting

Data formatting after reading multi-code using the script.

2026/02/11

Question

After multi-code reading, I want to receive the data in the format 'Left: XXX, Right: XXX', with the regions clearly separated.

Script-Multicode Data Formatting_image-1

function onResult (decodeResults, readerProperties, output)

{

          if(decodeResults[0].decoded)

                     {

                     if(decodeResults.length == 2)

                                {

                                if(decodeResults[0].symbology.center.x < decodeResults[1].symbology.center.x)

                                            output.content = "Left:" + decodeResults[0].content +"     "+ "Right:" + decodeResults[1].content;

                                            else

                                            output.content = "Left:" + decodeResults[1].content +"     "+ "Right:" + decodeResults[0].content;

                                }

                       else if(decodeResults.length == 1)

                                {

                                // DM280 resulution : 1440 x 1080

                                // After setting the area, select the X that will be the basis for dividing left and right, then change the number in the line below

                                if(         decodeResults[0].symbology.center.x < 720)

                                            output.content = "Left:" + decodeResults[0].content +"     "+ "Right: No Code";

                                else

                                    output.content = "Left: No Code" + "     "+ "Right:"+decodeResults[0].content;

                                }

                     else

                                output.content = "Left: No Read";

                     }        

                               

                               

                               

}

 

  1. When both have been read.

    Script-Multicode Data Formatting_image-2
  2. If only the left side is read

    Script-Multicode Data Formatting_image-3
  3. If only the right side is read

    Script-Multicode Data Formatting_image-4
  4. If neither has been read.

    Script-Multicode Data Formatting_image-5

相关资源