主题:C#问题请教
byte i = 0;
byte[] Data1 = new byte[8];
Data1[1] = 0x78;
switch (i)
{
case 0x20:
Data1[3] = 0x20;
break;
case 0x21:
Data1[3] = 0x21;
break;
case 0x22:
Data1[3] = 0x22;
break;
case 0x23:
Data1[3] = 0x23;
break;
case 0x24:
Data1[3] = 0x24;
break;
case 0x25:
Data1[3] = 0x25;
break;
case 0x26:
Data1[3] = 0x26;
break;
case 0x27:
Data1[3] = 0x27;
break;
case 0x28:
Data1[3] = 0x28;
break;
case 0x29:
Data1[3] = 0x29;
break;
case 0x30:
Data1[3] = 0x30;
break;
}
serialPort1.Write(Data1, 0, 8);
serialPort1.Read(Data1, 0, 8);
byte[] data1 = new byte[25];
string str = " ";
switch (Data1[3])
{
case 0x20:
str = "1";
str += "1";
break;
case 0x21:
str = "2";
str += "2";
break;
case 0x22:
str = "3";
str += "3";
break;
case 0x23:
str = "4";
str += "4";
break;
case 0x24:
str = "5";
str += "5";
break;
case 0x25:
str = "6";
str += "6";
break;
case 0x26:
str = "7";
str += "7";
break;
case 0x27:
str = "8";
str += "8";
break;
case 0x28:
str = "9";
str += "9";
break;
case 0x29:
str = "0";
str += "0";
break;
case 0x30:
str = ".";
str += ".";
break;
}
data1[0] = 0xAA;
data1[1] = 0x54;
data1[2] = 0x00;
data1[3] = 0x59;
data1[4] = 0x00;
data1[5] = 0x30;
for (int a = 6; a <8; a++)
{
data1[a] = System.Convert.ToByte(str[a - 6]);
}
data1[21] = 0xCC;
data1[22] = 0x33;
data1[23] = 0xC3;
data1[24] = 0x3C;
if (Data1[3] == 0x20&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x21&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x22&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x23&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x24&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x25&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x26&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x27&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x28&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x29&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x30&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
我是刚学习C#的,我想让两位的数字一个一个显示,而不是一次性显示出来,请问有什么方法吗?请各位指教
byte[] Data1 = new byte[8];
Data1[1] = 0x78;
switch (i)
{
case 0x20:
Data1[3] = 0x20;
break;
case 0x21:
Data1[3] = 0x21;
break;
case 0x22:
Data1[3] = 0x22;
break;
case 0x23:
Data1[3] = 0x23;
break;
case 0x24:
Data1[3] = 0x24;
break;
case 0x25:
Data1[3] = 0x25;
break;
case 0x26:
Data1[3] = 0x26;
break;
case 0x27:
Data1[3] = 0x27;
break;
case 0x28:
Data1[3] = 0x28;
break;
case 0x29:
Data1[3] = 0x29;
break;
case 0x30:
Data1[3] = 0x30;
break;
}
serialPort1.Write(Data1, 0, 8);
serialPort1.Read(Data1, 0, 8);
byte[] data1 = new byte[25];
string str = " ";
switch (Data1[3])
{
case 0x20:
str = "1";
str += "1";
break;
case 0x21:
str = "2";
str += "2";
break;
case 0x22:
str = "3";
str += "3";
break;
case 0x23:
str = "4";
str += "4";
break;
case 0x24:
str = "5";
str += "5";
break;
case 0x25:
str = "6";
str += "6";
break;
case 0x26:
str = "7";
str += "7";
break;
case 0x27:
str = "8";
str += "8";
break;
case 0x28:
str = "9";
str += "9";
break;
case 0x29:
str = "0";
str += "0";
break;
case 0x30:
str = ".";
str += ".";
break;
}
data1[0] = 0xAA;
data1[1] = 0x54;
data1[2] = 0x00;
data1[3] = 0x59;
data1[4] = 0x00;
data1[5] = 0x30;
for (int a = 6; a <8; a++)
{
data1[a] = System.Convert.ToByte(str[a - 6]);
}
data1[21] = 0xCC;
data1[22] = 0x33;
data1[23] = 0xC3;
data1[24] = 0x3C;
if (Data1[3] == 0x20&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x21&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x22&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x23&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x24&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x25&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x26&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x27&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x28&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x29&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
if (Data1[3] == 0x30&& Data1[1] == 0x78 && Data1.Length == 8)
serialPort1.Write(data1, 0, 25);
我是刚学习C#的,我想让两位的数字一个一个显示,而不是一次性显示出来,请问有什么方法吗?请各位指教