Copying an array of bytes to a String

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:

-Austin

2 Likes