我试图让服务器能够接收客户端字节并将其用作整数,我该怎么做?这是我要修复的代码~唯一的错误是它无法将字节处理为 int ......请帮助我
try
{
byte[] received = new byte[1024];
mStream.Read(received, 0, received.Length);
updateUI("Received: " + Encoding.ASCII.GetString(received));
int Cir;
Cir = received;
switch (Cir)
{
case 1 :
serialPort1.PortName = "COM5";
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.Parity = System.IO.Ports.Parity.None;
serialPort1.StopBits = System.IO.Ports.StopBits.One;
serialPort1.Open();
serialPort1.Write("a");
serialPort1.Close();
break;
case 2:
serialPort1.PortName = "COM5";
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.Parity = System.IO.Ports.Parity.None;
serialPort1.StopBits = System.IO.Ports.StopBits.One;
serialPort1.Open();
serialPort1.Write("a");
serialPort1.Close();
break;
}