1

I am assigned to write a C# WPF application to connect to a Google Coral Development Board through the Debug Port and Stream all the data that the Board outputs to a Windows Screen (e.g. TextBlock).

I follow this Microsoft referemce for the reading events. For now, after I establish the connection to the board, I see the outputs in my Textblock but it is not in the readable text format.

What I expected:

U-Boot SPL 2019.04.1 (Jan 11 2021 - 20:43:00 +0000)
power_bd71837_init
Board id: 0
DDRINFO: start DRAM init
DDRINFO:ddrphy calibration done
DDRINFO: ddrmix config done
Normal Boot
Trying to boot from MMC1
hdr read sector 300, count=1


U-Boot 2019.04.1 (Jan 11 2021 - 20:43:00 +0000), Build: jenkins-enterprise.uboot                                                                                                                                                             -imx-1

CPU:   Freescale i.MX8MQ rev2.1 1500 MHz (running at 1000 MHz)
CPU:   Commercial temperature grade (0C to 95C) at 37C
Reset cause: POR
Model: Freescale i.MX8MQ Phanbell
DRAM:  4 GiB
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... *** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial

 BuildInfo:
  - ATF
  - U-Boot 2019.04.1

flash target is MMC:0
Net:
Warning: ethernet@30be0000 using MAC address from ROM
eth0: ethernet@30be0000
Fastboot: Normal
Normal Boot
Hit any key to stop autoboot:  0
2065 bytes read in 6 ms (335.9 KiB/s)

What I actually see from the TextBlock: enter image description here

I check the BaudRate and other settings, nothing seems to be incorrect. I know that UART protocol sends data as byte, can someone spot if my output if wrong data type? If so, do I have to read receiving byte and convert to readable text?

Adding My Code

//Port setting
_serialPort.PortName = comPort.Name;
_serialPort.BaudRate = 115200;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;         
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;

_serialPort.DtrEnable = true;
_serialPort.RtsEnable = true;

// Port Data Receiving method
_serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
_serialPort.Open();

private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender;
            string indata = sp.ReadExisting();
            this.Dispatcher.Invoke(() =>
            {
                TextBlock_Output.Text += indata; 
            });
        };

Hardware Connection I connect the Debug Port of the Google Coral Board to my Windows Computer through a micro-USB(Coral Board) to USB(Windows Computer). I normally use this connection for debugging through COM Port via Putty as well.

Thank you!

J...
  • 30,968
  • 6
  • 66
  • 143
  • Try setting both `mySerialPort.RtsEnable=true;` and `mySerialPort.DtrEnable=true;` The following may be helpful: https://stackoverflow.com/questions/65957066/serial-to-usb-cable-from-a-scale-to-pc-some-values-are-just-question-marks/65971845#65971845 – Tu deschizi eu inchid Jul 21 '21 at 20:48
  • Here are some more URLs that may be helpful: https://coral.ai/docs/dev-board/serial-console/#connect-with-windows and https://coral.ai/docs/dev-board/get-started/#requirements. – Tu deschizi eu inchid Jul 21 '21 at 21:13
  • @user9938 Adding these settings does not seem to solve the problem. I looked into the post and could not find the solution. – Tony Nguyen Jul 22 '21 at 14:21
  • @J... Normally, I putty through COM Port (BaudRate: 115200) for debugging. I added into the post my COM port settings. Is there any way for me to check if this is a hardware issue rather than software issue? – Tony Nguyen Jul 22 '21 at 14:23
  • @J... Yes. I also verified that it works with RealTerm (i.e. Baud: 115200, Parity: None, Data Bits: 8 bits, Stop bits: 1 bit, Hardware Flow Control: None) – Tony Nguyen Jul 22 '21 at 15:41
  • @J... Yes, I have not modified the ```_serialPort.Encoding``` property. I am finding this post relevant to my issue: https://stackoverflow.com/questions/18698292/reading-from-serial-port-affecting-values – Tony Nguyen Jul 22 '21 at 15:45
  • Did you install the driver as described in one of the URLs I posted? – Tu deschizi eu inchid Jul 22 '21 at 16:22
  • I think you should write a minimal application--perhaps even a console app, to prove if it is the SerialPort class or not. Are you sure you're not setting the baud rate somewhere else in your code, too, or something like that? If another application can successfully read the data, then there's no reason SerialPort can't. – Jonathon Reinhart Jul 23 '21 at 01:24

1 Answers1

0

From the documentation, on all platforms they indicate using a terminal emulator like screen (linux/MacOS) or PuTTy (windows).

A terminal emulator is more than simply a text box and the data stream will be more than simply readable ANSI characters. In addition to the text, the data stream will also include a variety of control characters, or escape sequences, that are used to indicate how to lay out and render the text-based UI to the user in a remote terminal window. You cannot use a plain serial port class to reproduce this behaviour - you require a fully featured terminal emulator. As a sender, you must also produce the correct control character outputs to be able to move the cursor in the terminal window, to send copy/paste/cancel or other commands, and perform other user interaction with the remote screen.

A number of libraries exist that provide this functionality for C#, but recommending one is out of scope for answers here. You could also write your own terminal emulator, of course, processing the VT100 control sequences yourself, but this would be a considerable exercise. In any case, the data coming into the serial port needs to be parsed and interpreted before you can render the text to the screen. Simply printing the incoming characters to a text box will not work.

J...
  • 30,968
  • 6
  • 66
  • 143
  • Yeah, but ASCII characters should still show up as ASCII characters. I don't think this is the OP's problem. – Jonathon Reinhart Jul 23 '21 at 01:04
  • @JonathonReinhart If not that, then maybe this is one of those cases where the .net serial port class is [simply broken](https://www.sparxeng.com/blog/software/must-use-net-system-io-ports-serialport). Some UARTs at some baud rates I've seen return garbage like this in the DataReceived event. It's a flaw in the framework and you just have to workaround in those cases. OP's code otherwise seems fine. Just as well to use a terminal emulator library anyway. – J... Jul 23 '21 at 01:13
  • I've certainly had my fair share of `SerialPort` troubles, but I've never had trouble simply receiving some kind of valid data like this. It *looks* like a baud rate issue. – Jonathon Reinhart Jul 23 '21 at 01:23
  • @JonathonReinhart OP claims to have eliminated that. – J... Jul 23 '21 at 01:25