Beispiel #1
0
 private void GetAngle()//获取角度  线程存放在变量AngleVlue
 {
     while (Value.App_Run)
     {
         int RxLength = Usart.SendData(serialPort1, Usart.ThreadTxBuffer, Usart.ThreadTxBufferSize, ref Usart.ThreadRxBuffer, 100);
         ModBusClass.ModBus_Expend(Usart.ThreadRxBuffer, RxLength, ref Usart.ThreadRxModBusMsg);
         AngleValue = Tools.ByteToFloat(Usart.ThreadRxModBusMsg.Data, 0, 0);
         Thread.Sleep(100);
     }
 }
Beispiel #2
0
        private void button8_Click(object sender, EventArgs e)//回环测试
        {
            byte[] TXBuffer = System.Text.Encoding.GetEncoding("GB2312").GetBytes(textBox3.Text);
            byte[] RXBuffer = new byte[100];
            textBox4.Text = null;
            Application.DoEvents();
            int    Length = Usart.SendDataOne(Value.serialPort1, TXBuffer, TXBuffer.Length, ref RXBuffer, 100);
            string String = System.Text.Encoding.GetEncoding("GB2312").GetString(RXBuffer);

            textBox4.Text = String;
        }
Beispiel #3
0
        private void button8_Click(object sender, EventArgs e)//回环测试
        {
            byte[] TXBuffer = System.Text.Encoding.ASCII.GetBytes(textBox3.Text);
            byte[] RXBuffer = new byte[100];
            pictureBox1.Image = Properties.Resources.Close;
            textBox4.Text     = null;
            Application.DoEvents();
            int    Length = Usart.SendDataOne(serialPort1, TXBuffer, TXBuffer.Length, ref RXBuffer, 100);
            string String = System.Text.Encoding.ASCII.GetString(RXBuffer);

            if (Length > 0)
            {
                pictureBox1.Image = Properties.Resources.Open;
            }
            textBox4.Text = String;
        }
Beispiel #4
0
        private void GetAngle()//获取角度  线程存放在变量AngleVlue
        {
            while (Value.App_Run)
            {
                int RxLength = Usart.SendData(Value.serialPort1, Usart.ThreadTxBuffer, Usart.ThreadTxBufferSize, ref Usart.ThreadRxBuffer, 100);
                ModBusClass.ModBus_Expend(Usart.ThreadRxBuffer, RxLength, ref Usart.ThreadRxModBusMsg);
                AngleValue = Tools.ByteToFloat(Usart.ThreadRxModBusMsg.Data, 0, 0);
                HumiValue  = Tools.ByteToFloat(Usart.ThreadRxModBusMsg.Data, 4, 0);

                try
                {
                    Vol         = Tools.ByteToFloat(Usart.ThreadRxModBusMsg.Data, 8, 0);
                    Userate_CPU = Usart.ThreadRxModBusMsg.Data[12];
                }
                catch { }
                Thread.Sleep(100);
            }
        }
Beispiel #5
0
 private string SendRead(ACFF Mode, byte[] Data, int Length)
 {
     try
     {
         Random ra = new Random();
         FillValue();
         TxModBus.MsgFlag    = (byte)Mode;
         TxModBus.DataFlag   = 0x01;
         TxModBus.DataLength = Length;
         TxModBus.MsgLength  = Length + 3;
         int TxLength = ModBusClass.ModBus_CreateMsg(ref TxBuffer, ref TxModBus, (int)Mode, ra.Next(0, 255), 0x91, Data, Length);
         TxBufferSize = TxLength;
         int RxLength = Usart.SendData(Value.serialPort1, TxBuffer, TxLength, ref RxBuffer, 100);
         ModBusClass.ModBus_Expend(RxBuffer, RxLength, ref RxModBus);
         return(Tools.GetStringFromByte(RxModBus.Data));
     }
     catch { try { Value.serialPort1.Open(); } catch { }; return("NULL"); }
 }
