FEZ Spider: Read UART without USB Connection

Hello,

I have a problem with the display of measurements, which I get through UART.
When my Spider motherboard is connected to the laptop via USB, the current value is shown on the display.
Now if you take the USB connection and connects an external power supply to the DP module, I no longer see value on display.
I tried different Code.

I’ve even programmed a small sample for testing. The Dips on Spider Mainboard are all off. I tried it on Serial Debug. Its the same. Any Idea?


using System;
using System.Collections;
using System.Threading;
using System.IO.Ports;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp10
{
    public partial class Program
    {
        Text text;
        Canvas layout;
        Window window;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            SetupUI();
            Debug.Print("Program Started");

            GT.Socket socket = GT.Socket.GetSocket(4, true, null, null);
            GT.Interfaces.Serial serial = new GT.Interfaces.Serial(socket, 115200, 
                                                                    GT.Interfaces.Serial.SerialParity.None, 
                                                                    GT.Interfaces.Serial.SerialStopBits.One, 
                                                                    8, 
                                                                    GT.Interfaces.Serial.HardwareFlowControl.NotRequired, 
                                                                    null);
            serial.Open();

            serial.DataReceived += new GT.Interfaces.Serial.DataReceivedEventHandler(serial_DataReceived);

        }
        void SetupUI()
        {
            window = display.WPFWindow;
            layout = new Canvas();

            text = new Text("0");
            text.Height = 50;
            text.Width = 250;
            text.ForeColor = Colors.Black;
            text.Font = Resources.GetFont(Resources.FontResources.NinaB);
            text.Visibility = Visibility.Visible;
            layout.Children.Add(text);
            Canvas.SetLeft(text, 40);
            Canvas.SetTop(text, 40);

            window.Child = layout;
        }
        void serial_DataReceived(GT.Interfaces.Serial sender, SerialData data)
        {
            byte[] buffer = new byte[sender.BytesToRead];
            sender.Read(buffer, 0, buffer.Length);
            string output_t = bytesToString(buffer);
            text.TextContent = output_t;
            Debug.Print(output_t);
            buffer = null;
            output_t = null;
        }

        public static string bytesToString(byte[] bytes)
        {
            string s = "";
            for (int i = 0; i < bytes.Length; ++i)
                s += (char)bytes[i];
            return s;
        }
    }
}

Did you try different UART socket on the main board? Is the behavior the same?

Yes i tried all 4 sockets, I use just the socket 11 with serial Debug.

If you have a test string instead of the value output in the label, then you get an advertisement, otherwise it will disappear.
The interface is thus at least queried once before.

Very strange.


void serial_DataReceived(GT.Interfaces.Serial sender, SerialData data)
        {
            byte[] buffer = new byte[sender.BytesToRead];
            sender.Read(buffer, 0, buffer.Length);
            sender.DiscardInBuffer();
            sender.Flush();
            string output_t = bytesToString(buffer);
            //text.TextContent = output_t;
            text.TextContent = "test";
            Debug.Print(output_t);
            buffer = null;
            output_t = null;
        }

After setting the text can you call invalidate?

He is already valid, but the buffer is not described in more if I now understand correctly. Therefore, the text disappears. But I do not know why suddenly no more data can be read. I close it back into the laptop, it works again.

What Dip positions on Spider Mainboard is correct to work without USB connection to my laptop and with serial input (UART) ?

@ clamb - The dip switches should be in the default position, if you are only using UART to communicate. The dip switches should only be changed if you need serial debugging.

I do not know why, but it works now. Thank you.
The dip switches were the first attempt also to default, but I have not been flush on the serial interface. Thats the thing i have added later.

Thank you very much.