public static bool ReadPLCValueFloat(ScanItem item, ref double readvalue) { if (string.IsNullOrEmpty(item.strValue)) { readvalue = 0.0f; return(false);; } else { readvalue = double.Parse(item.strValue); return(true);; } }
public static bool ReadPLCValueInt16(ScanItem item, ref Int16 readvalue) { if (string.IsNullOrEmpty(item.strValue)) { readvalue = 0; return(false);; } else { readvalue = Int16.Parse(item.strValue); return(true);; } }
public static bool SetPLCValueInt32(int plcindex, ScanItem item, Int32 setvalue) { SoftElemType type = item.AddressType; int address = item.Address; Int32[] value = new Int32[1]; value[0] = setvalue; if (m_inovanceAPI[plcindex].WriteH3UElement(plcindex, type, address, 2, value)) { return(true); } else { return(false); } }
public static bool ReadPLCValueByte(ScanItem item, ref bool bread) { if (string.IsNullOrEmpty(item.strValue)) { bread = false; return(false);; } else { if (item.strValue == "0") { bread = false; } else if (item.strValue == "1") { bread = true; } return(true);; } }
private void buttonModify_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count <= 0) { MessageBox.Show("请先选中要修改行"); return; } int iRow = dataGridView.SelectedRows[0].Index; if (iRow >= 0) { if (UniqueCheck(0)) { string strName = dataGridView.Rows[iRow].Cells[0].Value.ToString(); ScanItem updatedictionary = InovanceManage.m_inovanceDoc[netid].m_scanDictionary[strName]; ScanItem updatelist = InovanceManage.m_inovanceDoc[netid].m_ScanDataList[iRow]; dataGridView.Rows[iRow].Cells[0].Value = textBoxName.Text; updatedictionary.strName = textBoxName.Text; updatelist.strName = textBoxName.Text; dataGridView.Rows[iRow].Cells[1].Value = (SoftElemType)cbAddressType.SelectedItem; updatedictionary.AddressType = (SoftElemType)cbAddressType.SelectedItem; updatelist.AddressType = (SoftElemType)cbAddressType.SelectedItem; dataGridView.Rows[iRow].Cells[2].Value = tbStartAddress.Text; updatedictionary.Address = int.Parse(tbStartAddress.Text); updatelist.Address = int.Parse(tbStartAddress.Text); dataGridView.Rows[iRow].Cells[3].Value = (PLCDataType)cbDataType.SelectedItem; updatedictionary.DataType = (PLCDataType)cbDataType.SelectedItem; updatelist.DataType = (PLCDataType)cbDataType.SelectedItem; //dataGridView.Rows[iRow].Cells[4].Value = false; //updatedictionary.bScanning = false; //updatelist.bScanning = false; } } }
public static bool SetPLCValueByte(int plcindex, ScanItem item, bool bset) { SoftElemType type = item.AddressType; int address = item.Address; byte[] value = new byte[1]; if (bset) { value[0] = 1; } else { value[0] = 0; } if (m_inovanceAPI[plcindex].WriteH3UElement(plcindex, type, address, 1, value)) { return(true); } else { return(false); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (!UniqueCheck(1)) { return; } try { ScanItem item = new ScanItem(); item.strName = textBoxName.Text; item.Address = int.Parse(tbStartAddress.Text); item.AddressType = (SoftElemType)cbAddressType.SelectedItem; item.DataType = (PLCDataType)cbDataType.SelectedItem; int length = 1; for (int i = 0; i < length; i++) { ScanItem newitem = new ScanItem(); newitem.AddressType = (SoftElemType)cbAddressType.SelectedItem; newitem.DataType = (PLCDataType)cbDataType.SelectedItem; DataGridViewRow gridrow = new DataGridViewRow(); //element name DataGridViewTextBoxCell elementnamecell = new DataGridViewTextBoxCell(); item.strName = textBoxName.Text; if (i > 0) { item.strName = textBoxName.Text + "_" + i.ToString(); } elementnamecell.Value = item.strName; //element type DataGridViewTextBoxCell elementtypecell = new DataGridViewTextBoxCell(); elementtypecell.ValueType = typeof(SoftElemType); elementtypecell.Value = item.AddressType; //element address DataGridViewTextBoxCell elementaddresscell = new DataGridViewTextBoxCell(); item.Address = int.Parse(tbStartAddress.Text) + i; elementaddresscell.Value = item.Address; //element data type DataGridViewTextBoxCell elementdatatypecell = new DataGridViewTextBoxCell(); elementdatatypecell.ValueType = typeof(PLCDataType); elementdatatypecell.Value = item.DataType; //scan item //DataGridViewCheckBoxCell scancell = new DataGridViewCheckBoxCell(); //scancell.Value = item.bScanning; //value item DataGridViewTextBoxCell valuecell = new DataGridViewTextBoxCell(); valuecell.Value = item.strValue; InovanceManage.m_inovanceDoc[netid].m_ScanDataList.Add(item); InovanceManage.m_inovanceDoc[netid].m_scanDictionary.Add(item.strName, item); gridrow.Cells.Add(elementnamecell); gridrow.Cells.Add(elementtypecell); gridrow.Cells.Add(elementaddresscell); gridrow.Cells.Add(elementdatatypecell); //gridrow.Cells.Add(scancell); gridrow.Cells.Add(valuecell); dataGridView.Rows.Add(gridrow); } } catch { } }
public void ScanPLC() { if (InovanceManage.m_inovanceAPI[netid].bConnectInovanceOk == false) { return; } while (true) { Action action1 = () => { if (InovanceManage.m_inovanceAPI[netid].bConnectInovanceOk) { ConnIndicatePB.Image = Green; } else { ConnIndicatePB.Image = Grey; } }; ConnIndicatePB.Invoke(action1); for (int i = 0; i < dataGridView.Rows.Count; i++) { //if (!bool.Parse(dataGridView.Rows[i].Cells[4].Value.ToString())) //{ // continue; //} try { string strName = dataGridView.Rows[i].Cells[0].Value.ToString(); ScanItem updatedictionary = InovanceManage.m_inovanceDoc[netid].m_scanDictionary[strName]; ScanItem updatelist = InovanceManage.m_inovanceDoc[netid].m_ScanDataList[i]; SoftElemType elementtype = (SoftElemType)dataGridView.Rows[i].Cells[1].Value; int startaddress = int.Parse(dataGridView.Rows[i].Cells[2].Value.ToString()); PLCDataType datatype = (PLCDataType)dataGridView.Rows[i].Cells[3].Value; string strValue = string.Empty; switch (datatype) { case PLCDataType.BYTE: byte[] tempbyte = new byte[1]; InovanceManage.m_inovanceAPI[netid].ReadH3UElement(netid, elementtype, startaddress, 1, ref tempbyte); strValue = tempbyte[0].ToString(); break; case PLCDataType.INT16: short[] tempshort = new short[1]; InovanceManage.m_inovanceAPI[netid].ReadH3UElement(netid, elementtype, startaddress, 1, ref tempshort); strValue = tempshort[0].ToString(); break; case PLCDataType.INT32: Int32[] templong = new Int32[1]; InovanceManage.m_inovanceAPI[netid].ReadH3UElement(netid, elementtype, startaddress, 2, ref templong); strValue = templong[0].ToString(); break; case PLCDataType.UINT16: ushort[] tempushort = new ushort[1]; InovanceManage.m_inovanceAPI[netid].ReadH3UElement(netid, elementtype, startaddress, 1, ref tempushort); strValue = tempushort[0].ToString(); break; case PLCDataType.UINT32: UInt32[] tempulong = new UInt32[1]; InovanceManage.m_inovanceAPI[netid].ReadH3UElement(netid, elementtype, startaddress, 2, ref tempulong); strValue = tempulong[0].ToString(); break; case PLCDataType.FLOAT: float[] tempfloat = new float[1]; InovanceManage.m_inovanceAPI[netid].ReadH3UElement(netid, elementtype, startaddress, 2, ref tempfloat); strValue = tempfloat[0].ToString(); break; } updatedictionary.strValue = strValue; updatelist.strValue = strValue; Action action = () => { dataGridView.Rows[i].Cells[4].Value = strValue; }; this.Invoke(action); } catch (Exception ex) { Action action = () => { dataGridView.Rows[i].Cells[4].Value = ex.ToString(); }; this.Invoke(action); } Thread.Sleep(10); } } }