I will be working on a project that will be interfacing a Netduino 3 WIFI with an 8051F340, a TTL camera, and a PC via USB to serial adapter. I’ve worked on a few small projects in C# but this will be a much larger undertaking as I will exploring new concepts that I have only novice experience with. I’ve been studying the code given on the Netduino page for UART and will be testing the code. I’d like to get a better understanding of how I can change the code for my purposes. The gist of the projects is that the Netduino I will receive and transfer data bytes via 3 of the com ports. The information will arrive asynchronously and will send in the same manner. Most data will be no more than 5bytes, but the JPG coming back from the camera may be bigger. I understand that the buffer needs to be large enough to handle whatever data is received. The data to and from the 8051 will contain 9 data bits a start and stop bit. I want the event handler to initiate every time data is received, move the data a container object, compare that first byte to a table of if-then statements, then call and method or procedure that will initiate a transmission of data. My first questions are…
I see that a byte array is being use to catch the received data. What container might I use to catch the 9 data bits from the 8051 that would still allow for an array of three or four 9 bit packages? I’m hoping I can use 9 bit UART with the 8051 because less coding on that end.
transmitter.Write(Encoding.UTF8.GetBytes(messageToSend), 0, messageToSend.Length);
Similarly, I see this line seems to initial the transmission. It also seems to encapsulate only 8 bits. How might I initiate transmission with 9 bits?
Also I figure it would be easier to compare the first byte using if-then statements to choose how it want to respond. It there a better way to do this, and are methods the best way to initiate a transmission reply?
Lastly I’m concerned about data collision or loss in the buffer when multiple ports write to the Netduino at once. Would multi-threading help to avoid this?