16 진수 값을 10 진수 값으로 변환하는 수신기 소프트웨어를 만들려고합니다. 이건 내 코드입니다 :HexString에서 Decimal로 변환 오류 : 인덱스가 범위를 벗어났습니다. 음수가 아니어야하며 콜렉션의 크기보다 작아야합니다. 매개 변수 이름 : startIndex
// Obtain the number of bytes waiting in the port's buffer
int bytes = comport.BytesToRead;
// Create a byte array buffer to hold the incoming data
byte[] buffer = new byte[bytes];
// Read the data from the port and store it in our buffer
comport.Read(buffer, 0, bytes);
string hexValues = ByteArrayToHexString(buffer);
string[] hexValuesSplit = hexValues.Split(' ');
foreach (String hex in hexValuesSplit)
{
// Convert the number expressed in base-16 to an integer.
int value = Convert.ToInt32(hex, 16);
Log(LogMsgType.Incoming, value+" ppm \n");
}
하지만 그것은 항상 인덱스가 범위를 벗어났습니다 "라고 시리얼 데이터를 보내려고 할 때 컬렉션의 크기보다 음이 아닌 및 작아야합니다 매개 변수 이름 :.. 시작 인덱스 ". 그래서 내가 뭘하는거야?
어떤 라인에서 오류가 발생합니까? –
나는 당신이 제공하지 않은'ByteArrayToHexString'에 있다고 생각합니다 : ( –