Use the CDC test app

… visits
Parent Previous Next

Use this Windows app to check a CDC serial connection and then build your own simple control panel. Start with the matching CDC example in Framework so that the PIC and PC agree on the commands.


The source is in CDC Data > PC Host App. Open CDC_Data_VS_WPF.sln. If you have not built a WPF app before, follow Build the Windows test apps first.


Build and open the app

  1. Build the supplied project before changing its code. Keep its target as .NET Framework 4.8.
  2. After a successful Release build, open bin\Release\net48 and run CDC_Data_VS_WPF.exe. Keep the other build files with it.
  3. Program your board with the matching CDC firmware. Check the PIC and clock settings before using an example made for another board.
  4. Connect the USB cable. Windows must show a COM port for the device before the app can connect.

See the example window on the CDC serial page. Follow the current settings below; the picture is an example.

Make the first connection

  1. Click Refresh and select the board's COM port. Select the board, not another serial device. Windows may show USB Serial Device (COMx) instead of your product name.
  2. Close any other terminal or test app using that port.
  3. For a first USB-only test, use the settings below, unless the firmware example tells you otherwise.
  4. Click Connect. The panel turns green when Windows has opened and configured the port.
  5. Send one command and check the reply. A green panel means the port is open; the reply shows whether your PIC program understood the command.

Setting

Starting choice

What to know

Baud rate

115200

This is a requested serial setting, not the USB transfer speed. Match it when the PIC connects USB to a real UART.

Data bits / parity / stop bits

8 / None / 1

A common starting combination. Match the firmware or UART where needed.

Flow control

None

Leave it here unless the firmware supports another method. Software flow control can interfere with binary bytes.

DTR

Enabled

Some CDC firmware waits for this signal before sending data.

RTS

Disabled

Change it only if the firmware uses it.

Write timeout

1000 ms

The normal starting limit for a send.

After unplugging: select the port and connect again. This CDC app does not reconnect automatically or resend earlier commands. Click Disconnect before changing the port settings.

On restart, the app returns to its source-code defaults.

Send a known command

The three buttons send one binary byte each, with no line ending or padding:

Button

Byte sent in decimal

Same byte in hex

SEND 100

100

64

SEND 200

200

C8

SEND 222

222

DE

SEND 100 does not send the text 100. Typing 100 as text sends three character bytes. Use the button only when the PIC example expects command byte 100. What the command does, and what reply you should see, comes from that firmware.


Use Custom to try other data:

Choose

Enter

Use it for

Text (UTF-8)

Hello

A firmware command or message written as text

Hex bytes

64 C8 DE 00

Exact byte values written in hex

Decimal bytes

100 200 222 0

Exact byte values written in decimal

For a text command, choose None, CR, LF or CR + LF under Ending, as required by the PIC program. These endings apply only to Custom Send. Typing \r\n does not insert a line ending; use the control. Press Send, or press Enter in the input box.


Start with a short command your firmware understands.

Read the reply

Use Text view for text and Hex view for exact byte values. If a reply looks empty or strange, inspect Hex view before changing the firmware.

A successful send only tells you that Windows accepted the bytes. Look for the expected device reply before calling the test successful. Failed sends are not retried automatically.

Make small changes to the source

Most changes belong in these three files:

File or place

A simple first change

MainWindow.xaml

Change a button's label and numeric Tag to match a different command. Change both so the label stays truthful.

MainWindow.xaml.vb, USER SETTINGS

Change the startup baud rate, DTR, flow control or other defaults.

OnConnected / OnDisconnected

Enable or disable your own controls when the port opens or closes.

OnDataReceived

Turn the received bytes into the readings or replies your firmware sends.

Styles.xaml

Change the window's colours and shared appearance.

Keep the communication files unchanged for the first project. Save, rebuild and repeat the same small test after each edit.


CDC arrives as a stream: one receive event can contain half a message or several messages. For text commands, collect data until the agreed line ending. Keep this handling short so the window remains responsive.

If it does not work

What you see

First check

No COM port

Use CDC firmware, check the cable and Windows device list, then Refresh.

Port in use / access denied

Close other serial apps and connect again.

Green panel but no reply

Check the command format, DTR and whether the PIC keeps servicing USB and reads incoming data.

Send times out

Use Flow control None and confirm the PIC is receiving.

Wrong-looking text

Inspect Hex view; check binary versus text and the expected ending.

See also

Created with the Personal Edition of HelpNDoc: Elevate Your CHM Help Files with HelpNDoc's Advanced Customization Options