Error writing on serial port problem

Open a thread for a question about the simulator control software.
If you cannot receive any data in the input setup use the upper two forums!

Error writing on serial port problem

Postby R4MP4G3RXD » Thu 24. Sep 2015, 21:35

Hello everyone! Recently I've started a project, a dashboard for some racing games, mainly dirt 3!
So my problem is that everything works good until a minute and then x-sim pops up with "Error writing on serial port"
I think it happens because sometimes my cpu usage is at 100.5%
But I really don't know, please help, me people! Thanks in advance!

Error:
Image

Setup:
-RPM
Image
-GEAR
Image
-SPEED
Image

USO:
Image

CODE FOR ARDUINO:
Code: Select all
#include <LiquidCrystal.h>

LiquidCrystal lcd (12, 11, 5, 4, 3, 2);

void setup()
{

  Serial.begin(115200);

  lcd.begin(20, 4);
  lcd.print("LOADING");
 
  lcd.clear();

}

void loop()
{

  if (Serial.available())
  {

    //Get data from serial

    char kindofdata = Serial.read();
    int reading = Serial.parseInt();

    //Send data to the write command

    writetolcd(kindofdata, reading);

  }

}

void writetolcd(char kind, int data)
{

  //Read the kind of data

  if (kind == 'R')
  {
   
    if (data * 33 >= 6200) digitalWrite(13, HIGH);
    else digitalWrite(13, LOW);
   
    lcd.setCursor(1, 1);
    lcd.print("RPM : ");
   
    lcd.setCursor(7, 1);
    lcd.print("     ");
   
    lcd.setCursor(7, 1);
    lcd.print(data * 33);  //Convert data to a more accurate reading

    return;

  }

  //Read the kind of data

  if (kind == 'G')
  {
   
    lcd.setCursor(1, 2);
    lcd.print("Gear : ");
    lcd.setCursor(8, 2);
   
    if (data == 255) lcd.print("R");
    else if (data == 0) lcd.print("1");
    else if (data == 36) lcd.print("2");
    else if (data == 73) lcd.print("3");
    else if (data == 109) lcd.print("4");
    else if (data == 146) lcd.print("5");
    else if (data == 223) lcd.print("6");
    else if (data == 239) lcd.print("7");
    else if (data == 255) lcd.print("8");
   
    return;

  }
 
  //Read the kind of data
 
  if (kind == 'S')
  {
    lcd.setCursor(1, 0);
    lcd.print("Speed : ");
    lcd.setCursor(12, 0);
    lcd.print("Km/h");
   
    lcd.setCursor(9, 0);
    lcd.print("   ");
    lcd.setCursor(9, 0);
    lcd.print(data * 2);
   
    return;
  }

  return;

}


I'm going to change the shift light so, I can determine the rpm at which the led turns on, but as long as I don't get this problem fixed I'm not really gonna be doing much else.

Thanks in advance!
Regards,
--Valentin
R4MP4G3RXD
 
Posts: 5
Joined: Fri 31. Jan 2014, 20:13
Has thanked: 0 time
Been thanked: 0 time

Re: Error writing on serial port problem

Postby sirnoname » Thu 24. Sep 2015, 22:25

Maybe, or you have power spikes (motor power noise for example), a long cable or other USB disconnects.
The error write is from a standard windows API call, normally this is cpu load independend.
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

Re: Error writing on serial port problem

Postby R4MP4G3RXD » Fri 25. Sep 2015, 15:35

sirnoname wrote:Maybe, or you have power spikes (motor power noise for example), a long cable or other USB disconnects.
The error write is from a standard windows API call, normally this is cpu load independend.


Probably the cpu usage, I closed my youtube tab in my browser and the cpu was around 96% usage, and I didn't get an error. I don't have motors or anything, just a display and an led. :D

Thanks a lot for the response! :mrgreen:
R4MP4G3RXD
 
Posts: 5
Joined: Fri 31. Jan 2014, 20:13
Has thanked: 0 time
Been thanked: 0 time

Re: Error writing on serial port problem

Postby sirnoname » Fri 25. Sep 2015, 16:40

ok, but this can be changed to wait longer on a write.
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

Re: Error writing on serial port problem

Postby R4MP4G3RXD » Sat 26. Sep 2015, 10:55

sirnoname wrote:ok, but this can be changed to wait longer on a write.


Yeah, but then there is a delay that can mess me up..
What do you reckon is the best delay setting?
R4MP4G3RXD
 
Posts: 5
Joined: Fri 31. Jan 2014, 20:13
Has thanked: 0 time
Been thanked: 0 time

Re: Error writing on serial port problem

Postby sirnoname » Sat 26. Sep 2015, 12:09

