2015-10-06 67 views
1

我試圖在當前目錄下名爲「test」的文件夾中創建一個名爲「test.txt」的文件,並在其中添加一些文本行。顯示操作中的不同操作

我在程序中使用此代碼段,但得到一個異常說,file is already in use by another process。這部分有沒有問題?

File.Create(FileName); 
string fullPathName2 = Path.GetFullPath(FileName);    
File.AppendAllText(fullPathName2, time + Environment.NewLine); 

回答

1

在「靜態」代碼中,您有一個循環來設置矩陣的每一列。每次要設置的列由DL中的位掩碼選擇,它從0x80開始(第一列),然後再旋轉7次(0x40,0x20,0x10,...),然後它返回到其初始值值,並且由於矩陣中有8列,每次都會得到相同的圖像。

請注意,內存轉儲實際上是繪製數字的位圖,每個字節表示單個列,從左到右。

在「移動」版本中,在每個循環(我們上面提到過)之後,我們執行另一個循環到DL,使它從下一個循環的下一列開始,所以如果第一個循環是從0x80- 0x01(導致矩陣的列取值00 00 41 FF 01 00 00 00),第二個是0x40-0x80。 (導致矩陣的列取值00 41 FF 01 00 00 00 00

例如,

迭代1:

value 00 00 41 FF 01 00 00 00 
col 0 1 2 3 4 5 6 7 

迭代2:

value 00 00 41 FF 01 00 00 00 
col 7 0 1 2 3 4 5 6 

編輯:

在我們僅在列之一點亮的LED每次迭代中,和其餘的是關斷,但似乎所有的列都已設置(這是一種幻覺)。我不知道燈光是否真的存在,但這就是我們無論如何看到的。

我的意思是在任何細胞,如果相應的行和列值等於1,則細胞會發光?

是,例如(X - LED上,O- - LED關閉):

0 O O O O O O O O 1 O O X X O O O O 1 O O O O O O O O 
0 O O O O O O O O 1 O O X X O O O O 1 O O O O O O O O 
1 O O O O O X O O 1 O O X X O O O O 1 O O O O O O O O 
0 O O O O O O O O 0 O O O O O O O O 1 O O O O O O O O 
0 O O O O O O O O 0 O O O O O O O O 1 O O O O O O O O 
0 O O O O O O O O 0 O O O O O O O O 1 O O O O O O O O 
0 O O O O O O O O 0 O O O O O O O O 1 O O O O O O O O 
0 O O O O O O O O 0 O O O O O O O O 1 O O O O O O O O 
    0 0 0 0 0 1 0 0  0 0 1 1 0 0 0 0  0 0 0 0 0 0 0 0 

你的靜態組件的僞代碼將是這樣的:

// rotation of a byte 
#define ROR(x, n) (((x >> n) | (x << (8-n))) & 0xff) 
col_selector = 0x80; 
rows_map = {0x00, 0x00, 0x41, 0xFF, 0x01, 0x00, 0x00, 0x00} 
for (col_index = 0; i < col_index; ++col_index) 
{ 
    // 1st - 0x80 --> 0b10000000 --> 1st column from the left 
    // 2nd - 0x40 --> 0b01000000 --> 2nd column from the left 
    choose_cols(ROR(col_selector, col_index)); 
    // 1st - cols_map[0] --> 0x00 --> 0b00000000 --> don't set any row in column 0 
    // 3rd - cols_map[2] --> 0x41 --> 0b01000001 --> set the 2nd and 8th rows in column 2 
    choose_rows(rows_map[col_index]); 
} 

在第二種情況,我們把它換成另一個迴路:

col_selector = 0x80; 
for (i = 0; i < 8; ++i) 
    // 1st time, col_selector is 0x80 
    // 2nd time, col_selector is ROR(0x80, 1) --> 0x40 
    rows_map = {0x00, 0x00, 0x41, 0xFF, 0x01, 0x00, 0x00, 0x00} 
    for (col_index = 0; i < col_index; ++col_index) 
    { 
     // first i iteration: 
     // 1st - 0x80 --> 0b10000000 --> 1st column from the left 
     // 2nd - 0x40 --> 0b01000000 --> 2nd column from the left 
     // second i iteration: 
     // 1st - 0x40 --> 0b01000000 --> 2nd column from the left 
     // 2nd - 0x20 --> 0b00100000 --> 3rd column from the left 
     // 8th - 0x80 --> 0b10000000 --> 1st column from the left 
     choose_cols(rotate col_selector col_index times to the right); 

     // this part is the same in both iterations 
     // 1st - cols_map[0] --> 0x00 --> 0b00000000 --> don't set any row in column 0 
     // 3rd - cols_map[2] --> 0x41 --> 0b01000001 --> set the 2nd and 8th rows in column 2 
     choose_rows(rows_map[col_index]); 
    } 
    col_selector = ROR(col_selector, 1) 
} 
+0

我還有一個問題。在靜態情況下LED如何發光。我的意思是在任何單元格中,如果相應的行和列值等於1,那麼單元格會發光?有這種類型的案件或任何其他邏輯嗎? @MByD – user5404530

+1

@ user5404530 - 如果我回答了您的問題,請將我的答案標記爲已接受,如果您有其他問題,請將其張貼在新帖子中。它使網站更清潔,並幫助其他人使用網站中的Q&A。 – MByD

+0

但問題與帖子有關。如果你回答這個問題,我肯定會接受你的答案:) @MByD – user5404530