Example #1
0
        /// <summary>
        /// 读取下位机返回的数据
        /// </summary>
        /// <returns></returns>
        public static byte[] ReadAndWriteToDevice(String cmd)
        {
            int len = 64;

            byte[] inputdatas = new byte[len];
            try
            {
                byte[] outdatas = new byte[len];
                outdatas[0] = 0x55;
                outdatas[1] = 0x2;
                outdatas[2] = 0x1;
                outdatas[3] = 0x00;
                byte[] inputs = StringToBytes(cmd, new string[] { ",", " " }, 16);
                if (inputs != null && inputs.Length > 0)
                {
                    outdatas = inputs;
                }
                System.Windows.Forms.Application.DoEvents();
                //MyDeviceManagement.InputAndOutputReports(0, false, outdatas, ref inputdatas, 100);

                if (MyDeviceManagement.WriteReport(0, false, outdatas, ref inputdatas, 100))
                {
                    int length = 0;
                    while (!MyDeviceManagement.ReadReport(0, false, outdatas, ref inputdatas, 100))
                    {
                        length++;
                        if (length == 20)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(inputdatas);
        }