先來看一下規格書是怎麼說的:
根據下圖每一個 die的測試結果存放在6個 bytes 資料裡面,
例如:第一個 byte 的14,15 bit是存放測試的結果,
0:表示沒測試;1:表示Pass die
2:表示Fail 1die;3:表示Fail 2die
那要麼取出這個 bit 呢? 很簡單將這個 byte資料右移6次的結果就是第14,15 bit 的資料:
die_test = Int(data[idx]) >> 6
再來看另外一組,如第三個 byte 和第二個 byte 的第1個 bit是存放 Y座標值,要怎麼取出呢?
第三個 byte全部是值只要將資料轉成數字,第二個 byte的第1 bit要取出只要對它和1做 and
運算即可:(因為是高位元所以要乘上 256)
die_y = (Int(data[idx+2]) & 1)*256 + Int(data[idx+3])
最後1個 byte (0-5 bit)是存放 bin 的結果:
bin_n = Int(data[idx + 5])
看你需要讀取哪些資料就用上述方式取出,
接著再建立一個2D的陣列存放資料,由於資料會轉成字串形式因此我宣告為字串型態:
map_txt = ones(String, row, col)
這裡要注意的是通常在C或是Python陣列都是如下的格式,要儲存(取出)都是行(col),列(row)
如下圖,取出 3 的資料會寫成 a = array[2,0] ,a = 3
但在 Julia 是先 列(row),再 行(col)
這樣就可以寫個代碼來表示一下流程:
map = ones(String, row, col)
idx = 237
for r = 1 to row
for c = 1 to col
map[r,c] = read_data
idx += 6
end
end
執行後匯出的結果如下:
應該不難吧?!
這個程式會用到 檔案I/O,格式化輸出,2維陣列存取,邏輯運算子,正規式,型態轉換,
如果都能運用,基本上這個語言的基礎就都具備了。
程式碼:
using Printf
function to_str(data_s, s_pos, e_pos)
str = ""
for idx = s_pos:e_pos
str = str*Char(data_s[idx]) #combine str
end
return str
end
function time_format(time_s)
time_stamp = "20"*time_s[1:2]*"/"*time_s[3:4]*"/"*time_s[5:6]*" "*
time_s[7:8]*":"*time_s[9:10]
end
function read_0_235(data)
run_card = replace(to_str(data, 1, 20), r"\s" => "")
device_name = replace(to_str(data, 21, 36), r"\s" => "")
wafer_size = Int(Int(data[37]) * 256 + Int(data[38]) * 0.1)
global angle = Int(data[49]) * 256 + Int(data[50])
global col = Int(data[53]) * 256 + Int(data[54])
global row = Int(data[55]) * 256 + Int(data[56])
wd = replace(to_str(data, 61, 81), r"[\s+|\0+]" => "")
lot_no = replace(to_str(data, 83, 100), r"\s" => "")
cassette_no = Int(data[101]) * 256 + Int(data[102])
slot_no = Int(data[103]) * 256 + Int(data[104]
s_time = time_format(to_str(data, 149, 158))
e_time = time_format(to_str(data, 161, 170))
l_time = time_format(to_str(data, 173, 182))
u_time = time_format(to_str(data, 185, 194))
status = Int(data[209])
global header_array = []
push!(header_array, "Run_Card:"*run_card)
push!(header_array, "Device_Name:"*device_name)
push!(header_array, "Wafer_Size:"*string(wafer_size))
push!(header_array, "Angle:"*string(angle))
push!(header_array, "Wafer_ID:"*wd)
push!(header_array, "Lot_No:"*lot_no)
push!(header_array, "Cassette_No:"*string(cassette_no))
push!(header_array, "Slot_No:"*string(slot_no))
push!(header_array, "Start_Time :"*s_time)
push!(header_array, "Finish_Time:"*e_time)
push!(header_array, "Load_Time :"*l_time)
push!(header_array, "Unload_Time:"*u_time)
push!(header_array, "Status:"*string(status))
end
function read_236(data)
global map_txt = ["" for i in 1:row , j in 1:col]
#global map_txt = ones(String, row, col)
global pass_dies = 0
global fail_dies = 0
global total_dies = 0
idx = 237
for r = 1:row
for c = 1:col
die_test = Int(data[idx ]) >> 6
die_type = Int(data[idx + 2]) >> 6
dummy = Int(data[idx + 2]) >> 1
dummy = dummy & 1
die_x = (Int(data[idx]) & 1) * 256 + Int(data[idx + 1])
die_y = (Int(data[idx + 2]) & 1) * 256 + Int(data[idx + 3])
bin_n = Int(data[idx + 5])
if die_test == 0
if (die_type == 0) && (dummy == 1)
map_txt[r, c] = "."
elseif (die_type == 1) && (dummy == 0)
map_txt[r, c] = "M"
elseif (die_type == 2) && (dummy == 0)
map_txt[r, c] = "M"
end
end
if die_test == 1 #pass die
map_txt[r, c] = string(bin_n)
pass_dies += 1
end
if die_test == 2 #fail die
fail_dies += 1
if bin_n == 1
map_txt[r, c] = string(bin_n)
else
map_txt[r, c] = string(bin_n)
end
end
idx += 6
end #col loop end
end #row loop end
total_dies = pass_dies + fail_dies
end
function print_header(array)
for i in array
println(i)
end
end
function print_map()
#map_txt2 = []
#map_txt2 = permutedims(map_txt)
#show(stdout, "text/plain", map_txt2)
if angle == 90
for i = 1:col
for j = row:-1:1
@printf "%2s" map_txt[j, i]
end
println()
end
end #if end
end
function print_summary()
println("\n\nSummary\n===========================")
@printf "Total Pass:%6d\n" pass_dies
@printf "Total Fail:%6d\n" fail_dies
@printf "Total Test:%6d\n" total_dies
end
function open_file(fname)
println("Map File: ", fname, "\n")
fin = open(fname, "r")
map_data = read(fin)
end
#-----main Program-----
for i in eachindex(ARGS)
map_data = open_file(ARGS[i])
read_0_235(map_data)
read_236(map_data)
print_header(header_array)
print_map()
print_summary()
end
上一篇:使用 Julia 讀取TSK map 檔案(一)
沒有留言:
張貼留言