Exemplo n.º 1
0
        /// <summary>
        /// 获取厂商
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_9(object sender, RoutedEventArgs e)
        {
            byte[] by = new byte[4];
            by[0] = (byte)int.Parse(dz.Text.Trim());
            by[1] = 0x23;
            by[2] = 0x22;
            by[3] = 0x10;

            var crc = CRC16Helper.CRC16(by, 0, by.Length - 1);
            var bit = BitConverter.GetBytes(crc);

            byte[] by2 = new byte[by.Length + 2];
            for (int i = 0; i < by.Length; i++)
            {
                by2[i] = by[i];
            }
            by2[by.Length]     = bit[1];
            by2[by.Length + 1] = bit[0];


            if (sp.IsOpen)
            {
                sp.Write(by2, 0, by2.Length);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 造压+微调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_8(object sender, RoutedEventArgs e)
        {
            byte[] by = new byte[15];
            by[0] = (byte)int.Parse(dz.Text.Trim());
            by[1] = 0x10;
            by[2] = 0x20;
            by[3] = 0x08;

            by[4] = 0x00;
            by[5] = 0x04;

            by[6] = 0x08;

            var zyz = this.zy.Text.Trim();
            //点精度转16
            //Single sin = 5;
            //var sinbyte = BitConverter.GetBytes(sin);
            Single sin   = Single.Parse(zyz);
            var    sinby = BitConverter.GetBytes(sin);

            by[7]  = sinby[1];
            by[8]  = sinby[0];
            by[9]  = sinby[3];
            by[10] = sinby[2];

            by[11] = sinby[1];
            by[12] = sinby[0];
            by[13] = sinby[3];
            by[14] = sinby[2];



            var crc = CRC16Helper.CRC16(by, 0, by.Length - 1);
            var bit = BitConverter.GetBytes(crc);

            byte[] by2 = new byte[by.Length + 2];
            for (int i = 0; i < by.Length; i++)
            {
                by2[i] = by[i];
            }
            by2[by.Length]     = bit[1];
            by2[by.Length + 1] = bit[0];


            if (sp.IsOpen)
            {
                sp.Write(by2, 0, by2.Length);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 设置压力单位
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            byte[] by = new byte[7];
            by[0] = (byte)int.Parse(dz.Text.Trim());
            by[1] = 0x06;
            by[2] = 0x20;
            by[3] = 0x07;

            by[4] = 0x02;

            if (this.combo.SelectedItem == null)
            {
                MessageBox.Show("请选择压力单位");
                return;
            }


            by[5] = 0x00;
            by[6] = (this.combo.SelectedItem as ConfigModel).Value;

            var crc = CRC16Helper.CRC16(by, 0, by.Length - 1);
            var bit = BitConverter.GetBytes(crc);

            byte[] by2 = new byte[by.Length + 2];
            for (int i = 0; i < by.Length; i++)
            {
                by2[i] = by[i];
            }
            by2[by.Length]     = bit[1];
            by2[by.Length + 1] = bit[0];


            if (sp.IsOpen)
            {
                sp.Write(by2, 0, by2.Length);
            }
        }