首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#采撷程序总是提示device error,无法获得两个输入通道的值

2013-06-26 
C#采集程序总是提示device error,无法获得两个输入通道的值namespace MTS{class DataDeal{public static L

C#采集程序总是提示device error,无法获得两个输入通道的值

namespace MTS
{
    class DataDeal
    {
public static List<Position_Temperature> mvToTemperture(float[] x, float[] ch0, float[] ch1, double slope, double intercept,string path)
        {
        List<Position_Temperature> list_pt = new List<Position_Temperature>();
            if (x == null || ch0 == null || ch1 == null)        
            {
                MessageBox.Show("Device Error!");
                return list_pt ;
            }
            if (!x.Length.Equals(ch0.Length) || !x.Length.Equals(ch1.Length))
            {
                MessageBox.Show("数据维数不等!");
                return list_pt;//输入参数维数不等,返回//2
            }
            int length = x.Length;
            float[] y1Log = new float[length];
            float[] y2Log = new float[length];
            try
            {
                for (int i = 0; i < length; i++)
                {
     y1Log[i] = (float)System.Math.Log(Convert.ToDouble(ch0[i].ToString()), Math.E);
     y2Log[i] = (float)System.Math.Log(Convert.ToDouble(ch1[i].ToString()), Math.E);
                }
                MWArray z = null;
                datadisposeclass drClass = new datadisposeclass();
                z = drClass.data_dispose((MWArray)(MWNumericArray)x,
                                (MWArray)(MWNumericArray)ch1,
                                (MWArray)(MWNumericArray)ch0,
                                (MWArray)(MWNumericArray)y2Log,


                                (MWArray)(MWNumericArray)y1Log,
                                (MWArray)slope, (MWArray)intercept
                            );
                Array r = ((MWNumericArray)z).ToArray(MWArrayComponent.Real);

                Position_Temperature pt = new Position_Temperature();

                StringBuilder t = new StringBuilder();
                StringBuilder bd = new StringBuilder();

                DataTable dt = new DataTable();
                dt.Columns.Add("DetectPosition");
                dt.Columns.Add("Temperature");
                dt.Columns.Add("DetectTime");
                DataRow dr;
                float temp;
                for (int j = 0; j < r.Length; j++)
                {
                    dr = dt.NewRow();
                    dr["DetectPosition"] = (int)(j + 1);
                    temp = (float)r.GetValue(0, j);
                    if (temp == float.NaN)
                    {
                        break;
                    }
                    dr["Temperature"] = (float)r.GetValue(0, j);
                    dr["DetectTime"] = DateTime.Now.ToLocalTime();
                    dt.Rows.Add(dr);
                    pt.Temperature = (float)r.GetValue(0, j);


                    pt.Position = j + 1;
                    list_pt.Add(pt);
                    t.Append(pt.Position + "\t" + pt.Temperature + "\r\n");
                    //temp = (float)r.GetValue(1, j);
                    //bd.Append(pt.Position + '\t' + temp + "\r\n");
                }

                DbOper.InsertBySqlbulk("tb_position_temperature", dt);
                if (!File.Exists(path + @"\Temp\T.txt"))
                {
                    FileStream fs = new FileStream(path + @"\Temp\T.txt", FileMode.CreateNew);
                    fs.Close();
                }
                //if (!File.Exists(path + @"\Temp\BD.txt"))
                //{
                //    FileStream fs = new FileStream(path + @"\Temp\BD.txt", FileMode.CreateNew);
                //    fs.Close();
                //}
                StreamWriter sw = new StreamWriter(path + @"\Temp\T.txt");
                sw.Write(t.ToString());
                //sw = new StreamWriter(path + @"\Temp\BD.txt");
                //sw.Write(bd.ToString());
                sw.Close();
                return list_pt;
            }
            catch
            {
                return list_pt;
            }
        }
    }

    struct Position_Temperature


    {//保存处理后的坐标温度值
        public int Position;
        public float Temperature;
    }
}

C# 采集卡
[解决办法]
if (!OpenDevice("/dev/spcm0")) return dfd;将这句话括号里面改成板卡的ID。

热点排行