Beispiel #6
0
        private string SendReadSensor(ACFF Mode, byte[] Data, int Length)
        {
            Random ra = new Random();

            timer1.Enabled = false;
            FillValue();
            TxModBus.MsgFlag    = (byte)Mode;
            TxModBus.DataFlag   = 0x91;
            TxModBus.DataLength = Length;
            TxModBus.MsgLength  = Length + 3;
            int TxLength = ModBusClass.ModBus_CreateMsg(ref TxBuffer, ref TxModBus, (int)Mode, ra.Next(0, 255), 0x91, Data, Length);

            textBox5.Text = Tools.HexToString(TxBuffer, TxLength);
            TxBufferSize  = TxLength;
            int RxLength = Usart.SendData(serialPort1, TxBuffer, TxLength, ref RxBuffer, 100);

            textBox6.Text = Tools.HexToString(RxBuffer, RxLength);
            ModBusClass.ModBus_Expend(RxBuffer, RxLength, ref RxModBus);
            if (RxModBus.ErrorFlag == ModBusClass.ModBus_Ok)
            {
                string R = Tools.GetStringFromByte(RxModBus.Data);
                if (Mode == ACFF.ACFF_GetCPUModel)
                {
                    label16.Text = R;
                }
                if (Mode == ACFF.ACFF_GetBSD)
                {
                    label17.Text = R;
                }
                if (Mode == ACFF.ACFF_GetCPUID)
                {
                    label15.Text = R;
                }
                if (Mode == ACFF.ACFF_GetCANSpeed)
                {
                    label14.Text = R;
                }
                if (Mode == ACFF.ACFF_GetSensorModel)
                {
                    label10.Text = R;
                }
                if (Mode == ACFF.ACFF_GetSensorNumber)
                {
                    label11.Text = R;
                }
                if (Mode == ACFF.ACFF_GetSensorName)
                {
                    label12.Text = R;
                }
                if (Mode == ACFF.ACFF_GetSensorNote)
                {
                    label13.Text = R;
                }
                timer1.Enabled = true;
            }
            else
            {
                MessageBox.Show("ModBus解析错误代码[" + RxModBus.ErrorFlag + "]");
            }
            return(Tools.GetStringFromByte(RxModBus.Data));
        }
Beispiel #7
0
        private string SendReadSensor(ACFF Mode, byte[] Data, int Length)
        {
            Random ra = new Random();

            timer1.Enabled = false;
            FillValue();
            TxModBus.MsgFlag    = (byte)Mode;
            TxModBus.DataFlag   = 0x01;
            TxModBus.DataLength = Length;
            TxModBus.MsgLength  = Length + 3;
            int TxLength = ModBusClass.ModBus_CreateMsg(ref TxBuffer, ref TxModBus, (int)Mode, ra.Next(0, 255), 0x91, Data, Length);

            textBox5.Text = Tools.HexToString(TxBuffer, TxLength);
            TxBufferSize  = TxLength;
            RxBuffer      = new byte[512];
            int RxLength = Usart.SendData(Value.serialPort1, TxBuffer, TxLength, ref RxBuffer, 100);

            // MessageBox.Show(Tools.HexToString(RxBuffer, 100));
            textBox6.Text = Tools.HexToString(RxBuffer, RxLength);
            ModBusClass.ModBus_Expend(RxBuffer, RxLength, ref RxModBus);
            if (RxModBus.ErrorFlag == ModBusClass.ModBus_Ok)
            {
                string R = Tools.GetStringFromByte(RxModBus.Data);
                if (Mode == ACFF.SCFF_GetSystemInfor)
                {
                    label16.Text = R;
                }
                if (Mode == ACFF.SCFF_GetCPUModel)
                {
                    label17.Text = R;
                }
                if (Mode == ACFF.SCFF_GetHandVersion)
                {
                    label15.Text = R;
                }
                if (Mode == ACFF.SCFF_GetSoftVersion)
                {
                    label14.Text = R;
                }
                if (Mode == ACFF.SCFF_GetSensorModel)
                {
                    label10.Text = R;
                }
                if (Mode == ACFF.SCFF_GetSensorNumber)
                {
                    label11.Text = R;
                }
                if (Mode == ACFF.SCFF_GetSensorName)
                {
                    label12.Text = R;
                }
                if (Mode == ACFF.SCFF_GetSensorNote)
                {
                    label13.Text = R;
                }
                if (Mode == ACFF.SCFF_GetProgTime)
                {
                    label22.Text = R;
                }
                if (Mode == ACFF.SCFF_GetFlashSize)
                {
                    label41.Text = R;
                }
                if (Mode == ACFF.SCFF_GetLibVersion)
                {
                    label43.Text = R;
                }
            }
            else if (TxModBus.SlaveAddr != ModBusClass.BroadAddr)
            {
                textBox6.Text = "ModBus解析错误代码[" + RxModBus.ErrorFlag + "]";
            }
            return(Tools.GetStringFromByte(RxModBus.Data));
        }