Exemple #1
0
        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);
            }
        }
Exemple #2
0
        public bool WriteAm600Element(int netid, SoftElemType elementtype, int startaddress, int ncount, UInt32[] value)
        {
            int nRet = 0;

            if (!bConnectInovanceOk)
            {
                return(false);
            }
            lock (objLock)
            {
                nRet = Am600_Write_Soft_Elem_UInt32(elementtype, startaddress, ncount, value, netid);
            }
            if (1 == nRet)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        public bool ReadAm600Element(int netid, SoftElemType elementtype, int startaddress, int ncount, ref float[] value)
        {
            int nRet = 0;

            if (!bConnectInovanceOk)
            {
                return(false);
            }
            lock (objLock)
            {
                nRet = Am600_Read_Soft_Elem_Float(elementtype, startaddress, ncount, value, netid);
            }
            if (1 == nRet)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        public bool ReadH3UElement(int netid, SoftElemType elementtype, int startaddress, int ncount, ref ushort[] value)
        {
            int nRet = 0;

            if (!bConnectInovanceOk)
            {
                return(false);
            }
            lock (objLock)
            {
                nRet = H3u_Read_Soft_Elem_UInt16(elementtype, startaddress, ncount, value, netid);
            }
            if (1 == nRet)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #5
0
        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);
            }
        }
Exemple #6
0
        private void buttonSet_Click(object sender, EventArgs e)
        {
            bool bRet = false;

            if (dataGridView.SelectedRows.Count <= 0)
            {
                MessageBox.Show("请先选中要设定的行");
                return;
            }

            if (string.IsNullOrEmpty(textBoxName.Text))
            {
                MessageBox.Show("名字为空,请检查!");
                return;
            }
            if (string.IsNullOrEmpty(cbAddressType.SelectedItem.ToString()))
            {
                MessageBox.Show("元件地址为空,请检查!");
                return;
            }
            if (int.Parse(tbStartAddress.Text) < 0)
            {
                MessageBox.Show("元件地址小于零,请检查!");
                return;
            }
            if (string.IsNullOrEmpty(cbDataType.SelectedItem.ToString()))
            {
                MessageBox.Show("元件数据类型为空,请检查!");
                return;
            }
            switch ((PLCDataType)cbDataType.SelectedItem)
            {
            case PLCDataType.BYTE:
                if (tbSetValue.Text != "0" && tbSetValue.Text != "1")
                {
                    MessageBox.Show("字节只能赋值为0或1");
                    return;
                }
                break;

            case PLCDataType.INT16:
                if (!JudgeNumber.isWhloeNumber(tbSetValue.Text))
                {
                    MessageBox.Show("输入数据不是整形");
                    return;
                }
                if (Int64.Parse(tbSetValue.Text) < Int16.MinValue || Int64.Parse(tbSetValue.Text) > Int16.MaxValue)
                {
                    MessageBox.Show("请输入-32768~32767之间的数字!");
                    return;
                }

                break;

            case PLCDataType.INT32:
                if (!JudgeNumber.isWhloeNumber(tbSetValue.Text))
                {
                    MessageBox.Show("输入数据不是整形");
                    return;
                }
                if (Int64.Parse(tbSetValue.Text) < Int32.MinValue || Int64.Parse(tbSetValue.Text) > Int32.MaxValue)
                {
                    MessageBox.Show("请输入-2147483648~2147483647之间的数字!");
                    return;
                }
                break;

            case PLCDataType.UINT16:
                if (!JudgeNumber.isPositiveInteger(tbSetValue.Text))
                {
                    MessageBox.Show("输入数据不是无符号整形");
                    return;
                }
                if (UInt64.Parse(tbSetValue.Text) < 0 || UInt64.Parse(tbSetValue.Text) > 32767)
                {
                    MessageBox.Show("请输入0~32767之间的数字!");
                    return;
                }
                break;

            case PLCDataType.UINT32:
                if (!JudgeNumber.isPositiveInteger(tbSetValue.Text))
                {
                    MessageBox.Show("输入数据不是无符号整形");
                    return;
                }
                if (UInt64.Parse(tbSetValue.Text) < 0 || UInt64.Parse(tbSetValue.Text) > 2147483647)
                {
                    MessageBox.Show("请输入0~2147483647之间的数字!");
                    return;
                }
                break;

            case PLCDataType.FLOAT:
                if (!JudgeNumber.isDecimal(tbSetValue.Text))
                {
                    MessageBox.Show("输入数据不是浮点数");
                    return;
                }
                break;
            }

            string       strName      = textBoxName.Text;
            SoftElemType elementtype  = (SoftElemType)cbAddressType.SelectedItem;
            int          startaddress = int.Parse(tbStartAddress.Text);
            PLCDataType  datatype     = (PLCDataType)cbDataType.SelectedItem;
            string       strValue     = tbSetValue.Text;

            switch (datatype)
            {
            case PLCDataType.BYTE:
                byte[] tempbyte = new byte[1];
                tempbyte[0] = byte.Parse(strValue);
                bRet        = InovanceManage.m_inovanceAPI[netid].WriteH3UElement(netid, elementtype, startaddress, 1, tempbyte);
                break;

            case PLCDataType.INT16:
                Int16[] tempshort = new Int16[1];
                tempshort[0] = short.Parse(strValue);
                bRet         = InovanceManage.m_inovanceAPI[netid].WriteH3UElement(netid, elementtype, startaddress, 1, tempshort);
                break;

            case PLCDataType.INT32:
                Int32[] templong = new Int32[1];
                templong[0] = Int32.Parse(strValue);
                bRet        = InovanceManage.m_inovanceAPI[netid].WriteH3UElement(netid, elementtype, startaddress, 2, templong);
                break;

            case PLCDataType.UINT16:
                UInt16[] tempushort = new UInt16[1];
                tempushort[0] = ushort.Parse(strValue);
                bRet          = InovanceManage.m_inovanceAPI[netid].WriteH3UElement(netid, elementtype, startaddress, 1, tempushort);
                break;

            case PLCDataType.UINT32:
                UInt32[] tempulong = new UInt32[1];
                tempulong[0] = UInt32.Parse(strValue);
                bRet         = InovanceManage.m_inovanceAPI[netid].WriteH3UElement(netid, elementtype, startaddress, 2, tempulong);
                break;

            case PLCDataType.FLOAT:
                float[] tempfloat = new float[1];
                tempfloat[0] = float.Parse(strValue);
                bRet         = InovanceManage.m_inovanceAPI[netid].WriteH3UElement(netid, elementtype, startaddress, 2, tempfloat);
                break;
            }
        }
