/// <summary> /// The message header includes the datalength, which allows the message to span /// more than one HID report. Useful for long UART/SPI transfers /// </summary> private void msgSend(section s, byte instruction, byte[] data) { HU320_USB_msg M = new HU320_USB_msg(); M.sect = s; M.instruction = instruction; M.flags = 0x0000; M.data = data; byte[] b = M.flatten(); usbI.write(b); }
/// <summary> /// This method handles events from the USB interface class, this will split into more events for UART SPI etc /// If the message is not an async read, the eventWaitHandle (waitReply) will be signalled, otherwise and event will be triggered /// </summary> /// <param name="message"></param> private void usbI_dataReceived(byte[] message) { //message[0] = always 0 for a HID report RX_msg = new HU320_USB_msg(message); //If the message is an async read message, store the data - and optionally trigger the correct event if ((RX_msg.sect == section.UART) && (RX_msg.instruction == (byte)UART_Instr.asyncReceive) && UART_enabled) { //store the data int oldBufferLength = UART_RXbuffer.Length; Array.Resize(ref UART_RXbuffer, UART_RXbuffer.Length + RX_msg.data.Length); Array.Copy(RX_msg.data, 0, UART_RXbuffer, oldBufferLength, RX_msg.data.Length); this.UART_bytesToRead = UART_RXbuffer.Length; if ((UART_dataReceived != null) && (UART_RXbuffer.Length >= UART_rxBytesThreshold)) { UART_dataReceived(this); } } else if ((RX_msg.sect == section.SPI_Ext) && (RX_msg.instruction == (byte)SPI_instr.asyncReply) && SPI_enabled) { //store the data int oldBufferLength = SPI_RXbuffer.Length; Array.Resize(ref SPI_RXbuffer, SPI_RXbuffer.Length + RX_msg.data.Length); Array.Copy(RX_msg.data, 0, SPI_RXbuffer, oldBufferLength, RX_msg.data.Length); this.SPI_bytesToRead = SPI_RXbuffer.Length; if ((SPI_dataReceived != null) && (SPI_RXbuffer.Length >= SPI_rxBytesThreshold)) { SPI_dataReceived(this); } } //else if ((RX_msg.sect == section.I2C) && (RX_msg.instruction == (byte)I2C_instr.asyncReply) && (I2C_dataReceived != null) && (I2C_RXbuffer.Length >= I2C_rxBytesThreshold)) //I2C_dataReceived(this); else //The message is a normal reply { waitReply.Set(); } }
/// <summary> /// This method handles events from the USB interface class, this will split into more events for UART SPI etc /// If the message is not an async read, the eventWaitHandle (waitReply) will be signalled, otherwise and event will be triggered /// </summary> /// <param name="message"></param> private void usbI_dataReceived(byte[] message) { //message[0] = always 0 for a HID report RX_msg = new HU320_USB_msg(message); //If the message is an async read message, store the data - and optionally trigger the correct event if ((RX_msg.sect == section.UART) && (RX_msg.instruction == (byte)UART_Instr.asyncReceive) && UART_enabled) { //store the data int oldBufferLength = UART_RXbuffer.Length; Array.Resize(ref UART_RXbuffer, UART_RXbuffer.Length + RX_msg.data.Length); Array.Copy(RX_msg.data, 0, UART_RXbuffer, oldBufferLength, RX_msg.data.Length); this.UART_bytesToRead = UART_RXbuffer.Length; if ((UART_dataReceived != null) && (UART_RXbuffer.Length >= UART_rxBytesThreshold)) UART_dataReceived(this); } else if ((RX_msg.sect == section.SPI_Ext) && (RX_msg.instruction == (byte)SPI_instr.asyncReply) && SPI_enabled) { //store the data int oldBufferLength = SPI_RXbuffer.Length; Array.Resize(ref SPI_RXbuffer, SPI_RXbuffer.Length + RX_msg.data.Length); Array.Copy(RX_msg.data, 0, SPI_RXbuffer, oldBufferLength, RX_msg.data.Length); this.SPI_bytesToRead = SPI_RXbuffer.Length; if ((SPI_dataReceived != null) && (SPI_RXbuffer.Length >= SPI_rxBytesThreshold)) SPI_dataReceived(this); } //else if ((RX_msg.sect == section.I2C) && (RX_msg.instruction == (byte)I2C_instr.asyncReply) && (I2C_dataReceived != null) && (I2C_RXbuffer.Length >= I2C_rxBytesThreshold)) //I2C_dataReceived(this); else //The message is a normal reply waitReply.Set(); }