2016-11-10 337 views
0

我試圖寫入使用PB12.5的十六進制文件,我能夠寫入它沒有任何問題,但通過測試發現,我將需要發送一個空值(00)的文件在某些​​點。我知道如果我給一個字符串賦予空值,它會將整個字符串空出來,所以我嘗試使用Blob,我可以在需要時插入一個空值(BlobEdit(blb_data,ll_pos,CharA(0)))嘗試寫入使用PB12.5使用BlobEdit(Blob)的十六進制文件(.bin)

但BlobEdit()會自動在每個位置之間插入一個空值,我不希望這樣做,因爲它會導致問題,因爲我試圖更新該十六進制文件。我只需要將我的CharA(lb_byte)添加到Blob中的每個連續位置。

有沒有辦法解決這個問題,或者是PB無法做到這一點?下面是代碼:

ll_test = 1 
    ll_pos = 1 
    ll_length = Len(ls_output) 
    Do While ll_pos <= (ll_length) 
     ls_data = Mid(ls_output, ll_pos, 2) 
     lb_byte = Event ue_get_decimal_value_of_hex(ls_data) 
     ll_test = BlobEdit(blb_data, ll_test, CharA(lb_byte), EncodingANSI!) 
     ll_pos = ll_pos + 2 
    Loop 

十六進制文件顯示如下:

16 35 2D D8 08 45 29 18 35 27 76 25 30 55 66 85 44 66 57 A4 67 99 

斑點更新後:

16 00 48 00 5D 00 C3 92 00 08 00 48 00 51 00 E2 

回答

1

我希望能幫助你:

////////////////////////////////////////////////////////////////////////// 
// Function: f_longtohex 
// Description: LONG to HEXADECIMAL 
// Ambito: public 
// Argumentos:  as_number //Variable long to convert to hexadecimal 
//    as_digitos //Number of digits to return 
// Return:   String  
// Example: 
//    f_longtohex(198 , 2) --> 'C6' 
//    f_longtohex(198 , 4) --> '00C6' 
////////////////////////////////////////////////////////////////////////// 
long ll_temp0, ll_temp1 
char lc_ret 
if isnull(as_digitos) then as_digitos = 2 
IF as_digitos > 0 THEN 
    ll_temp0 = abs(as_number/(16^(as_digitos - 1))) 
    ll_temp1 = ll_temp0 * (16^(as_digitos - 1)) 
    IF ll_temp0 > 9 THEN 
     lc_ret = char(ll_temp0 + 55) 
    ELSE 
     lc_ret = char(ll_temp0 + 48) 
    END IF 
    RETURN lc_ret + f_longtohex(as_number - ll_temp1 , as_digitos - 1) 
END IF 
RETURN '' 
相關問題