Dear all,
i cannot replicate the maximum speed available by USB Serial port!
I'm expect 820kbytes/sec but i got 7,5kbytes/sec !!!
here is my test program (client and server).
Someone can help me to find the reason?
Thanks much
________________
Teensy source
________________
#include <stdlib.h>
#include <string.h>
const uint8_t BUFFERDATA = 128;
uint8_t receivedData[BUFFERDATA];
uint8_t *receivedData_ptr = &receivedData[0];
int receivedData_len;
void setup()
{
Serial.begin(57600); // USB is always 12 Mbit/sec
}
void loop()
{
receivedData_len=0;
while (Serial.available()>0)
{
receivedData[receivedData_len] = Serial.read();
receivedData_len++;
}
if (receivedData_len>0)
{
// Received data
sendCOMData(receivedData_ptr,receivedData_len);
}
}
void sendCOMData(uint8_t *data, int data_len)
{
Serial.write(data, data_len);
Serial.send_now();
}
____________
Client c#.NET
____________
using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
namespace SerialOATH
{
class Program
{
static SerialPort _serialPort;
static void Main(string[] args)
{
// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
// Allow the user to set the appropriate properties.
Console.WriteLine("COM7");
_serialPort.PortName = "COM7";
_serialPort.BaudRate = 115200;
byte[] data = new byte[] { 0x01, 0x14, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte[] result = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
TimeSpan start = new TimeSpan(DateTime.UtcNow.Ticks);
for (int pp = 0; pp < 1000; pp++)
{
_serialPort.Open();
_serialPort.Write(data, 0, data.Length);
while (_serialPort.BytesToRead < 1) { };
int tot = _serialPort.BytesToRead;
Array.Resize<byte>(ref result, tot);
for (int i = 0; i < tot; i++)
result = (byte)_serialPort.ReadByte();
_serialPort.Close();
}
TimeSpan stop = new TimeSpan(DateTime.UtcNow.Ticks);
Console.WriteLine("It required {0} millisec to complete", (stop.TotalMilliseconds - start.TotalMilliseconds));
Console.ReadKey();
}
}
}
i cannot replicate the maximum speed available by USB Serial port!
I'm expect 820kbytes/sec but i got 7,5kbytes/sec !!!
here is my test program (client and server).
Someone can help me to find the reason?
Thanks much
________________
Teensy source
________________
#include <stdlib.h>
#include <string.h>
const uint8_t BUFFERDATA = 128;
uint8_t receivedData[BUFFERDATA];
uint8_t *receivedData_ptr = &receivedData[0];
int receivedData_len;
void setup()
{
Serial.begin(57600); // USB is always 12 Mbit/sec
}
void loop()
{
receivedData_len=0;
while (Serial.available()>0)
{
receivedData[receivedData_len] = Serial.read();
receivedData_len++;
}
if (receivedData_len>0)
{
// Received data
sendCOMData(receivedData_ptr,receivedData_len);
}
}
void sendCOMData(uint8_t *data, int data_len)
{
Serial.write(data, data_len);
Serial.send_now();
}
____________
Client c#.NET
____________
using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
namespace SerialOATH
{
class Program
{
static SerialPort _serialPort;
static void Main(string[] args)
{
// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
// Allow the user to set the appropriate properties.
Console.WriteLine("COM7");
_serialPort.PortName = "COM7";
_serialPort.BaudRate = 115200;
byte[] data = new byte[] { 0x01, 0x14, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte[] result = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
TimeSpan start = new TimeSpan(DateTime.UtcNow.Ticks);
for (int pp = 0; pp < 1000; pp++)
{
_serialPort.Open();
_serialPort.Write(data, 0, data.Length);
while (_serialPort.BytesToRead < 1) { };
int tot = _serialPort.BytesToRead;
Array.Resize<byte>(ref result, tot);
for (int i = 0; i < tot; i++)
result = (byte)_serialPort.ReadByte();
_serialPort.Close();
}
TimeSpan stop = new TimeSpan(DateTime.UtcNow.Ticks);
Console.WriteLine("It required {0} millisec to complete", (stop.TotalMilliseconds - start.TotalMilliseconds));
Console.ReadKey();
}
}
}