public void BuildRawString_FromWork(Models.SiemensTag tag) { string str = tag.Content.ToString(); int stringLenght = tag.Content.ToString().Length; byte[] b = new byte[stringLenght + 2]; b[0] = (byte)(tag.MaxStringLenght + 2); b[1] = (byte)stringLenght; try { //controllo se la stringa che devo scrivere non sia null, oppure maggiore del limite massimo imposto dal plc if (str == null) { throw new Exception("La stringa da convertire non può essere null."); } if (str.Length > tag.MaxStringLenght) { throw new Exception("La stringa Inserita è più lunga del massimo consentito da questa variabile"); } for (int i = 0; i < stringLenght; i++) { b[i + 2] = (byte)str[i]; } tag.RawContent = b; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void BuildWorkString_FromRaw(Models.SiemensTag tag) { string raw = tag.RawContent.ToString(); int lunghezzaRaw = raw[1]; int startingOffset = 2; tag.Content = raw.Substring(startingOffset, lunghezzaRaw); }