//20200917 读取M位 public bool getPlcMX(string plcIp, int pos, int bit) { byte[] Buffer = new byte[1];//M6.0 即读取MB6,一个字节的长度即可,所以定义Buffer的长度为1个字节 Client.ConnectTo(plcIp, 0, 3); Client.MBRead(pos, 1, Buffer); Client.Disconnect(); return(S7.GetBitAt(Buffer, 0, bit)); }
public void RangierenOutput(byte[] digOutput, byte[] anOutput) { mainWindow.Leuchte_P1 = S7.GetBitAt(digOutput, (int)BitPosAusgang.P1); foreach (Behaelter beh in mainWindow.gAlleBehaelter) { beh.BehalterDatenRangierenOutput(digOutput); } }
public bool getPlcDbxVaule(string plcIp, int Rack, int Slot, int DbNum, int dbx, int dbxx) { byte[] Buffer = new byte[1]; Client.ConnectTo(plcIp, Rack, Slot); Client.DBRead(DbNum, dbx, 1, Buffer);//读取Dbx所对应的值 Client.Disconnect(); return(S7.GetBitAt(Buffer, 0, dbxx)); }
public void RangierenOutput(byte[] digOutput, byte[] anOutput) { mainWindow.M1 = S7.GetBitAt(digOutput, (int)BitPosAusgang.M1); mainWindow.K1 = S7.GetBitAt(digOutput, (int)BitPosAusgang.K1); mainWindow.K2 = S7.GetBitAt(digOutput, (int)BitPosAusgang.K2); mainWindow.P1 = S7.GetBitAt(digOutput, (int)BitPosAusgang.P1); mainWindow.P2 = S7.GetBitAt(digOutput, (int)BitPosAusgang.P2); }
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); } }
public static bool ReadBitFromBuffer(int address, int subAddress, byte[] buffer) { try { return(S7.GetBitAt(buffer, address, subAddress)); } catch { } return(false); }
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 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); } }
private bool StatusM(string a, int b, int c, int d) { bool w; byte[] Buffer = new byte[18]; if (a == "A") { int result2 = CPU.ABRead(b, 4, Buffer); if (result2 != 0) { MetroFramework.MetroMessageBox.Show(this, CPU.ErrorText(result2)); } else { //Fehler weil Zahl nicht höher als Buffer sein darf!!! //Faktorrechnung einfügen!!! w = S7.GetBitAt(Buffer, 0, c); return(w); } } else if (a.Equals("DB")) { int result3 = CPU.DBRead(b, c, 4, Buffer); if (result3 != 0) { MetroFramework.MetroMessageBox.Show(this, CPU.ErrorText(result3)); } else { //Fehler weil Zahl nicht höher als Buffer sein darf!!! //Faktorrechnung einfügen!!! w = S7.GetBitAt(Buffer, 0, d); return(w); } } else { int result2 = CPU.EBRead(b, 4, Buffer); if (result2 != 0) { MetroFramework.MetroMessageBox.Show(this, CPU.ErrorText(result2)); } else { //Fehler weil Zahl nicht höher als Buffer sein darf!!! //Faktorrechnung einfügen!!! w = S7.GetBitAt(Buffer, 0, c); return(w); } } return(false); }
public void ReadIMask(int start, int bit, out bool result) { result = false; byte[] buf = new byte[1]; lock (syncLock) { int code = _s7Client.EBRead(start, 1, buf); Validate(code); } result = S7.GetBitAt(buf, 0, bit); }
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 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ü. }
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; }); }
private void timer1_Tick(object sender, EventArgs e) { byte[] db1Buffer = new byte[58]; ///db1 dbsinin okunacak alaninin buffer adresi isaretleniyor Result = client.DBRead(1, 0, 58, db1Buffer); ///db1 dbsinin tum bytlari okunuyor 58 adet byte var db1 de if (Result != 0) ///sonuc sifirsa hata mesaji ver degilse devam et { toolStripStatusLabel1.Text = client.ErrorText(Result); } double db1_dbd18 = S7.GetRealAt(db1Buffer, 18); ///db1 dbsinin buffer a alinmis 58 byte icerisinde 18. real olan bayti oku ve double degiskene ata textBox_act_ref.Text = db1_dbd18.ToString("0.##"); /// double degiskeni (db1_dbd18) string degere donustur ve textbox a yaz progressBar_press.Value = Convert.ToInt32(db1_dbd18); double db1_dbd14 = S7.GetRealAt(db1Buffer, 14); textBox_temp.Text = db1_dbd14.ToString("0.##"); progressBar_temp.Value = Convert.ToInt32(db1_dbd14); bool motor1_state, motor2_state, motor3_state; motor1_state = S7.GetBitAt(db1Buffer, 54, 3); motor2_state = S7.GetBitAt(db1Buffer, 54, 4); motor3_state = S7.GetBitAt(db1Buffer, 54, 5); if (motor1_state == true) { m1_state.BackColor = Color.Green; } else { m1_state.BackColor = Color.Red; } if (motor2_state == true) { m2_state.BackColor = Color.Green; } else { m2_state.BackColor = Color.Red; } if (motor3_state == true) { m3_state.BackColor = Color.Green; } else { m3_state.BackColor = Color.Red; } }
private void ReadUserDB() { while (isConnected) { usersClient.DBRead(3103, 0, rfidReadBuffer.Length, rfidReadBuffer); hasReadRFID = S7.GetBitAt(rfidReadBuffer, 0, 0); if (hasReadRFID) { oSignalUserEvent.Set(); } Thread.Sleep(50); } }
/// <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); }
public void SpreadCycle() { PLcDBRead(); if (S7.GetBitAt(DB1, Execute_Spread_Cycle[0], Execute_Spread_Cycle[1])) { S7.SetBitAt(ref DB1, Execute_Spread_Cycle[0], Execute_Spread_Cycle[1], false); PLcDBWrite(); } S7.SetBitAt(ref DB1, Execute_Spread_Cycle[0], Execute_Spread_Cycle[1], true); PLcDBWrite(); while (S7.GetBitAt(DB1, Execute_Spread_Cycle[0], Execute_Spread_Cycle[1])) { System.Threading.Thread.Sleep(100); PLcDBRead(); } }
private void RefreshValues() { lock (_locker) { var buffer = new byte[1]; int result = _client.DBRead(1, 0, buffer.Length, buffer); if (result == 0) { Db1Dbx00 = S7.GetBitAt(buffer, 0, 0); } else { Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "\t Read error: " + _client.ErrorText(result)); } } }
public void HomeZ1() { PLcDBRead(); if (S7.GetBitAt(DB1, Execute_Move_Z1[0], Execute_Move_Z1[1])) { S7.SetBitAt(ref DB1, Execute_Move_Z1[0], Execute_Move_Z1[1], false); PLcDBWrite(); } S7.SetBitAt(ref DB1, Execute_Move_Z1[0], Execute_Move_Z1[1], true); PLcDBWrite(); while (S7.GetBitAt(DB1, Execute_Move_Z1[0], Execute_Move_Z1[1])) { System.Threading.Thread.Sleep(100); PLcDBRead(); } }
//Function to move axis Z2 ( the print bed) with set step public void StepZ2(float step) { PLcDBRead(); if (S7.GetBitAt(DB1, Execute_Move_Z2[0], Execute_Move_Z2[1])) { S7.SetBitAt(ref DB1, Execute_Move_Z2[0], Execute_Move_Z2[1], false); PLcDBWrite(); } S7.SetRealAt(DB1, Pos_Z2, step); S7.SetBitAt(ref DB1, Execute_Move_Z2[0], Execute_Move_Z2[1], true); PLcDBWrite(); while (S7.GetBitAt(DB1, Execute_Move_Z2[0], Execute_Move_Z2[1])) { System.Threading.Thread.Sleep(100); P }
public void HomeAll() { PLcDBRead(); if (S7.GetBitAt(DB1, Home_all_axes[0], Home_all_axes[1])) { S7.SetBitAt(ref DB1, Home_all_axes[0], Home_all_axes[1], false); PLcDBWrite(); } S7.SetBitAt(ref DB1, Home_all_axes[0], Home_all_axes[1], true); PLcDBWrite(); while (S7.GetBitAt(DB1, Home_all_axes[0], Home_all_axes[1])) { System.Threading.Thread.Sleep(100); PLcDBRead(); } }
private void Status() { lock (_locker) { var buffer2 = new byte[2]; int result2 = _client.DBRead(5, 0, buffer2.Length, buffer2); if (result2 == 0) { MinusA1Status = S7.GetBitAt(buffer2, 0, 0); } else { Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "\t Read error: " + _client.ErrorText(result2)); } } }
public void HomeZ2() { PLcDBRead(); if (S7.GetBitAt(DB1, Start_Homing_Z2[0], Start_Homing_Z2[1])) { S7.SetBitAt(ref DB1, Start_Homing_Z2[0], Start_Homing_Z2[1], false); PLcDBWrite(); } S7.SetBitAt(ref DB1, Start_Homing_Z2[0], Start_Homing_Z2[1], true); PLcDBWrite(); while (S7.GetBitAt(DB1, Start_Homing_Z2[0], Start_Homing_Z2[1])) { System.Threading.Thread.Sleep(100); PLcDBRead(); } }
internal static object GetS7Value(Tag tagItem, byte[] buffer) { object returnValue; if (tagItem.DataType == "Bit") { returnValue = S7.GetBitAt(buffer, tagItem.Position, 0); } else if (tagItem.DataType == "Word") { returnValue = S7.GetWordAt(buffer, 0); } else if (tagItem.DataType == "Short") { returnValue = S7.GetShortAt(buffer, 0); } else if (tagItem.DataType == "DWord") { returnValue = S7.GetDWordAt(buffer, 0); } else if (tagItem.DataType == "DInt") { returnValue = S7.GetDIntAt(buffer, 0); } else if (tagItem.DataType == "Float") { returnValue = S7.GetFloatAt(buffer, 0); } else if (tagItem.DataType == "String") { returnValue = S7.GetStringAt(buffer, 0, buffer.Length); } else if (tagItem.DataType == "PrintableString") { returnValue = S7.GetPrintableStringAt(buffer, 0, buffer.Length); } else if (tagItem.DataType == "Date") { returnValue = S7.GetDateAt(buffer, 0); } else { returnValue = S7.GetStringAt(buffer, 0, buffer.Length); } return(returnValue); }
public void MoveZ2Down() { PLcDBRead(); if (S7.GetBitAt(DB1, Execute_Move_Z2[0], Execute_Move_Z2[1])) { S7.SetBitAt(ref DB1, Execute_Move_Z2[0], Execute_Move_Z2[1], false); PLcDBWrite(); } S7.SetRealAt(DB1, Pos_Z1, 10); S7.SetBitAt(ref DB1, Execute_Move_Z2[0], Execute_Move_Z2[1], true); PLcDBWrite(); while (S7.GetBitAt(DB1, Execute_Move_Z2[0], Execute_Move_Z2[1])) { System.Threading.Thread.Sleep(100); PLcDBRead(); } }
/// <summary> /// 验证下料完成标志 /// </summary> /// <param name="clientId"></param> /// <returns></returns> public bool VerifyGripCompleted(int clientId) { bool result = false; byte[] buf = new byte[1]; result = ReadData(clientId, 0, 1, buf); if (result) { result = S7.GetBitAt(buf, 0, 6); if (result) { // 重置标志位 result = WritePlcFlags(clientId, 0, false, new int[] { 6 }); } } return(result); }
public bool VerifyWirteIDCompleted(int nmb) { byte[] buf = new byte[1]; bool result = false; lock (syncObj) { if (_s7Client.Connected()) { result = ReadData(nmb, 256, 1, buf); if (result) { result = S7.GetBitAt(buf, 0, 1); } } } return(result); }
public void ChangePosX(float amount) { PLcDBRead(); if (S7.GetBitAt(DB1, Execute_move_X[0], Execute_move_X[1])) { S7.SetBitAt(ref DB1, Execute_move_X[0], Execute_move_X[1], false); PLcDBRead(); System.Threading.Thread.Sleep(100); } S7.SetRealAt(DB1, Pos_X, amount); S7.SetBitAt(ref DB1, Execute_move_X[0], Execute_move_X[1], true); PLcDBWrite(); while (S7.GetBitAt(DB1, Execute_move_X[0], Execute_move_X[1])) { System.Threading.Thread.Sleep(100); PLcDBRead(); } }
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)); } } }