SCL中的条形码解码和分隔值

时间:2018-11-27 09:03:07

标签: arrays string char barcode data-manipulation

因此,在接下来的几个月中,我们将缓慢地将条形码更新给其他制造商,该制造商不便使用非常不同的解码格式。 See example image. With the first row being our current format, and the second and third being the updated. We will need to be able to read all 3 这是我们当前的解码SCL脚本:

TYPE UDT_Decoded_Bearing:
STRUCT
Company_ID      : byte;
Component_ID    : STRING[10];    
Mfg_Year        : byte;
Mfg_Month       : byte;
Serial          : STRING[8];
END_STRUCT
END_TYPE

DATA_BLOCK DecodedBearing
STRUCT
    dataUDT: UDT_Decoded_Bearing;
    Element: STRING[20];
    Data: String[20];
END_STRUCT
BEGIN
END_DATA_BLOCK

FUNCTION FC_Decode_Bearing : WORD
VAR_INPUT
Raw_Barcode: ARRAY[1..512] OF CHAR;
END_VAR
VAR_OUTPUT
DecodedData: UDT_Decoded_Bearing;
END_VAR
VAR_TEMP
i: INT;
iStartChar: INT;
iEndChar: INT;
iFoundChar: INT;
//    Element: STRING[20];
//    Data: STRING[20];
Source: ARRAY[1..512] OF CHAR;
END_VAR
Source:= Raw_Barcode;
iStartChar:= 3; // skip over the initial open tag
DecodedBearing.Element:= '';
DecodedBearing.Data:= '';

DecodedData.Company_ID      := 0;
DecodedData.Component_ID    := '';
DecodedData.Mfg_Year        := 0;
DecodedData.Mfg_Month       := 0;
DecodedData.Serial          := '';       

FOR i:= 0 TO 20 DO 
    iStartChar:= FIND_CHAR(IN1:= Source, START_CHAR:= iStartChar, SEARCH_CHAR:= '<') + 1; //Finding Start of opening Tag
    iFoundChar:= FIND_CHAR(IN1:= Source, START_CHAR:= iStartChar, SEARCH_CHAR:= '>'); //Finding End of opening Tag
    DecodedBearing.Element:= CHAR_TO_STR (IN1:= Source, START_CHAR:= iStartChar, Length := iFoundChar - iStartChar); //reading opening tag

    iFoundChar:= FIND_CHAR(IN1:= Source, START_CHAR:= iStartChar, SEARCH_CHAR:= '<'); //Finding Start of closing tag
    iStartChar:= iStartChar + 1;
    DecodedBearing.Data:= CHAR_TO_STR (IN1 := Source, START_CHAR := iStartChar, Length := iFoundChar - iStartChar); //reading tag data
    iStartChar:= iStartChar + 1;                

    IF    DecodedBearing.Element = 'companyCode'           THEN
        IF    DecodedBearing.Data = '8AMS'   THEN   // Brenco - To Be Tested
            DecodedData.Company_ID := 1;
        ELSIF DecodedBearing.Data = '8FAS'   THEN   // FAG - To Be Tested
            DecodedData.Company_ID := 2;
        ELSIF DecodedBearing.Data = 'KOYO'   THEN   // Guess!!!
            DecodedData.Company_ID := 3;
        ELSIF DecodedBearing.Data = '8SKF'   THEN   // To Be Tested
            DecodedData.Company_ID := 4;
        ELSIF DecodedBearing.Data = '8TIM'   THEN   // Proven Working - 2D Barcode
            DecodedData.Company_ID := 5;
        ELSIF DecodedBearing.Data = '8NTN'   THEN   // Guess - Added 20160410 JCP
            DecodedData.Company_ID := 6;

        END_IF;
    ELSIF DecodedBearing.Element = 'idNumber' THEN    
        DecodedData.Component_ID    := DecodedBearing.Data;
    ELSIF DecodedBearing.Element = 'C205'     THEN    
        DecodedData.Serial          := DecodedBearing.Data;
    ELSIF DecodedBearing.Element = 'C206'     THEN    
        DecodedData.Mfg_Year        := INT_TO_BYTE(STRNG_I(DecodedBearing.Data));
    ELSIF DecodedBearing.Element = 'C207'     THEN    
        DecodedData.Mfg_Month       := INT_TO_BYTE(STRNG_I(DecodedBearing.Data));
    END_IF;
END_FOR;
//END_WHILE;
FC_Decode_Bearing:= 0;
END_FUNCTION

我有点想让它读取括号之间的内容,而又读取括号之外的内容,并能够从中获取相同的数据。第三个示例中的第8、9和10部分将需要添加为变量,因为它们是翻新的月份和年份。 对此,我们将给予任何帮助。 谢谢!

0 个答案:

没有答案