09-26-2022 10:55 PM - edited 09-26-2022 11:00 PM
Hello Application engineers,
I used Visa Read to read data from a USB serial port, then used a Match Pattern to find an index (offset past match) in the read buffer string as shown below,
The front panel is as below in hex display..
Issue: The returned offset past match is not as what I thought to be 6 when regular expression is 4C120100042A; and to be 7 when regular expression is 4C120100042A01. They are 5 and -1 respectively.
regular expression offset past match
4C 1
4C12 2
4C1201 3
4C120100 4
4C12010004 5
4C120100042A 5
4C120100042A01 -1
4C120100042A0107 -1
Could someone explains why?
Code is attached.
Thanks.
Solved! Go to Solution.
09-27-2022 12:07 AM
Don't use Match Pattern with binary data. Match Pattern can use special characters to search for regular expressions in string. In your case, at some point, you are searching for 0x2A which is "*" (special character) so result is not what you expect. You can search in the function detailed help to see what each special character does.
To check if a string is a part of another string use Search/Split String instead! Be careful that this function returns the offset of match instead of offset past match.
09-27-2022 12:10 AM
I think it has to do with non-printable characters. I know for sure that null character is not allowed, and you have a null character in your regular expression. I guess my question is why do you need to do this? Maybe we can think of a better way to do whatever it is you are trying to do.
09-27-2022 04:09 AM - edited 09-27-2022 04:10 AM
09-27-2022 09:21 PM - edited 09-27-2022 09:23 PM
Thank you LucianM,
In the read buffer string, there are device register address, data register address and data value, I need to obtain the data from a specified device and data register addresses (or regular expression), so I can extract data starting from the offset past match, The Search/Split String works fine for me.
Gu