AndreAtMarin
New member
Hello,
I'm working with a device witch has a Teensy 4 inside for control and communication with a PC over USB.
I did not develop the application on de Teensy, I developed the application on the PC.
The Teensy developer had no problems with communications, I do.
I assume that the problem is at the PC side but I cannot pinpoint what it is, that is why I ask for advise here.
I've searched the web and this forum for known problems with a virtual USB-serial port but in the end found nothing that helped me to solve the problem.
The problem is that after receiving a number of bytes all communication over the virtual USB-serial line stops.
In test situation the Teensy developer cannot reproduce this problem.
For my application I have (valid) data for 0x3800 bytes (14336 bytes), then all communications stops.
More exactly, the DataReceived callback function is not triggered anymore.
This 'point of failure' is repeatable and exact at 0x3800 bytes.
I made a small C# test program for the communication.
See below for the code, for the port I use the default configuration which is 9600 baud, 8 databits, no parity, 1 stopbit, no handshake.
In other version of the code I tried several other combinations without success.
Other things I tried include:
- Looked up details for configuring (and known problems) for USB communication with a virtual USB-serial port.
- Changing USB serial configuration at device level. Using buffers on/off, changing default port configuration details.
- Tried to use handshake signals (DTR) without any success.
- Using C++ and try to open COM3 as a serial port. Can open the port but will not receive a single byte.
- Using several Nuget packages for serial communication.With nuget package 'SerialPortStream' I can receive 0x4000 bytes, all others fail all together or show the same behaviour as with the standard SerialPort class.
EDIT: one more thing I've done. Checked with 'Serial Port Monitor', data is received without problems. Which confirms (to me) that the problem is in the PC somewhere between the virtual USB-serial port handling and de .NET SerialPort instance.
I'm stuck, can't get the communication going.
Does anybody have advise on how to get this solved?
I'm working with a device witch has a Teensy 4 inside for control and communication with a PC over USB.
I did not develop the application on de Teensy, I developed the application on the PC.
The Teensy developer had no problems with communications, I do.
I assume that the problem is at the PC side but I cannot pinpoint what it is, that is why I ask for advise here.
I've searched the web and this forum for known problems with a virtual USB-serial port but in the end found nothing that helped me to solve the problem.
The problem is that after receiving a number of bytes all communication over the virtual USB-serial line stops.
In test situation the Teensy developer cannot reproduce this problem.
For my application I have (valid) data for 0x3800 bytes (14336 bytes), then all communications stops.
More exactly, the DataReceived callback function is not triggered anymore.
This 'point of failure' is repeatable and exact at 0x3800 bytes.
I made a small C# test program for the communication.
See below for the code, for the port I use the default configuration which is 9600 baud, 8 databits, no parity, 1 stopbit, no handshake.
In other version of the code I tried several other combinations without success.
Other things I tried include:
- Looked up details for configuring (and known problems) for USB communication with a virtual USB-serial port.
- Changing USB serial configuration at device level. Using buffers on/off, changing default port configuration details.
- Tried to use handshake signals (DTR) without any success.
- Using C++ and try to open COM3 as a serial port. Can open the port but will not receive a single byte.
- Using several Nuget packages for serial communication.With nuget package 'SerialPortStream' I can receive 0x4000 bytes, all others fail all together or show the same behaviour as with the standard SerialPort class.
EDIT: one more thing I've done. Checked with 'Serial Port Monitor', data is received without problems. Which confirms (to me) that the problem is in the PC somewhere between the virtual USB-serial port handling and de .NET SerialPort instance.
I'm stuck, can't get the communication going.
Does anybody have advise on how to get this solved?
Code:
using System;
using System.Threading;
namespace TestConsole
{
class Program
{
const string PORT_NAME = "COM3";
const int BAUD_RATE = 9600;
static System.IO.Ports.SerialPort port;
static void Main(string[] args)
{
Console.WriteLine($"] port connect {PORT_NAME}");
port = new System.IO.Ports.SerialPort(PORT_NAME, BAUD_RATE);
port.DataReceived += OnRx;
port.DtrEnable = true; // required for communiation
port.Open();
// and wait forever.
while (true) Thread.Sleep(1000);
}
static void OnRx(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
System.IO.Ports.SerialPort sp = (System.IO.Ports.SerialPort)sender;
while (0 < sp.BytesToRead)
{
var b = sp.ReadByte();
if (-1 < b) ConsoleWriteByte((byte)b);
else break;
}
}
const int BYTES_PER_LINE = 16;
static int count = 0;
static int line = 0;
static void ConsoleWriteByte(byte value)
{
if (count % BYTES_PER_LINE == 0)
{
Console.WriteLine();
Console.Write($"{line:x6}:");
count = 0;
line += BYTES_PER_LINE;
}
Console.Write($" {value:x2}");
count++;
}
}
}
Last edited: