public void Echo() { client.DBRead(1021, 0, echoReadBuffer.Length, echoReadBuffer); heartBeat = S7.GetIntAt(echoReadBuffer, 0); S7.SetIntAt(echoWriteBuffer, 0, (short)heartBeat); int writeResult = client.DBWrite(1022, 0, echoWriteBuffer.Length, echoWriteBuffer); }
public static void StateMotor(int numDB) { // Initialisation var res = -1; // Résultat de la fonction byte[] Buffer = new byte[2]; // Buffer 2 bytes byte[] BufferBis = new byte[55]; // Buffer 10 bytes if (Main._statusConnection) { res = Main.Client.DBRead(numDB, 80, 2, Buffer); } BitArray arBits = new BitArray(Buffer); // Convert buffer bytes to array of bits for (int i = 0; i < 15; i++) { Main._arStateMotor.Add(arBits.Get(i)); // Fill the array } if (Main._statusConnection) { res = Main.Client.DBRead(numDB, 56, 55, BufferBis); } Main._dspdMotor = S7.GetRealAt(BufferBis, 0); Main._dintMotor = S7.GetIntAt(BufferBis, 6) / 10; Main._dspdFMotor = S7.GetDIntAt(BufferBis, 48) / 100; }
/// <summary> /// 自动步骤 /// </summary> /// <param name="client"></param> /// <param name="dbNum"></param> /// <param name="dbByteLength"></param> /// <param name="dbStartElement"></param> /// <returns></returns> public static string[] ReadAutoStep(S7Client client, int dbNum, int dbByteLength, int dbStartElement) { // int dbInt; // dbInt = S7.GetIntAt(ReadBuffer, Convert.ToInt16(element)); // value = "" + dbInt; //double dbLReal = S7.GetLRealAt(ReadBuffer, 94);//读取Real位置在94 //txtReadServoPos.Text = dbLReal.ToString(); result = client.DBRead(dbNum, 0, dbByteLength, ReadBuffer);//dbNum from 0 length dbByteLength byte int dbInt = S7.GetIntAt(ReadBuffer, dbStartElement); for (int i = 1; i <= strAutoSteps.Length; i++) { if (i == dbInt) { strAutoStep[0] = strAutoSteps[i - 1];//当前步骤 if (i == strAutoSteps.Length) { strAutoStep[1] = strAutoSteps[0]; //下一步骤 } else { strAutoStep[1] = strAutoSteps[i]; } } } return(strAutoStep); }
public void Parse(byte[] buffer, int start) { plcDateTime = S7.GetDateTimeAt(buffer, start); start = start + 8; logEntryNumber = S7.GetDIntAt(buffer, start); start = start + 4; SRMNumber = S7.GetIntAt(buffer, start); start = start + 2; logEntryType = S7.GetStringAt(buffer, start); start = start + 52; logEntryDescription = S7.GetStringAt(buffer, start); start = start + 202; functionName = S7.GetStringAt(buffer, start); start = start + 52; operationMode = S7.GetStringAt(buffer, start); start = start + 52; faultOrWarningState = (FaultOrWarningState)S7.GetIntAt(buffer, start); start = start + 2; XPosition_mm = S7.GetDIntAt(buffer, start); start = start + 4; YPosition_mm = S7.GetDIntAt(buffer, start); start = start + 4; Z1Position_mm = S7.GetIntAt(buffer, start); start = start + 2; Z2Position_mm = S7.GetIntAt(buffer, start); start = start + 2; Z3Position_mm = S7.GetIntAt(buffer, start); start = start + 2; Z4Position_mm = S7.GetIntAt(buffer, start); start = start + 2; XTarget_mm = S7.GetDIntAt(buffer, start); start = start + 4; YTarget_mm = S7.GetDIntAt(buffer, start); start = start + 4; Z1Target_mm = S7.GetIntAt(buffer, start); start = start + 2; Z2Target_mm = S7.GetIntAt(buffer, start); start = start + 2; Z3Target_mm = S7.GetIntAt(buffer, start); start = start + 2; Z4Target_mm = S7.GetIntAt(buffer, start); start = start + 2; XSpeed_mmps = S7.GetIntAt(buffer, start); start = start + 2; YSpeed_mmps = S7.GetIntAt(buffer, start); start = start + 2; Z1Speed_mmps = S7.GetIntAt(buffer, start); start = start + 2; Z2Speed_mmps = S7.GetIntAt(buffer, start); start = start + 2; Z3Speed_mmps = S7.GetIntAt(buffer, start); start = start + 2; Z4Speed_mmps = S7.GetIntAt(buffer, start); start = start + 2; }
public int readPlcDbwValue(string plcIp, int Rack, int Slot, int DbNum, int DbwNum) { Client.ConnectTo(plcIp, Rack, Slot); Client.DBRead(DbNum, DbwNum, 2, Buffer);//读取DbwNum所对应的字的值 Client.Disconnect(); return(S7.GetIntAt(Buffer, 0)); }
private void getDbwValues() { ReadDbw(); int Pos = System.Convert.ToInt32(dbwNum.Text); int S7Int = S7.GetIntAt(Buffer, Pos); dbwValue.Text = System.Convert.ToString(S7Int); }
private void BtnUpdateMonitor_Click(object sender, EventArgs e) { try { if (this.m_InfoList.Count < 0) { throw new Exception(@"不存在正在监视的变量"); } for (var index = 0; index < this.m_InfoList.Count; index++) { var block = this.m_BlockDict[this.m_InfoList[index].BlockName]; var offsetByte = this.m_InfoList[index].OffsetByte; var offsetBit = this.m_InfoList[index].OffsetBit; var stringLength = this.m_InfoList[index].StringLength; var dataType = this.m_InfoList[index].DataType; string strValue; switch (dataType) { case DataType.Bit: strValue = S7.GetBitAt(block, offsetByte, offsetBit).ToString(); break; case DataType.Byte: strValue = S7.GetUSIntAt(block, offsetByte).ToString(); break; case DataType.Ushort: strValue = S7.GetUIntAt(block, offsetByte).ToString(); break; case DataType.Uint: strValue = S7.GetUDIntAt(block, offsetByte).ToString(); break; case DataType.Ulong: strValue = S7.GetULIntAt(block, offsetByte).ToString(); break; case DataType.Sbyte: strValue = S7.GetSIntAt(block, offsetByte).ToString(); break; case DataType.Short: strValue = S7.GetIntAt(block, offsetByte).ToString(); break; case DataType.Int: strValue = S7.GetDIntAt(block, offsetByte).ToString(); break; case DataType.Long: strValue = S7.GetLIntAt(block, offsetByte).ToString(); break; case DataType.Float: strValue = S7.GetRealAt(block, offsetByte).ToString(CultureInfo.InvariantCulture); break; case DataType.Double: strValue = S7.GetLRealAt(block, offsetByte).ToString(CultureInfo.InvariantCulture); break; case DataType.String: var byteArr = new byte[stringLength]; Array.Copy(block, offsetByte, byteArr, 0, stringLength); strValue = System.Text.Encoding.ASCII.GetString(byteArr); break; default: throw new ArgumentOutOfRangeException(); } this.lvMonitor.Items[index].SubItems[2].Text = strValue; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button8_Click(object sender, EventArgs e) { int Pos = System.Convert.ToInt32(textBox15.Text); int S7Int = S7.GetIntAt(Buffer, Pos); textBox14.Text = System.Convert.ToString(S7Int); }
public void RangierenOutput(byte[] digOutput, byte[] anOutput) { if (!mainWindow.DebugWindowAktiv) { mainWindow.Q1 = S7.GetBitAt(digOutput, (int)BitPosAusgang.Q1); mainWindow.Y = S7.GetIntAt(anOutput, 0); mainWindow.Ie = S7.GetIntAt(anOutput, 2); } }
public void RangierenOutput(byte[] digOutput, byte[] anOutput) { mainWindow.P1 = S7.GetBitAt(digOutput, (int)BitPosAusgang.P1); mainWindow.P2 = S7.GetBitAt(digOutput, (int)BitPosAusgang.P2); mainWindow.Q3_RL = S7.GetBitAt(digOutput, (int)BitPosAusgang.Q3_RL); mainWindow.Q4_LL = S7.GetBitAt(digOutput, (int)BitPosAusgang.Q4_LL); mainWindow.XFU = S7.GetBitAt(digOutput, (int)BitPosAusgang.XFU); mainWindow.FuSpeed = S7.GetIntAt(anOutput, 0); }
public int ReadValue() { lock (_lockObject) { _plcConnection.DBRead(10, 0, 4, _buffer); int value = S7.GetIntAt(_buffer, 2); return(value); } }
private void timer1_Tick(object sender, EventArgs e) { try { this.result = this.Client.DBRead(10, 38, 10, this.db1Buffer); } catch (Exception ex) { int num = (int)MessageBox.Show(ex.Message); this.result = -1; } if ((uint)this.result > 0U) { this.ShowResult(this.result); } try { // Setta la word del DB10 all'int che ha il PLC(?) // dbBuffer = Array di byte this.db10.Word01 = S7.GetIntAt(this.db1Buffer, 0); this.db10.Word02 = S7.GetIntAt(this.db1Buffer, 2); this.db10.Word03 = S7.GetIntAt(this.db1Buffer, 4); this.db10.Word04 = S7.GetIntAt(this.db1Buffer, 6); this.db10.Word05 = S7.GetIntAt(this.db1Buffer, 8); // Setta i vari label/etc... dell'UI Label lblValore01 = this.lblValore01; short num = this.db10.Word01; string str1 = num.ToString(); lblValore01.Text = str1; Label lblValore02 = this.lblValore02; num = this.db10.Word02; string str2 = num.ToString(); lblValore02.Text = str2; Label lblValore03 = this.lblValore03; num = this.db10.Word03; string str3 = num.ToString(); lblValore03.Text = str3; Label lblValore04 = this.lblValore04; num = this.db10.Word04; string str4 = num.ToString(); lblValore04.Text = str4; Label lblValore05 = this.lblValore05; num = this.db10.Word05; string str5 = num.ToString(); lblValore05.Text = str5; // Scrive il db10 nel file XML, noi prob. dovremmo usare il DBSQL CSerialDeserial.WriteFile(this.db10); } catch (Exception ex) { int num = (int)MessageBox.Show(ex.Message); this.result = -1; } }
private void BtnRead_Click(object sender, EventArgs e) { var buffer = new byte[14];//guncelle int readresult = Plc.DBRead(2, 0, buffer.Length, buffer); TxtRead1.Text = Convert.ToString(S7.GetBitAt(buffer, 0, 0)); //0.byte'ın 0.biti TxtRead2.Text = Convert.ToString(S7.GetBitAt(buffer, 0, 1)); //0.byte'ın 1.biti TxtRead3.Text = Convert.ToString(S7.GetIntAt(buffer, 2)); // 2. byte (for plc 1int= 2 byte) TxtRead4.Text = Convert.ToString(S7.GetUDIntAt(buffer, 4)); //4. byte (for plc 1dint= 4 byte) TxtRead5.Text = Convert.ToString(S7.GetWordAt(buffer, 8)); //8.byte (1 word = 2 byte) TxtRead6.Text = Convert.ToString(S7.GetDWordAt(buffer, 10)); //10.byte (1 dword = 4 byte) =10+4=14 oldu bufferda 14tü. }
public void Tick(S7Client c) { byte[] buffer = new byte[24]; byte[] buffer_out = new byte[10]; c.DBRead(1, 0, 24, buffer); gas_v = S7.GetRealAt(buffer, 0); pump = S7.GetRealAt(buffer, 4); steam_v = S7.GetRealAt(buffer, 8); water_lvl = S7.GetRealAt(buffer, 12); pressure = S7.GetRealAt(buffer, 16); alrm = S7.GetIntAt(buffer, 20); torch = S7.GetBitAt(buffer, 22, 0); if (alrm == 0) { water_lvl += 0.02f * pump; if (torch) { water_lvl -= 0.01f * gas_v; pressure += 0.01f * gas_v; } pressure -= 0.03f * steam_v; if (water_lvl < 0) { water_lvl = 0; alrm = 3; } if (water_lvl > 1) { water_lvl = 1; alrm = 4; } if (pressure < 0.3f) { pressure = 0.3f; } if (pressure > 0.95f) { alrm = 1; } if (pressure > 1) { alrm = 2; } S7.SetRealAt(buffer_out, 0, water_lvl); S7.SetRealAt(buffer_out, 4, pressure); S7.SetIntAt(buffer_out, 8, (short)alrm); c.DBWrite(1, 12, 10, buffer_out); } }
private bool ReadValue() { var client = _connection?.PlcClient; if (client == null) { return(false); } var buffer = new byte[Math.Max(64, _info.ByteCount + 2)]; var result = client.DBRead(_info.DbNumber, _info.Offset, _info.ByteCount, buffer); if (result != 0) { TronTrace.TraceError($"PlcItem.DBRead({_info.DbNumber}, {_info.Offset}) failed - {result} {PlcResult.GetResultText(result)}"); return(false); } switch (_info.PlcDataType) { case PlcDataTypes.X: _value = S7.GetBitAt(buffer, 0, _info.Bit) ? 1 : 0; break; case PlcDataTypes.B: _value = S7.GetByteAt(buffer, 0); break; case PlcDataTypes.INT: _value = S7.GetIntAt(buffer, 0); break; case PlcDataTypes.DINT: _value = S7.GetDIntAt(buffer, 0); break; case PlcDataTypes.DT: _value = S7.GetDateTimeAt(buffer, 0); break; case PlcDataTypes.STRING: _value = S7.GetStringAt(buffer, 0); break; } if (!_value.Equals(_oldValue)) { _oldValue = _value; ValueChanged?.Invoke(this); } return(true); }
private static void Reader_ReadHandler(object sender, ReadEventArgs e) { Task.Run(() => { if (e.Result == 0 || e.Result == 5) { var CXNCKD = S7.GetIntAt(e.Data, 42); Console.WriteLine(string.Format("一号线-车辆车厢内侧宽度:{0}", CXNCKD)); var CXNCCD = S7.GetIntAt(e.Data, 40); Console.WriteLine(string.Format("一号线-车辆车厢内侧长度:{0}", CXNCCD)); var CKGD = S7.GetIntAt(e.Data, 6); Console.WriteLine(string.Format("一号线-车框高度:{0}", CKGD)); var SDZCBS = S7.GetIntAt(e.Data, 36); Console.WriteLine(string.Format("一号线-设定装车包数:{0}", SDZCBS)); var JHZQCS = S7.GetIntAt(e.Data, 34); Console.WriteLine(string.Format("一号线-计划抓取次数:{0}", JHZQCS)); var DQZCSKZL = S7.GetIntAt(e.Data, 176); Console.WriteLine(string.Format("一号线-当前装车刷卡重量:{0}", DQZCSKZL)); var ZZCS = S7.GetDIntAt(e.Data, 138); Console.WriteLine(string.Format("一号线-总装车数:{0}", ZZCS)); var DTZCS = S7.GetIntAt(e.Data, 142); Console.WriteLine(string.Format("一号线-当天装车数:{0}", DTZCS)); var ZZCZL = S7.GetRealAt(e.Data, 158); Console.WriteLine(string.Format("一号线-总装车重量:{0}", ZZCZL)); var DTZCZL = S7.GetRealAt(e.Data, 162); Console.WriteLine(string.Format("一号线-当天装车重量:{0}", DTZCZL)); var JCSJHG = S7.GetBitAt(e.Data, 70, 2); Console.WriteLine(string.Format("一号线-检测数据合格:{0}", JCSJHG)); var WMBXZHG = S7.GetBitAt(e.Data, 70, 3); Console.WriteLine(string.Format("一号线-尾门板X值合格:{0}", WMBXZHG)); var DQZCZL = S7.GetDIntAt(e.Data, 0); Console.WriteLine(string.Format("一号线-当前装车重量:{0}", DQZCZL)); var CPH = S7.GetStringAt(e.Data, 180, Encoding.GetEncoding("GB2312")); Console.WriteLine(string.Format("一号线-车牌号:{0}", CPH)); } e.Dispose(); e = null; }); }
public StructDB0 Lectura2(int DbNumber, int offSetStart) { StructDB0 Result = new StructDB0(); byte[] readBuffer = new byte[4]; client.DBRead(DbNumber, offSetStart, readBuffer.Length, readBuffer);//Lectura de buffer //Extraer datos y meterlos en Struct Result.SerialNumber = S7.GetIntAt(readBuffer, 0).ToString(); Result.TestResult = (short)S7.GetWordAt(readBuffer, 2); return(Result);// Devuelve un objeto del tipo StructDB0 }
private void button5_Click(object sender, EventArgs e) { byte[] bob = new byte[2]; int result = s7Client.DBRead(1, 0, 2, bob); if (result == 0) { bool bo = Convert.ToBoolean(S7.GetIntAt(bob, 0)); toolStripStatusLabel1.Text = bo ? "True" : "False"; } else { toolStripStatusLabel1.Text = s7Client.ErrorText(result); } }
public StructDB0 Lectura(int DbNumber, int offSetStart) { StructDB0 Result = new StructDB0(); byte[] readBuffer = new byte[21]; client.DBRead(DbNumber, offSetStart, readBuffer.Length, readBuffer);//Lectura de buffer //Extraer datos y meterlos en Struct Result.SerialNumber = S7.GetCharsAt(readBuffer, 0, 12); Result.TestResult = S7.GetIntAt(readBuffer, 12); Result.RealDetector = S7.GetRealAt(readBuffer, 14); Result.byte20 = S7.GetByteAt(readBuffer, 20); return(Result);// Devuelve un objeto del tipo StructDB0 }
private void getDbwValues() { ReadDbw(); int Pos = System.Convert.ToInt32(dbwNum.Text); int S7Int = S7.GetIntAt(Buffer, Pos); textBox8.Text = System.Convert.ToString(S7Int); textBox8.Enabled = false; listInfo.Items.Add(DateTime.Now.ToString()); listInfo.Items.Add("从DB" + dbNum.Text + "获取到的DBW" + dbwNum.Text + "的值是" + System.Convert.ToString(S7Int)); listInfo.Items.Add("---"); if (listInfo.Items.Count > 20) { listInfo.Items.Clear(); } }
/// <summary> /// 确认槽标志及槽号 /// </summary> /// <param name="slot"></param> /// <returns></returns> public bool ReadUnloadSlot(int Dbnmb, out int slot) { byte[] buf = new byte[4]; bool result = ReadData(Dbnmb, 0, 4, buf); slot = -1; if (result) { result = S7.GetBitAt(buf, 0, 0); if (result) { slot = S7.GetIntAt(buf, 2); } } return(result); }
private void RefreshValues() { lock (_locker) { var buffer = new byte[4]; int result = _client.DBRead(1, 0, buffer.Length, buffer); if (result == 0) { PumpState = S7.GetBitAt(buffer, 0, 2); HighLimit = S7.GetBitAt(buffer, 0, 3); LowLimit = S7.GetBitAt(buffer, 0, 4); TankLevel = S7.GetIntAt(buffer, 2); } else { Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "\t Read error: " + _client.ErrorText(result)); } } }
/// <summary> /// extract value from raw buffer /// </summary> /// <param name="buffer"> buffer length must be greater than Offset.ByteOffset+4, else do nothing </param> public void GetValueFromGroupBuffer(byte[] buffer) { if (buffer.Length < Offset.ByteOffset + 4) { return; } switch (VType) { case varType.BOOL: Value = S7.GetBitAt(buffer, Offset.ByteOffset, Offset.BitOffset); break; case varType.BYTE: Value = S7.GetByteAt(buffer, Offset.ByteOffset); break; case varType.WORD: Value = S7.GetWordAt(buffer, Offset.ByteOffset); break; case varType.DWORD: Value = S7.GetDWordAt(buffer, Offset.ByteOffset); break; case varType.INT: Value = S7.GetIntAt(buffer, Offset.ByteOffset); break; case varType.DINT: Value = S7.GetDIntAt(buffer, Offset.ByteOffset); break; case varType.REAL: Value = S7.GetRealAt(buffer, Offset.ByteOffset); break; // Added String Read case varType.STRING: Value = S7.GetStringAt(buffer, Offset.ByteOffset); break; } }
private void ReadSeqDB() { while (isConnected) { sequenceClient.DBRead(3102, 0, stepReadBuffer.Length, stepReadBuffer); changeScreen = S7.GetBitAt(stepReadBuffer, 0, 0); stationNum = S7.GetIntAt(stepReadBuffer, 2); //Console.WriteLine(changeScreen); if (!stationSet) { if (lblStationNum.InvokeRequired) { lblStationNum.Invoke((MethodInvoker) delegate { lblStationNum.Text = "STN: " + stationNum; }); } stationSet = true; } if (hasRestarted) { oSignalSeqEvent.Set(); hasRestarted = false; } else if (changeScreen && !hasChanged) { hasChanged = true; oSignalSeqEvent.Set(); } else if (!changeScreen && hasChanged) { hasChanged = false; } Thread.Sleep(50); } }
public string GetDecS(byte[] buffer) { string i = "[Error]"; switch (buffer.Length) { case 1: i = S7.GetSIntAt(buffer, 0).ToString(); break; case 2: i = S7.GetIntAt(buffer, 0).ToString(); break; case 4: i = S7.GetDIntAt(buffer, 0).ToString(); break; } return(i); }
internal override void DbRead() { lock (base._locker) { var buffer = new byte[60]; int result = _client.DBRead(53, 0, buffer.Length, buffer); if (result == 0) //If no error { //Casting byte array to value type Number = S7.GetIntAt(buffer, 0); Name = S7.GetStringAt(buffer, 2); IsDoubler = S7.GetBitAt(buffer, 28, 0); SendTrigger = S7.GetBitAt(buffer, 28, 1); SpendingEmployee = S7.GetStringAt(buffer, 30); } else { throw new Exception(" Read error S7-1200 error: " + _client.ErrorText(result) + " Time: " + DateTime.Now.ToString("HH:mm:ss")); } } }
private int GetValueOfTypeFromPlc() { switch (ObjectConfigure.WorldLen) { case S7Consts.S7WLBit: return(Convert.ToInt32(S7.GetBitAt(BufferData, 0, 0))); case S7Consts.S7WLByte: case S7Consts.S7WLChar: return(Convert.ToInt32(S7.GetByteAt(BufferData, 0))); case S7Consts.S7WLWord: case S7Consts.S7WLInt: return(Convert.ToInt32(S7.GetIntAt(BufferData, 0))); case S7Consts.S7WLDWord: case S7Consts.S7WLReal: return(Convert.ToInt32(S7.GetRealAt(BufferData, 0))); default: return(0); } }
private void _dataReadTimer_Elapsed(object sender, ElapsedEventArgs e) { if (!_s7Plc.Connected) { RaiseIsDisconnected(); return; } // Do the read lock (_lockObject) { var readResult = _s7Plc.DBRead(10, 4, 2, _inBuffer); if (readResult > 0) { PlcLastErrorMessage = _s7Plc.ErrorText(readResult); RaiseError(); } _currentReadValue = S7.GetIntAt(_inBuffer, 0); } RaiseDataReaded(); }
private void ReadPLC() { // Connect if disconnected if (!client.Connected) { client.Connect(); } //Do this for each DB in the configuration foreach (var db in configService.ActiveConfig.DBReads) { Byte[] buffer = new byte[db.DBLengthByte]; var ret = client.DBRead(db.DBNumber, db.DBOffsetByte, db.DBLengthByte, buffer); var errorText = client.ErrorText(ret); if (ret == 0) { Console.WriteLine($"Reading DB{db.DBNumber} success."); } else { Console.WriteLine($"Reading DB{db.DBNumber} failed, error {ret}:, {errorText}"); } //Parse the db into parts foreach (var tag in db.Tags) { switch (tag.Type) { case "Bool": tag.Data = S7.GetBitAt(buffer, tag.OffsetByte, tag.OffsetBit); break; case "Int8": tag.Data = S7.GetByteAt(buffer, tag.OffsetByte); break; case "Int16": tag.Data = S7.GetIntAt(buffer, tag.OffsetByte); break; case "Int32": tag.Data = S7.GetDIntAt(buffer, tag.OffsetByte); break; case "Int64": tag.Data = S7.GetLIntAt(buffer, tag.OffsetByte); break; case "Float": tag.Data = S7.GetRealAt(buffer, tag.OffsetByte); break; case "Double": tag.Data = S7.GetLRealAt(buffer, tag.OffsetByte); break; case "String": tag.Data = S7.GetCharsAt(buffer, tag.OffsetByte, tag.StringLength); break; default: Console.WriteLine($"Unknown type for tag {tag.Name}"); break; } } } }
private void FieldBtn_Click(object sender, EventArgs e) { /* * 0 Byte 8 Bit Word (All) * 1 Word 16 Bit Word (All) * 2 DWord 32 Bit Word (All) * 3 LWord 64 Bit Word (S71500) * 4 USint 8 Bit Unsigned Integer (S71200/1500) * 5 UInt 16 Bit Unsigned Integer (S71200/1500) * 6 UDInt 32 Bit Unsigned Integer (S71200/1500) * 7 ULint 64 Bit Unsigned Integer (S71500) * 8 Sint 8 Bit Signed Integer (S71200/1500) * 9 Int 16 Bit Signed Integer (All) * 10 DInt 32 Bit Signed Integer (S71200/1500) * 11 LInt 64 Bit Signed Integer (S71500) * 12 Real 32 Bit Floating point (All) * 13 LReal 64 Bit Floating point (S71200/1500) * 14 Time 32 Bit Time elapsed ms (All) * 15 LTime 64 Bit Time Elapsed ns (S71500) * 16 Date 16 Bit days from 1990/1/1 (All) * 17 TOD 32 Bit ms elapsed from midnight (All) * 18 DT 8 Byte Date and Time (All) * 19 LTOD 64 Bit time of day (ns) (S71500) * 20 DTL 12 Byte Date and Time Long (S71200/1500) * 21 LDT 64 Bit ns elapsed from 1970/1/1 (S71500) */ int Pos = System.Convert.ToInt32(TxtOffset.Text); switch (CBType.SelectedIndex) { case 0: { TxtValue.Text = "16#" + System.Convert.ToString(Buffer[Pos], 16).ToUpper(); break; } case 1: { UInt16 Word = S7.GetWordAt(Buffer, Pos); TxtValue.Text = "16#" + System.Convert.ToString(Word, 16).ToUpper(); break; } case 2: { UInt32 DWord = S7.GetDWordAt(Buffer, Pos); TxtValue.Text = "16#" + System.Convert.ToString(DWord, 16).ToUpper(); break; } case 3: { UInt64 LWord = S7.GetLWordAt(Buffer, Pos); TxtValue.Text = "16#" + System.Convert.ToString((Int64)LWord, 16).ToUpper(); // <-- Convert.ToString does not handle UInt64 break; } case 4: { UInt16 USInt = S7.GetUSIntAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(USInt); break; } case 5: { UInt16 UInt = S7.GetUIntAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(UInt); break; } case 6: { UInt32 UDInt = S7.GetDWordAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(UDInt); break; } case 7: { UInt64 ULInt = S7.GetLWordAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(ULInt); break; } case 8: { int SInt = S7.GetSIntAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(SInt); break; } case 9: { int S7Int = S7.GetIntAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(S7Int); break; } case 10: { int DInt = S7.GetDIntAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(DInt); break; } case 11: { Int64 LInt = S7.GetLIntAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(LInt); break; } case 12: { Single S7Real = S7.GetRealAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(S7Real); break; } case 13: { Double S7LReal = S7.GetLRealAt(Buffer, Pos); TxtValue.Text = System.Convert.ToString(S7LReal); break; } case 14: { Int32 TimeElapsed = S7.GetDIntAt(Buffer, Pos); // TIME type is a 32 signed number of ms elapsed // Can be added to a DateTime or used as Value. TxtValue.Text = "T#" + System.Convert.ToString(TimeElapsed) + "MS"; break; } case 15: { Int64 TimeElapsed = S7.GetLIntAt(Buffer, Pos); // LTIME type is a 64 signed number of ns elapsed // Can be added (after a conversion) to a DateTime or used as Value. TxtValue.Text = "LT#" + System.Convert.ToString(TimeElapsed) + "NS"; break; } case 16: { DateTime DATE = S7.GetDateAt(Buffer, Pos); TxtValue.Text = DATE.ToString("D#yyyy-MM-dd"); break; } case 17: { DateTime TOD = S7.GetTODAt(Buffer, Pos); TxtValue.Text = TOD.ToString("TOD#HH:mm:ss.fff"); break; } case 18: { DateTime DT = S7.GetDateTimeAt(Buffer, Pos); TxtValue.Text = DT.ToString("DT#yyyy-MM-dd-HH:mm:ss.fff"); break; } case 19: { DateTime LTOD = S7.GetLTODAt(Buffer, Pos); TxtValue.Text = LTOD.ToString("LTOD#HH:mm:ss.fffffff"); break; } case 20: { DateTime DTL = S7.GetDTLAt(Buffer, Pos); TxtValue.Text = DTL.ToString("DTL#yyyy-MM-dd-HH:mm:ss.fffffff"); break; } case 21: { DateTime LDT = S7.GetLDTAt(Buffer, Pos); TxtValue.Text = LDT.ToString("LDT#yyyy-MM-dd-HH:mm:ss.fffffff"); break; } } }