Basic connectivity
Today I have been working on a GHI Electronics TinyCLR V2 C# library for the Seeedstudio LoRa-E5 module using my Seeedstudio LoRa-E5 Development Kit.
My initial test rig is based on an Fezduino board with a Grove Base Shield V2.0 connected to
LoRa-E5 Development Kit by a Grove – Universal 4 Pin 20cm Unbuckled Cable(TX/RX reversed)
The code has compile time options for synchronous and asynchronous operation.
public class Program
{
private static UartController serialDevice;
private const string ATCommand = "at+ver\r\n";
#if TINYCLR_V2_FEZDUINO
private static readonly string SerialPortId = SC20100.UartPort.Uart5;
#endif
#if TINYCLR_V2_SC20100DEV_MIKROBUS_1
private const string SerialPortId = SC20100.UartPort.Usart2;
#endif
#if TINYCLR_V2_SC20100DEV_MIKROBUS_2
private const string SerialPortId = SC20100.UartPort.Uart3;
#endif
public static void Main()
{
Debug.WriteLine("devMobile.IoT.SeeedE5.ShieldSerial starting");
try
{
serialDevice = UartController.FromName(SerialPortId);
serialDevice.SetActiveSettings(new UartSetting()
{
BaudRate = 9600,
Parity = UartParity.None,
StopBits = UartStopBitCount.One,
Handshaking = UartHandshake.None,
DataBits = 8
});
serialDevice.Enable();
#if SERIAL_ASYNC_READ
serialDevice.DataReceived += SerialDevice_DataReceived;
#endif
while (true)
{
byte[] txBuffer = UTF8Encoding.UTF8.GetBytes(ATCommand);
int txByteCount = serialDevice.Write(txBuffer);
Debug.WriteLine($"TX: {txByteCount} bytes");
#if SERIAL_SYNC_READ
while( serialDevice.BytesToWrite>0)
{
Debug.WriteLine($" BytesToWrite {serialDevice.BytesToWrite}");
Thread.Sleep(100);
}
int rxByteCount = serialDevice.BytesToRead;
if (rxByteCount>0)
{
byte[] rxBuffer = new byte[rxByteCount];
serialDevice.Read(rxBuffer);
Debug.WriteLine($"RX sync:{rxByteCount} bytes read");
String response = UTF8Encoding.UTF8.GetString(rxBuffer);
Debug.WriteLine($"RX sync:{response}");
}
#endif
Thread.Sleep(20000);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
#if SERIAL_ASYNC_READ
private static void SerialDevice_DataReceived(UartController sender, DataReceivedEventArgs e)
{
byte[] rxBuffer = new byte[e.Count];
sender.Read(rxBuffer, 0, e.Count);
Debug.WriteLine($"RX Async:{e.Count} bytes read");
String response = UTF8Encoding.UTF8.GetString(rxBuffer);
Debug.WriteLine($"RX Async:{response}");
}
#endif
}
When I first ran the code no data was received so I doubled checked the serial connections and figured out I had to modify the cable and reverse the TX and RX pins.
The thread '<No Name>' (0x2) has exited with code 0 (0x0).
devMobile.IoT.SeeedLoRaE5.ShieldSerial starting
TX: 8 bytes
RX Async:1 bytes read
RX Async:+
RX Async:8 bytes read
RX Async:VER: 4.0
RX Async:5 bytes read
RX Async:.11
TX: 8 bytes
RX Async:1 bytes read
RX Async:+
RX Async:9 bytes read
RX Async:VER: 4.0.
RX Async:4 bytes read
RX Async:11