I believe that this is a straightforward question, but after researching the error code in various places, it makes little sense to me.
What I am trying to achieve:
What is happening:
The statement below is generating the error, "CS0443: Syntax error, value expected" The error is located inside the pointer brackets of serPortXmitBuffer object of the "Write" statement.
mySerialPort.Write (serPortXmitBuffer[], 0, serPortXmitBuffer.Count-1); mySerialPort.Write (serPortXmitBuffer[error here], 0, serPortXmitBuffer.Count-1);
The "Write" statement is being passed a valid name in serPointXmitBuffer and I have checked that the array is there and correct. For the life of me, I have no idea why this code snippet is generating an error for a value??? The contents of the array are 11 bytes as follows: 255, 255, 2 65, 73, 77, 16, 2 0, 0, 3
What I have tried:
For completeness, the code that generates the array is shown below:
int incArrPnter;
Console.WriteLine("Writing passed in xmitBuffer within TXPACK routine");
for (incArrPnter = 0; incArrPnter <= _array.Count-1; incArrPnter = incArrPnter + 1)
{
Console.WriteLine(_array[incArrPnter]);
}
// Declare our new List<byte> array, serPortXmitBuffer
// Copy all bytes in "_array" over to serPortXmitBuffer
List<byte> serPortXmitBuffer = new List<byte>();
// Copy "_array" over to serPortXmitBuffer
for (incArrPnter = 0; incArrPnter <= _array.Count - 1; incArrPnter = incArrPnter + 1)
{
serPortXmitBuffer.Add(_array[incArrPnter]);
}
// Try to write the contents of serPortXmitBuffer to the serial port.
mySerialPort.Write (serPortXmitBuffer[0], 0, serPortXmitBuffer.Count-1);
A couple of things that I learned that are not necessarily obvious to me (maybe others might not be aware so I am posting this answer:
List as a structure is NOT supported by the "Write" method when trying to send bytes out a serial port. It must be a traditional array of bytes like myArray[]
So far, I have found no way to allow "myArray.Count-1" to be a valid element within the Write statement to represent the total number of bytes to be transmitted. It must be either a number (int) or a variable that is an int.
I would love to be wrong on the second point, but so far, nothing I have read or seen allows me to pass "myArray.Count" or "myArray.Count - 1" as neither of these expressions resolves to an int.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.