我正在尝试创建一个名为" test.txt"的文件。在名为" test"的文件夹中在当前目录中并向其中添加一些文本行。
我在程序中使用此代码段但是获得了file is already in use by another process
的异常。这部分有什么问题吗?
File.Create(FileName);
string fullPathName2 = Path.GetFullPath(FileName);
File.AppendAllText(fullPathName2, time + Environment.NewLine);
答案 0 :(得分: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
)
E.g。
迭代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)
}