The problem is to change X-Sim to use other WinAPI commands, not to change USO.
For now X-Sim send xyz zu the serial buffer and return immediatelly because it is only memory to serial port output buffer memory. I have to increase the WinAPI calls to a longer wait cycle.

Code: Select all
m_CommTimeouts.ReadIntervalTimeout = 50;
m_CommTimeouts.ReadTotalTimeoutConstant = 50;
m_CommTimeouts.ReadTotalTimeoutMultiplier = 10;
m_CommTimeouts.WriteTotalTimeoutConstant = 50;
m_CommTimeouts.WriteTotalTimeoutMultiplier = 0;


So it waits for 50ms for a buffer transfere.

By the way, what happens if you run in the program setup with the profiler on a single CPU core?
And try to increase the main program task priority in same dialog.
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

Re: Error writing on serial port problem

Postby R4MP4G3RXD » Sun 27. Sep 2015, 13:14

sirnoname wrote:The problem is to change X-Sim to use other WinAPI commands, not to change USO.
For now X-Sim send xyz zu the serial buffer and return immediatelly because it is only memory to serial port output buffer memory. I have to increase the WinAPI calls to a longer wait cycle.

Code: Select all
m_CommTimeouts.ReadIntervalTimeout = 50;
m_CommTimeouts.ReadTotalTimeoutConstant = 50;
m_CommTimeouts.ReadTotalTimeoutMultiplier = 10;
m_CommTimeouts.WriteTotalTimeoutConstant = 50;
m_CommTimeouts.WriteTotalTimeoutMultiplier = 0;


So it waits for 50ms for a buffer transfere.

By the way, what happens if you run in the program setup with the profiler on a single CPU core?
And try to increase the main program task priority in same dialog.


I've just ran the profiler on the single core and it worked perfectly while having 2 web browsers open! The cpu was only at about 87% usage! :D
Thanks a bunch for the help! :mrgreen:
ps. why do I get the same value for 1st gear as for neutral gear? :?:
R4MP4G3RXD
 
Posts: 5
Joined: Fri 31. Jan 2014, 20:13
Has thanked: 0 time
Been thanked: 0 time

Re: Error writing on serial port problem

Postby JBDLink » Fri 3. Jun 2016, 20:46

Hello!
I have the same Serial Write Error on Com3 problem.

I started my configuration with 4 bass shakers and everything works perfect. But when I add an arduino mega on USO, just for power some leds, it works perfect for 3-4 minutes and then the X-Sims stops because Serial Write error on Com3. If I click start on X-Sim after the error it works perfect for 3-4 mins more, and the problem again.

I tried diferents usb ports in my computer and diferent usb cables with no luck. I tried diferent comport speeds. I tried to run x-sim on a single cpu.

The cpu load don't exceed 45% while playing Assetto Corsa + X-Sim

With a USO delay of 200 ms, the error comes in 3-4 mins, If I increase the delay time, serial write error comes later. It seams to me that is a saturation problem.

Thanks in advance!
JBDLink
 
Posts: 19
Joined: Wed 25. May 2016, 18:31
Has thanked: 0 time
Been thanked: 0 time

Re: Error writing on serial port problem

Postby sirnoname » Sat 4. Jun 2016, 12:51

You must do this test without any motor power influence. You can open the windows device manager. This will show you all devices and it will only refresh if there is a smart USB disconnect. Check if it will refresh suddenly or not while the comport error will pop up.
There are some other tools on the market which can count the reconnects on USB for you.
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

Re: Error writing on serial port problem

Postby JBDLink » Sat 4. Jun 2016, 13:44

sirnoname wrote:You must do this test without any motor power influence. You can open the windows device manager. This will show you all devices and it will only refresh if there is a smart USB disconnect. Check if it will refresh suddenly or not while the comport error will pop up.
There are some other tools on the market which can count the reconnects on USB for you.




I'll check for usb disconnects and try some tools to count the usb reconnects.

When you say "do the test without any motor influence": the G27 steering wheel and joystick count as motors? beacuse they are connected to usb ports at the same computer.

Thank you for the quick reply!

edit: I tried to play with the device manager opened but no refresh when I get the serial write error.
I tried with an Arduino UNO instead of Arduino Mega but same problem at same minute.
I tried with no motors at all, same problem.
I have unchecked the power saving option in all my usb ports.
I have updated the USB drivers on my computer again.
My OS is Windows10.

I'm looking for a sotfware to track the usb disconnections, can you recomend me any one?

is there any way for making x-sim to autoreconect after the error? if I close the error window and click start again on x-sim all works good for 3-4 minutes more.

I'm empy of ideas!
JBDLink
 
Posts: 19
Joined: Wed 25. May 2016, 18:31
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Converter questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron