Example #1
0
        public bool m_holdContinue = false; //取引伸计后的继续标志

        public void SendPauseTest()
        {
            m_pause = !m_pause;

            byte[] buf = new byte[5];
            int    ret;

            buf[0] = 0x04;                                                              //命令字节
            buf[1] = 0xf3;                                                              //试验保持命令
            buf[2] = 0;
            buf[3] = 0;
            buf[4] = 0;

            ret = RwUsb.WriteData1582(1, buf, 5, 1000);                         //发送写命令
        }
Example #2
0
        private void btnAccess_Click(object sender, EventArgs e)
        {
            /*
             *      在实际的应用程序中,应设置一配置(读取全部传感器信息)完成全局标志。
             *      因为如果pc机程序没有配置,而随便发出控制命令,可能造成发给主机的命令
             *      不正确而失控!
             */

            byte[] buf = new byte[203];
            int    ret;
            int    offset  = 0;
            int    len     = 0;
            int    m_value = 0;
            byte   i       = 0;
            int    m_index = 0;

            byte[] m_temp = new byte[20];

            buf[0] = 0x01;                                                              //命令字节
            buf[1] = Convert.ToByte(offset / 256);                                      //偏移量
            buf[2] = Convert.ToByte(offset % 256);
            buf[3] = Convert.ToByte(len / 256);                                         //每次读的长度
            buf[4] = Convert.ToByte(len % 256);

            ret = RwUsb.WriteData1582(1, buf, 5, 1000);                                 //发送读命令

            len = 203;
            ret = RwUsb.ReadData1582(2, buf, len, 5000);                                    //读数据

            m_ControlCount = len;
            m_NuIni        = buf[1];
            m_NuIni        = m_NuIni << 8;
            m_NuIni        = m_NuIni | buf[0];
            m_SensorCount  = buf[2];
            //查找所有传感器
            for (i = 0; i < m_SensorCount; i++)
            {
                m_SensorArray[i].sockt  = buf[i * 10 + 3];
                m_SensorArray[i].type   = buf[i * 10 + 4];
                m_SensorArray[i].volt   = buf[i * 10 + 5];
                m_SensorArray[i].direct = buf[i * 10 + 6];

                m_SensorArray[i].scale  = buf[i * 10 + 8];
                m_SensorArray[i].scale  = m_SensorArray[i].scale << 8;
                m_SensorArray[i].scale |= buf[i * 10 + 7];

                m_SensorArray[i].balance  = buf[i * 10 + 10];
                m_SensorArray[i].balance  = m_SensorArray[i].balance << 8;
                m_SensorArray[i].balance |= buf[i * 10 + 9];

                m_SensorArray[i].gain  = buf[i * 10 + 12];
                m_SensorArray[i].gain  = m_SensorArray[i].gain << 8;
                m_SensorArray[i].gain |= buf[i * 10 + 11];
            }

            m_LoadSensorCount         = 0;
            m_DisplacementSensorCount = 0;
            m_ElongateSensorCount     = 0;
            //传感器序号及ID
            for (i = 0; i <= m_SensorCount; i++)
            {
                if (m_SensorArray[i].type == 0x80)
                {
                    m_DSensorArray[m_DisplacementSensorCount].SensorIndex = i;

                    m_DisplacementSensorCount++;
                }
                else if (m_SensorArray[i].type == 0x81)
                {
                    m_LSensorArray[m_LoadSensorCount].SensorIndex = i;
                    m_LoadSensorCount++;
                }
                else if (m_SensorArray[i].type == 0x82)
                {
                    m_ESensorArray[m_ElongateSensorCount].SensorIndex = i;
                    m_ElongateSensorCount++;
                }
            }

            SensorArrayFlag = 1;

            if (m_SensorCount > 0)
            {
                //this.tsbtnAccess.BackColor = Color.Gray;
                this.tsbtnAccess.Text      = "已连接";
                this.tsbtnAccess.ForeColor = Color.Green;
            }
            else
            {
                //this.tsbtnAccess.BackColor = Color.Gray;
                this.tsbtnAccess.Text      = "连接";
                this.tsbtnAccess.ForeColor = Color.Blue;
            }

            //生成传感器列表
            //    m_GridConfig.put_Rows(m_SensorCount+1);

            for (i = 0; i < m_SensorCount; i++)
            {
                m_index = i;
                string[] _arrSensors = new string[4];
                _arrSensors[0] = m_index.ToString();
                switch (m_SensorArray[i].type)
                {
                case 0x80:
                    _arrSensors[1] = "位移";
                    m_value        = m_SensorArray[i].scale;
                    m_value        = m_value >> 8;
                    m_value        = (int)(m_value * Math.Pow(10.0, m_SensorArray[i].scale & 0x000f));
                    _arrSensors[2] = m_value.ToString();
                    _arrSensors[3] = m_SensorArray[i].sockt.ToString();
                    break;

                case 0x81:
                    _arrSensors[1] = "负荷";
                    m_value        = m_SensorArray[i].scale;
                    m_value        = m_value >> 8;
                    m_value        = (int)(m_value * Math.Pow(10.0, m_SensorArray[i].scale & 0x000f));
                    _arrSensors[2] = m_value.ToString();
                    _arrSensors[3] = m_SensorArray[i].sockt.ToString();
                    break;

                case 0x82:
                    _arrSensors[1] = "变形";
                    m_value        = m_SensorArray[i].scale;
                    m_value        = m_value >> 8;
                    m_value        = (int)(m_value * Math.Pow(10.0, m_SensorArray[i].scale & 0x000f));
                    _arrSensors[2] = m_value.ToString();
                    _arrSensors[3] = m_SensorArray[i].sockt.ToString();
                    break;

                default:
                    break;
                }

                //AddSensorToListview(_arrSensors, this.listView1);
            }
            ftr.M_DisplacementSensorCount = this.m_DisplacementSensorCount;
            ftr.M_DSensorArray            = this.m_DSensorArray;
            ftr.M_ElongateSensorCount     = this.m_ElongateSensorCount;

            ftr.M_ESensorArray    = this.m_ESensorArray;
            ftr.M_LoadSensorCount = this.m_LoadSensorCount;
            ftr.M_LSensorArray    = this.m_LSensorArray;
            ftr.M_SensorArray     = this.m_SensorArray;
            ftr.M_SensorArrayFlag = this.SensorArrayFlag;
            ftr.M_SensorCount     = this.m_SensorCount;
        }