You only need to get the bytes if
line[0]=='F'
so you should move it inside theif
block.If you only need to get these 3
Int16
values, IMHO usingArray.Copy
,Array.Reverse
is a little bit too much.while(SerialPort.BytesToRead > 50){ string line = SerialPort.ReadLine(); if (line[0]=='F'){ byte[] encoded = enc.GetBytes(line); short value1 = BitConverter.ToInt16(new byte[] {encoded[2] , encoded [1]}, 0); short value2 = BitConverter.ToInt16(new byte[] {encoded[4] , encoded [3]}, 0); short value3 = BitConverter.ToInt16(new byte[] {encoded[6] , encoded [5]}, 0); } }
naming variables
value1, value2 and value3
screams for new meaningful names and for aList<T>
or any other collection. In this way the shown conversation could be done using a loop.comments like
// read line and turn string in byte array
does not add any value to the code, because the comment is describing what is done instead of why something is done.
A very good read about comments: http://codereview.stackexchange.com/a/90113/29371 https://codereview.stackexchange.com/a/90113/29371
You only need to get the bytes if
line[0]=='F'
so you should move it inside theif
block.If you only need to get these 3
Int16
values, IMHO usingArray.Copy
,Array.Reverse
is a little bit too much.while(SerialPort.BytesToRead > 50){ string line = SerialPort.ReadLine(); if (line[0]=='F'){ byte[] encoded = enc.GetBytes(line); short value1 = BitConverter.ToInt16(new byte[] {encoded[2] , encoded [1]}, 0); short value2 = BitConverter.ToInt16(new byte[] {encoded[4] , encoded [3]}, 0); short value3 = BitConverter.ToInt16(new byte[] {encoded[6] , encoded [5]}, 0); } }
naming variables
value1, value2 and value3
screams for new meaningful names and for aList<T>
or any other collection. In this way the shown conversation could be done using a loop.comments like
// read line and turn string in byte array
does not add any value to the code, because the comment is describing what is done instead of why something is done.
A very good read about comments: http://codereview.stackexchange.com/a/90113/29371
You only need to get the bytes if
line[0]=='F'
so you should move it inside theif
block.If you only need to get these 3
Int16
values, IMHO usingArray.Copy
,Array.Reverse
is a little bit too much.while(SerialPort.BytesToRead > 50){ string line = SerialPort.ReadLine(); if (line[0]=='F'){ byte[] encoded = enc.GetBytes(line); short value1 = BitConverter.ToInt16(new byte[] {encoded[2] , encoded [1]}, 0); short value2 = BitConverter.ToInt16(new byte[] {encoded[4] , encoded [3]}, 0); short value3 = BitConverter.ToInt16(new byte[] {encoded[6] , encoded [5]}, 0); } }
naming variables
value1, value2 and value3
screams for new meaningful names and for aList<T>
or any other collection. In this way the shown conversation could be done using a loop.comments like
// read line and turn string in byte array
does not add any value to the code, because the comment is describing what is done instead of why something is done.
A very good read about comments: https://codereview.stackexchange.com/a/90113/29371
You only need to get the bytes if
line[0]=='F'
so you should move it inside theif
block.If you only need to get these 3
Int16
values, IMHO usingArray.Copy
,Array.Reverse
is a little bit too much.while(SerialPort.BytesToRead > 50){ string line = SerialPort.ReadLine(); if (line[0]=='F'){ byte[] encoded = enc.GetBytes(line); short value1 = BitConverter.ToInt16(new byte[] {encoded[2] , encoded [1]}, 0); short value2 = BitConverter.ToInt16(new byte[] {encoded[4] , encoded [3]}, 0); short value3 = BitConverter.ToInt16(new byte[] {encoded[6] , encoded [5]}, 0); } }
naming variables
value1, value2 and value3
screemsscreams for new meaningful names and for aList<T>
or any other collection. In this way the shown conversation could be done using a loop.comments like
// read line and turn string in byte array
does not add any value to the code, because the comment is describing what is done instead of why something is done.
A very good read about comments: http://codereview.stackexchange.com/a/90113/29371
You only need to get the bytes if
line[0]=='F'
so you should move it inside theif
block.If you only need to get these 3
Int16
values, IMHO usingArray.Copy
,Array.Reverse
is a little bit too much.while(SerialPort.BytesToRead > 50){ string line = SerialPort.ReadLine(); if (line[0]=='F'){ byte[] encoded = enc.GetBytes(line); short value1 = BitConverter.ToInt16(new byte[] {encoded[2] , encoded [1]}, 0); short value2 = BitConverter.ToInt16(new byte[] {encoded[4] , encoded [3]}, 0); short value3 = BitConverter.ToInt16(new byte[] {encoded[6] , encoded [5]}, 0); } }
naming variables
value1, value2 and value3
screems for new meaningful names and for aList<T>
or any other collection. In this way the shown conversation could be done using a loop.comments like
// read line and turn string in byte array
does not add any value to the code, because the comment is describing what is done instead of why something is done.
A very good read about comments: http://codereview.stackexchange.com/a/90113/29371
You only need to get the bytes if
line[0]=='F'
so you should move it inside theif
block.If you only need to get these 3
Int16
values, IMHO usingArray.Copy
,Array.Reverse
is a little bit too much.while(SerialPort.BytesToRead > 50){ string line = SerialPort.ReadLine(); if (line[0]=='F'){ byte[] encoded = enc.GetBytes(line); short value1 = BitConverter.ToInt16(new byte[] {encoded[2] , encoded [1]}, 0); short value2 = BitConverter.ToInt16(new byte[] {encoded[4] , encoded [3]}, 0); short value3 = BitConverter.ToInt16(new byte[] {encoded[6] , encoded [5]}, 0); } }
naming variables
value1, value2 and value3
screams for new meaningful names and for aList<T>
or any other collection. In this way the shown conversation could be done using a loop.comments like
// read line and turn string in byte array
does not add any value to the code, because the comment is describing what is done instead of why something is done.
A very good read about comments: http://codereview.stackexchange.com/a/90113/29371
You only need to get the bytes if
line[0]=='F'
so you should move it inside theif
block.If you only need to get these 3
Int16
values, IMHO usingArray.Copy
,Array.Reverse
is a little bit too much.while(SerialPort.BytesToRead > 50){ string line = SerialPort.ReadLine(); if (line[0]=='F'){ byte[] encoded = enc.GetBytes(line); short value1 = BitConverter.ToInt16(new byte[] {encoded[2] }, encoded [1]}, 0); short value2 = BitConverter.ToInt16(new byte[] {encoded[4] }, encoded [3]}, 0); short value3 = BitConverter.ToInt16(new byte[] {encoded[6] }, encoded [5]}, 0); } }
naming variables
value1, value2 and value3
screems for new meaningful names and for aList<T>
or any other collection. In this way the shown conversation could be done using a loop.comments like
// read line and turn string in byte array
does not add any value to the code, because the comment is describing what is done instead of why something is done.
A very good read about comments: http://codereview.stackexchange.com/a/90113/29371
You only need to get the bytes if
line[0]=='F'
so you should move it inside theif
block.If you only need to get these 3
Int16
values, IMHO usingArray.Copy
,Array.Reverse
is a little bit too much.while(SerialPort.BytesToRead > 50){ string line = SerialPort.ReadLine(); if (line[0]=='F'){ byte[] encoded = enc.GetBytes(line); short value1 = BitConverter.ToInt16(new byte[] {encoded[2] }, encoded [1], 0); short value2 = BitConverter.ToInt16(new byte[] {encoded[4] }, encoded [3], 0); short value3 = BitConverter.ToInt16(new byte[] {encoded[6] }, encoded [5], 0); } }
naming variables
value1, value2 and value3
screems for new meaningful names and for aList<T>
or any other collection. In this way the shown conversation could be done using a loop.comments like
// read line and turn string in byte array
does not add any value to the code, because the comment is describing what is done instead of why something is done.
A very good read about comments: http://codereview.stackexchange.com/a/90113/29371
You only need to get the bytes if
line[0]=='F'
so you should move it inside theif
block.If you only need to get these 3
Int16
values, IMHO usingArray.Copy
,Array.Reverse
is a little bit too much.while(SerialPort.BytesToRead > 50){ string line = SerialPort.ReadLine(); if (line[0]=='F'){ byte[] encoded = enc.GetBytes(line); short value1 = BitConverter.ToInt16(new byte[] {encoded[2] , encoded [1]}, 0); short value2 = BitConverter.ToInt16(new byte[] {encoded[4] , encoded [3]}, 0); short value3 = BitConverter.ToInt16(new byte[] {encoded[6] , encoded [5]}, 0); } }
naming variables
value1, value2 and value3
screems for new meaningful names and for aList<T>
or any other collection. In this way the shown conversation could be done using a loop.comments like
// read line and turn string in byte array
does not add any value to the code, because the comment is describing what is done instead of why something is done.
A very good read about comments: http://codereview.stackexchange.com/a/90113/29371