I want to ask about reading string array from PLC Beckhoff.
I have some methods for reading Int16 - it works correctly
public Int16[] ReadArrFromPLC_Int16(string Mnemonic, int ArrLength)
{
Int16[] TempVariable = null;
try
{
ITcAdsSymbol itc = PLC3.adsClient.ReadSymbolInfo(Mnemonic);
long indexGroup = itc.IndexGroup; ;
long indexOffset = itc.IndexOffset;
int[] args = { ArrLength };
TempVariable = (Int16[])PLC3.adsClient.ReadAny(indexGroup, indexOffset, typeof(Int16[]) , args);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Mnemonic);
}
return TempVariable;
}
but if I want to read array of string I get some exception: "Unable to marshal type. Parameter Name: type" in bold place: ...adsClient.ReadAny(indexGroup, indexOffset, typeof(string[]), args);
public string[] ReadArrFromPLC_String(string Mnemonic, int ArrLength)
{
string[] TempVariable = null;
try
{
ITcAdsSymbol itc = PLC3.adsClient.ReadSymbolInfo(Mnemonic);
long indexGroup = itc.IndexGroup; ;
long indexOffset = itc.IndexOffset;
int[] args = { ArrLength };
TempVariable = (string[])PLC3.adsClient.ReadAny(indexGroup, indexOffset, typeof(string[]), args);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Mnemonic);
}
return TempVariable;
}
I can read the array in loop but it take long time.
I found similar topic: MarshalAsAttribute array of strings but I don't know does it help me? and I don't know how I can use it in my case.
Thank you Hans Passant for the tip.
Below I show method - it works correctly, but I had to use loop in order to rewrite text from struct to string[].
Is could be something to add?