public GALILEO_RETURN_CODE Connect(String targetID, bool autoConnect, int timeout, Action <GALILEO_RETURN_CODE, String> onConnect = null, Action <GALILEO_RETURN_CODE, String> onDisconnect = null) { byte[] targetIDBytes = Encoding.ASCII.GetBytes(targetID); if (onConnect != null) { onConnectCB = (status, id, length) => { byte[] result = new byte[length]; Marshal.Copy(id, result, 0, (int)length); onConnect?.Invoke(status, Encoding.ASCII.GetString(result, 0, (int)length)); }; } if (onDisconnect != null) { onDisconnectCB = (status, id, length) => { byte[] result = new byte[length]; Marshal.Copy(id, result, 0, (int)length); onDisconnect?.Invoke(status, Encoding.ASCII.GetString(result, 0, (int)length)); }; } return(GalileoFunctions.Connect(instance, Encoding.ASCII.GetBytes(targetID), targetIDBytes.Length, autoConnect, timeout, onConnectCB, onDisconnectCB)); }