The print using console is correct(0xA0),
but the value write to .bin file is not correct(0xD0 0xB5).
What are you saying? The console shows one byte but you
claim the file has two bytes?
When input: 0xA0~0xB6, it's ok.
When input is 0xA5, 0xA5, 0x00, 0x33~0x3A, 0xA5, 0xA5...
value more than 0x7F is wrong again
You say 0xB6 is OK, yet you claim that values more
than 0x7F are wrong. But 0xB6 is greater than 0x7F.
You're not providing enough information re what you are
doing and how you are doing it.
Since the Console.WriteLine is displaying characters as
decimal values, how are you arriving at the hex values
you are describing?
How are you checking the contents of the output file?
What tool are you using?
As an aside, I trust you know that the code you have
won't automatically create a subdir named "log". If
one doesn't exist you will get a run time exception.
Build and run this code.
static void Main(string[] args)
{
FileStream fs_btfwlogging;
BinaryWriter bw_btfwlogging;
/* create a file to store BT FW log*/
DateTime dt = DateTime.Now;
string filepath = Directory.GetCurrentDirectory() + "\\log\\"
+ string.Format("BT_FW_{0}_{1:D2}_{2:D2}_{3:D2}{4:D2}{5:D2}.bin",
dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
using (fs_btfwlogging = new FileStream(filepath, FileMode.Create))
{
bw_btfwlogging = new BinaryWriter(fs_btfwlogging);
//byte[] BTFWCorrectlogArr = BTFWlogCollect.ToArray();
byte[] BTFWCorrectlogArr =
{ 0x0A, 0x0D, 0xA0, 0xD0, 0x7F, 0x8F, 0xF7, 0xFF };
for (int i = 0; i < BTFWCorrectlogArr.Length; i++)
{
//Console.WriteLine("{0}", BTFWCorrectlogArr[i]);
Console.WriteLine("{0:X2}", BTFWCorrectlogArr[i]);
bw_btfwlogging.Write(BTFWCorrectlogArr[i]);
}
}
}
The console should show:
0A
0D
A0
D0
7F
8F
F7
FF
The file will contain this when viewed using a hex
viewer/editor:
If your results differ you must be doing something wrong
outside of the code itself.
- Wayne