Exemple #7
0
        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);
                }
            }
        }
Exemple #8
0
 public static extern int H3u_Write_Soft_Elem_UInt32(SoftElemType eType, int nStartAddr, int nCount, UInt32[] pValue, int nNetId = 0);
Exemple #9
0
 public static extern int H3u_Write_Soft_Elem_Int16(SoftElemType eType, int nStartAddr, int nCount, short[] pValue, int nNetId = 0);
Exemple #10
0
 public static extern int Am600_Read_Soft_Elem_Float(SoftElemType eType, int nStartAddr, int nCount, float[] pValue, int nNetId = 0);
Exemple #11
0
 public static extern int Am600_Read_Soft_Elem_UInt32(SoftElemType eType, int nStartAddr, int nCount, UInt32[] pValue, int nNetId = 0);
Exemple #12
0
 public static extern int Am600_Read_Soft_Elem_Int16(SoftElemType eType, int nStartAddr, int nCount, short[] pValue, int nNetId = 0);
Exemple #13
0
 public static extern int Am600_Write_Soft_Elem(SoftElemType eType, int nStartAddr, int nCount, byte[] pValue, int nNetId = 0);
Exemple #14
0
 public static extern int H3u_Read_Soft_Elem(SoftElemType eType, int nStartAddr, int nCount, byte[] pValue, int nNetId = 0);
Exemple #15
0
 public static extern int H3u_Write_Soft_Elem_Float(SoftElemType eType, int nStartAddr, int nCount, float[] pValue, int nNetId = 0);