调用Java ->C ->dll

yxyvkwin  于 2023-03-06  发布在  Java
关注(0)|答案(1)|浏览(108)

我正在用Java实现一个需要发送C函数的程序,但是它也调用了一个dll,这是C代码:

int SampleCalibration7points(void){
    
    int sel_coeff_7P, neg_flags;
    
    int i, ret;
    
    int cali_type, cali_points;
    
    // COEFFICIENT_COUNT = 10 
    // global variable
    int coefficients[COEFFICIENT_COUNT] = {0};

    // 7 points calibration
    // complete calibration input, 24 bit values
    // {Pressure_ref[%], Pressure_raw, Tambient_ref, Tambient_raw}
    double cali_data[7][4]  =   {   {30,    982368,     10, 420864},
                                    {90,    7950208,    10, 420901},
                                    {30,    770304,     25, 1571148},
                                    {50,    2362176,    25, 1581184},
                                    {90,    7768800,    25, 1581104},
                                    {30,    547968,     40, 2749136},
                                    {90,    7620416,    40, 2749312}};

    int range_check;
    int test;

    double P_raw[7], P_des[7], T_raw[7],T_raw_back[7], T_des[7];
    double P_corr[7], T_corr[7],P_corr_percent[7], T_corr_deg[7]; 
    
    
    // limit definition
    // pressure limits are 0 and 100, due to percentage reference
    double T_min = -40.0, T_max = 85.0;
     
    // choose coefficient to be calculated

    /*
        //FLAGS for selCoeffs
        #define CO_OFFSET_S         0x1
        #define CO_GAIN_S           0x2
        #define CO_TCG              0x4
        #define CO_TCO              0x8
        #define CO_SOT_TCO          0x10
        #define CO_SOT_TCG          0x20
        #define CO_SOT_S            0x40
        #define CO_OFFSET_T         0x80
        #define CO_GAIN_T           0x100
        #define CO_SOT_T            0x200
    */
    sel_coeff_7P = (CO_OFFSET_S|CO_GAIN_S|CO_TCO|CO_TCG|CO_OFFSET_T|CO_GAIN_T|CO_SOT_TCO|CO_SOT_TCG|CO_SOT_T|CO_SOT_S);    

    // calibration type, default value 
    cali_type = 0;
    
    // number of calibration points
    cali_points = 7;   
    
    // rearrange data for coefficent calculation
    for ( i=0; i < cali_points; i++ ) {
        
        P_raw[i] = cali_data[i][1];
        // generate digital reference pressure values -> P_des[x]
        P_des[i] = ConvertBridgeFromPercent( cali_data[i][0]);
        
        T_raw[i] = cali_data[i][3] ;  
        // generate digital reference temp values -> T_des[x]
        ConvertTempFromDegrees(&T_des[i], cali_data[i][2], T_min, T_max );
    }

    // call DLL function
    // coefficent calculation
    ret = CalculateCoefficients( coefficients,
                                    &neg_flags, 
                                    cali_points, //number of coeffs max 7 
                                    sel_coeff_7P,
                                    cali_type, 
                                    P_raw, P_des, 
                                    T_raw, T_des);    

        /********** Coefficients resulst, T[-40..85]    *************
        coefficients =  {   -520831,
                            5880723,
                            489,
                            379060,
                            -4349,
                                -296970,
                            -278951,
                            -317710,
                            3817446,
                            -49055
                        }
        ***************************************************/
    
    for (i = 0;i<cali_points;i++){
        // call DLL functions
        T_corr[i] = GetCorrectedTemp(coefficients, T_raw[i]);
        ConvertTempToDegrees (&T_corr_deg[i] , (int) T_corr[i],  T_min, T_max );

        P_corr[i] = GetCorrectedBridge (coefficients, P_raw[i] , T_raw[i]); 
        P_corr_percent[i] = ConvertBridgeToPercent(P_corr[i]); 
        // Convert pressure precentage values to the according pressure values, depending on customers limits
    }
        /********** Corrected raw values, applying coefficients *************  
        
        corrected temperature[counts] =         
                            {       
                                 6710884,   
                                 6710949,   
                                 8712632,   
                                 8729989,   
                                 8729851,   
                                10737550,   
                                10737550    
                            }
                            
        corrected pressure [counts]=            
                            {
                                  5033172,  
                                 15099510,  
                                  5033171,  
                                  8388615,  
                                 15099510,  
                                  5033171,  
                                 15099510   
                            }                   
        *******************************************************************/    

    //check coefficients range, returns 1 when range is exceeded, else 0 
    // call DLL function
    range_check = VerifyCoefficients(coefficients) ;                                   
    return 0;
}

并且dll为校准L6.dll
例如:CalculateCoefficients是属于dll的函数之一。
你知道什么是最好的方法吗?因为我不知道如果使用JNI功能,我的C文件是否会继续调用所需的dll。
我尝试用Java直接调用dll(CalibrationL6.dll),但不支持,这就是为什么我尝试使用C代码代替。

57hvy0tb

57hvy0tb1#

请提供全部因为问题你是陈述是在printf陈述,这是不存在在给的代码.在它之上我不知道你怎样是能够得到输出因为我得到几个未宣告的变量的错误.如果你想要校准在java然后你必须使用%d.f而不是dll和使用printf陈述当类型%d.f而不是println

相关问题