EasyManua.ls Logo

Alkeria NECTA Series - Page 67

Default Icon
140 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
4. Interfacing to the world 66
Example Code 4.18 | Serial interface output conguration
device.PIOPorts[0].Source = OutputSource.UARTTx; // Uart Tx on Port 0
device.PIOPorts[0].Direction = IODirection.Output; // Port 0 output direction
device.UART.BaudRate = 38400; // 38400 bps
byte[] b = new byte[16]; // Data to send
device.UART.Send(b); // Send byte to Tx pin
In case you want to send a message whose size in bytes is greater than the output FIFO size, you should
mind that the Send method is blocking, i.e. it waits until the last byte of the message has found its place
in the output FIFO. To be sure that the Send method will not pause your application ow, you should
always send a number of bytes lower than UART.TxFIFOSize and wait until the output FIFO is empty
before calling the Send method.
Example Code 4.19 | Big buer send over serial interface
int bytesToSend = bigBuffer.Length; // Remaining bytes to send
int srcIndex = 0; // Index to the next byte to send
uint txFifoSize = device.UART.TxFIFOSize; // This is the size of output FIFO
while (bytesToSend > 0) // While we have bytes to send
{
// Allocate a temp buffer.
byte[] buffer = new byte[Math.Min(bytesToSend, txFifoSize)];
// Copy the data to send from the big buffer.
Array.Copy(bigBuffer, srcIndex, buffer, 0, buffer.Length);
// Wait for the output fifo to be empty.
while (!device.UART.TxFIFOEmpty)
Thread.Sleep(500); // Leave CPU time to other user threads
// Send the buffer
device.UART.Send(buffer);
// Update indexes and counters
srcIndex += buffer.Length;
bytesToSend -= buffer.Length;
}
Example Code 4.20 | Serial interface input conguration
device.UART.Reset(); // Input FIFO Reset
device.UART.InputPort = 1; // Uart RX on Port 1
uint rxFIFOLevel = device.UART.RxFIFOLevel; // How many bytes have been received
if (rxFIFOLevel > 0)
{
// Check if there has been an overrun error
if (device.UART.Overrun)
Debug.WriteLine("Input FIFO overrun detected");
// Extract the received bytes
byte[] data = device.UART.Read(rxFIFOLevel);
}

Table of Contents