mateo.p
(Mateo P)
July 31, 2024, 6:28pm
1
Hello, I need to copy an array of bytes into a string.
I have tried the brsmemcpy and brsmemmove but the resultant string is always empty
brsmemcpy(ADR(CM_Sigmatek_DataComm_Send2), ADR(Sigmatek_Datacomm_Buffer_Send), SIZEOF(Sigmatek_Datacomm_Buffer_Send));
brsmemmove(ADR(CM_Sigmatek_DataComm_Send2), ADR(Sigmatek_Datacomm_Buffer_Send), SIZEOF(Sigmatek_Datacomm_Buffer_Send));
Where CM_Sigmatek_DataComm_Send2 is a STRING[472] and Sigmatek_Datacomm_Buffer_Send is USINT Array [0β¦471]
Any help or suggestions would be greatly appreciated.
Hello Mateo,
First, this is part of your other conversation βConverting custom Data Structure to String - Ask Questions - B&R Community (br-automation.com) .β Please keep the conversation in a single thread.
Second, your string will look empty if the first byte of data is 0 or NULL. A null (denoted as \0, 0 value, not the character) is an indicator that the end of the string is reached, and no further characters should be displayed.
βHelloβ as a string looks like: βHβ βeβ βlβ βlβ βoβ \0 in memory
If you move the \0 to the front, making it: \0 βHβ βeβ βlβ βlβ βoβ in memory, then the resulting string is blank/empty.
Additional reading on STRINGS:
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and the length changed, or it may be fixed (after creation). A string is generally considered as a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. String may also denote more general arrays or ot...
-Austin
2 Likes