AnsweredAssumed Answered

how to pass real&image data to 2 dimention array&data type

Question asked by JosephChoi on Aug 20, 2010
Latest reply on Aug 21, 2010 by odanzy
hi all.

problem is simple ... i just got trace data from ena but i think there's some data_type issue.
i was visual basic user and previous vb code is running good.
first let me explain my VB code. below code is working good. our ena is setting real + image (smith chart)
///////////////////////////////////////////////////////////////

  Call OutputSiclLan(ENA_Address, ":FORM:DATA REAL")
number_of_point = 1227    ''''''///--it's hardware setting
ReDim Data_x(1, Number_Of_Point - 1)        '''''''''/// declare 2 dimention array
Call OutputSiclLan(ENA_Address, ":CALC1:PAR1:SEL")
Dim NumData_s As Long
Call OutputSiclLan(ENA_Address, ":CALC1:DATA:FDAT?")     '''''''/// read out the trace data
NumData_s = EnterSiclLanArrayReal64(ENA_Address, Data_x)    '''''' this point ,, just put trace data into 2 dimensional array.

ReDim Real_VNA_Data_Result(Number_Of_Point - 1)     '''''////make an array,
ReDim Imag_VNA_Data_Result(Number_Of_Point - 1)      '''''''''//// number of point is

ReDim Log_mag_result(Number_Of_Point- 1)       ''''''''''////

For i = 0 To Number_of_Measurement_Point - 1

Real_VNA_Data_Result(i) = Val(Format(Data_x(0, i), "#.######"))
Imag_VNA_Data_Result(i) = Val(Format(Data_x(1, i), "#.######"))
Lin_mag = Sqr(Real_VNA_Data_Result(i) ^ 2 + Imag_VNA_Data_Result(i) ^ 2)
If Lin_mag = 0 Then Lin_mag = 1E-300
Log_mag_result(i) = Val(Format(20 * (Log(Lin_mag) / Log(10#)), "#.######"))

Next i

////////////////////////// above visual basic coding is working fine...
//////////////i understand vb process , so i just convert to C#,,,,
/// please check below coding ,, i just convert to C# coding...
//// before it start C# can't put 1 dimention data to 2 dimentional array.
/////so i just make single array and divide to 2 dimentional array.

myNa01.WriteString(":FORM:DATA REAL ", true);
double [ , ] DATA_X = new double [2,Number_Of_Point-1];           ///declare 2 dimension array,
double[]  fullDATA_X = new double[(Number_Of_Point - 1) * 2];     ///declare 1 dimension array,

myNa01.WriteString(":CALC1:PAR1:SEL", true);
myNa01.WriteString(":CALC1:DATA:FDAT?", true);       ///get trace data from ena
fullDATA_X = (double[])myNa01.ReadIEEEBlock(IEEEBinaryType.BinaryType_R8, true, true);

         for ( i = 0; i < 2; i++)                        /////   i just divide it to 2 dimentional array.
         {
             for (k = 0; k < Number_Of_Point - 1; k++)
             {
                 if (i == 0)
                 {
                     DATA_X[i, k] = fullDATA_X[k];
                 }
                 else
                 {
                     DATA_X[i, k] = fullDATA_X[Number_Of_Point - 1 + k];
                 }
             }
         }
/////////////////////////////////////////////////
//////////////start calculate the data///////////////
///////////////////////////////////////////////
        for (k=0; k <= Number_of_Measurement_Point-1; k++)
        {
            Real_VNA_Data_Result[k] = DATA_X[0, k];
            Imag_VNA_Data_Result[k] = DATA_X[1, k];
            Lin_mag = System.Math.Sqrt( System.Math.Pow(Real_VNA_Data_Result[k],2.0) +
                                   System.Math.Pow(Imag_VNA_Data_Result[k],2.0)  );
            Log_mag_result[k] =  20 * ( Math.Log10(Lin_mag) );
        }
*******************************************************************************************************************************
**********************************************************************************************************************************
this above program is working good.. but real problem is simple .
all command is same as vb  ,,,,,   but C# case when we put trace data to array using  ReadIEEEBlock...
and visual basic is using   EnterSiclLanArrayReal64    function..
when i receive data from VB ,,  it is like  DATA_X(0,0) , DATA_X(0,1)=0.99786  , ~~~~~~~~~~~this is real value
and DATA_X(1,0) = -0.066535   ,   DATA_X(1,1) = -0.10456  ~~~~~ this is imaginery,,,,,,
this is correct value....

but when i run C#,,  the data is something wrong,
DATA_X[0,1] = 2.45665E200 ,,,DATA_X[0,2]= -0.000004423422E-500,, 
SO I GOT INFINITE DATA AND CAN NOT CALCULATE, CALCULATION RESULT ALSO INFINITE.
I THINK THE PROBLEM IS IN DATA TYPE,,
PLEASE ADVICE THIS ISSUE.

THANKS




BELOW IS JUST REFERENCE ,,, INFO OF OUR vb FUNCTION.      EnterSiclLanArrayReal64


Public Function EnterSiclLanArrayReal64(addr As Integer, databuf() As Double) As Long

  Dim status As Integer
  Dim actualcnt As Long
  Dim buf As String * 8
  Dim size As Long
  Dim Dummy As Integer
 
  On Error GoTo ErrHandler
 
  status = SICL4_1.Iread_Equipment(addr, buf, 8, SICL_Constant.I_TERM_MAXCNT, actualcnt)
 
  size = Val(Mid$(buf, 3, 6))
 
  '''Read data
  status = SICL4_1.Iread_Equipment(addr, databuf, size, SICL_Constant.I_TERM_MAXCNT, actualcnt)
 
  '''Read ending LF
  status = SICL4_1.Iread_Equipment(addr, buf, 1, SICL_Constant.I_TERM_MAXCNT, actualcnt)
 
  EnterSiclLanArrayReal64 = size / 8
 
  Exit Function

ErrHandler:
 
  Show_Error Error$, "Sub OutputSiclLan() clsENA", Show_On_Screen
 
  Dummy = SICL4_1.Siclcleanup_Equipment
 
End Function  

Outcomes