[solved] Issues with WIN 8 and FTDI USB-to-RS232 converters

Moderator: Moderators

[solved] Issues with WIN 8 and FTDI USB-to-RS232 converters

Postby ntestoni » 19.11.2013, 17:52

Dear sirs,
I started working with Rocrail on Ubuntu and an home-made DCC booster I designed on the basis of ORD-1 one year ago. I had no problem working with Linux, however I experienced some problems when I moved to the Windows environment. As my new laptop does not feature an RS232 port, I tried to use an FTDI USB-to-RS232 converter.

Unfortunately, as shown in the attached file [from top to bottom: #DTR, #RTS, DATA], I observed that the #DTR and #RTS lines returns to the high state just before starting sending out the packets data. This is problematic as RTS is used to power the short detection and the programming track feedback circuit and DTR is used to signal the booster to power-up. I tried to install the giveio.sys and to change the com port number from 19 to a lower number (3 fiist, then 4). The problem persisted.

So I decided looking at the rocrail source code. I found that this is an unwanted behavior. Infact 'rocdigs\impl\ddx\init.c' line 82 hints that RTS should stay high (#RTS should stay low) as long as the program is running and 'rocdigs\impl\ddx\locpool.c' line 585 hints that DTR should be high (#DTR should be low) as long as the booster is to be powered.

I tracked the source of this problem in the fact that each time the Windows function SetCommState is called within rocs_serial_setSerialMode in 'rocs\impl\win\wserial.c' , the RTS and DTR bit are reset. I have modified the file wserial.c in order to avoid this reset, recompiled the source code and now my booster works correclty.

If anyone with similar problems is interested, I'm willing to share the modified code and/or the modified executables.

Best regards,
Nicola Testoni
You do not have the required permissions to view the files attached to this post.
ntestoni
 

Re: [solved] Issues with WIN 8 and FTDI USB-to-RS232 convert

Postby Coldroots » 26.12.2015, 12:00

Same Problem here, can you please send me the file ?
Coldroots
 

Re: [solved] Issues with WIN 8 and FTDI USB-to-RS232 convert

Postby locodriver » 08.03.2016, 00:32

Hi!
I also use dcc232 system for handling layout, and have also problems with windows 8 and USB to SERIAL cable (on WIN XP was work fine).
Only a small suggestion maybe or a link?

Thank you
Regards.
Miha
locodriver
 

Re: [solved] Issues with WIN 8 and FTDI USB-to-RS232 convert

Postby ntestoni » 30.03.2016, 09:38

Dear friends,

In order to have it work on Win 8 I modified the source code in one file:
Source\rocs\impl\win\wserial.c
I can provide you the modified file for build 9130 if you give me an email address in private message.

Briefly, I added some code to store the RTS and DTR pin values, by means of two static variables:
Code: Select all
static Boolean rocs_serial_RTS = False;
static Boolean rocs_serial_DTR = False;


I also modified the functions
Code: Select all
void rocs_serial_setRTS( iOSerial inst, Boolean rts )
void rocs_serial_setDTR( iOSerial inst, Boolean dtr )

to make them store the current RTS and DTR pin values in the static variables and the function
Code: Select all
void rocs_serial_setSerialMode( iOSerial inst, serial_mode mode )

to restore the stored value after the call of SetCommState. :coding:

I applied the same trick to both builds 6227 and 9130: they both work fine.

Best regards,
Nicola Testoni
ntestoni
 

Re: [solved] Issues with WIN 8 and FTDI USB-to-RS232 convert

Postby rjversluis » 30.03.2016, 09:43

I can provide you the modified file for build 9130 if you give me an email address in private message.

why not publish it here?
Best Regards, Rob.
:!: PS: Do not forget to attach the usual files.
:!: PS: Nicht vergessen die übliche Dateien an zu hängen.
[ macOS - Linux] - [ N: CBUS - CANGCx ] - [ G: CBUS - CANGCx ]
rjversluis
Site Admin
 

Re: [solved] Issues with WIN 8 and FTDI USB-to-RS232 convert

Postby ntestoni » 30.03.2016, 09:45

Sure thing! :coding:

Code: Select all
/*
 Rocs - OS independent C library

 Copyright (C) 2002-2014 Rob Versluis, Rocrail.net

 


 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public License
 as published by the Free Software Foundation.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
#ifdef _WIN32

#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <mmsystem.h>

#include "rocs/impl/serial_impl.h"
#include "rocs/public/trace.h"
#include "rocs/public/thread.h"
#include "rocs/public/system.h"

#ifndef __ROCS_SERIAL__
    #pragma message("*** Win32 OSerial is disabled. (define __ROCS_SERIAL__ in rocs.h) ***")
#endif

/*
 * by Nicola Testoni (2015.05.29)
 * Store the actual value of RTS and DTR pins
 * to prevent port reset after SetCommState.
 */
static Boolean rocs_serial_RTS = False;
static Boolean rocs_serial_DTR = False;
static serial_mode rocs_serial_mode = undefined;

/*
 ***** __Private functions.
 */

//OVERLAPPED overlapped_global;


Boolean rocs_serial_close( iOSerial inst ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  o->rc = 0;
  if( o->handle ) {
    int rc = CloseHandle( o->handle );
    if( !o->blocking ) {
      freeMem( o->overlapped );
      timeEndPeriod(1);
    }
    o->handle = INVALID_HANDLE_VALUE;
    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "Serial[%s] closed.", o->device );
  }
#endif
  return True;
}

Boolean rocs_serial_open( iOSerial inst ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);

  Boolean timeoutSet = False;
  Boolean lineSet    = False;
  int rc = 0;
  char port[14];
  strcpy (port,"\\\\.\\");
  strncat (port, o->device ,5 );
  rocs_serial_close( inst );

  o->rc = 0;

  if( o->portbase == 0 ) {
    if( StrOp.equalsi( "com1", o->device ) )
      o->portbase = 0x3F8;
    else if( StrOp.equalsi( "com2", o->device ) )
      o->portbase = 0x2F8;
    else if( StrOp.equalsi( "com3", o->device ) )
      o->portbase = 0x3E8;
    else if( StrOp.equalsi( "com4", o->device ) )
      o->portbase = 0x2E8;
  }

  o->handle = CreateFile( port,
                          GENERIC_READ | GENERIC_WRITE,
                          0,
                          NULL,
                          OPEN_EXISTING,
                          o->blocking == True ? 0: FILE_FLAG_OVERLAPPED,
                          NULL
                        );

  rc = GetLastError();
  TraceOp.terrno( name, TRCLEVEL_INFO, __LINE__, 9999, rc, "Opening serial[%s]  [return code=%d]", o->device, rc );

  if( o->handle != INVALID_HANDLE_VALUE ) {
    if (!o->blocking) {
      o->overlapped = (void *)allocMem( sizeof( struct _OVERLAPPED ) );
      ((OVERLAPPED *)o->overlapped)->Internal = 0;
      ((OVERLAPPED *)o->overlapped)->InternalHigh = 0;
      ((OVERLAPPED *)o->overlapped)->Offset = 0;
      ((OVERLAPPED *)o->overlapped)->OffsetHigh = 0;
      timeBeginPeriod(1);
    }
    /*Is portbase defined (com1-4)? Can we access it by giveio.sys?*/
    if ( o->portbase && SystemOp.accessPort(o->portbase,8) ) {
      /* Simple test for 16550 compatible Uart by writing to and read back from scratch register */
      SystemOp.writePort( o->portbase + 7, 0x55 );
      if (SystemOp.readPort( o->portbase + 7 )==0x55)
        o->directIO= True;
      else
        o->directIO= False;
    } else
      o->directIO= False;
    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "blocking[%d] directIO[%d]", o->blocking, o->directIO);

    COMMTIMEOUTS        cto;
    GetCommTimeouts( o->handle, &cto );

    /* CommTimeout */
    cto.ReadIntervalTimeout         = o->timeout.read;
    cto.ReadTotalTimeoutMultiplier  = 0;
    cto.ReadTotalTimeoutConstant    = o->timeout.read;

    cto.ReadTotalTimeoutMultiplier  = 0;
    cto.ReadTotalTimeoutConstant    = o->timeout.write;

    timeoutSet = SetCommTimeouts( o->handle, &cto );
    rc = GetLastError();
    TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "Serial[%s] timeout setted.[rc=%d]", o->device, rc );

    if( timeoutSet ) {
      /* CommState */
      DCB   dcb;
      memset( &dcb, 0, sizeof( dcb ) );

      dcb.DCBlength         = sizeof(DCB) ;
      dcb.BaudRate          = o->line.bps;
      dcb.fBinary           = True;
      dcb.fParity           = False;
      dcb.fOutxCtsFlow      = o->line.flow == cts ? True:False;
      dcb.fOutxDsrFlow      = o->line.flow == dsr ? True:False;
      dcb.fDtrControl       = o->line.flow == dsr ? DTR_CONTROL_HANDSHAKE:DTR_CONTROL_DISABLE;
      dcb.fDsrSensitivity   = False;
      dcb.fTXContinueOnXoff = False;
      dcb.fOutX             = o->line.flow == xon ? True:False;
      dcb.fInX              = o->line.flow == xon ? True:False;
      dcb.fErrorChar        = False;
      dcb.fNull             = False;
      dcb.fRtsControl       = o->line.rtsdisabled ? RTS_CONTROL_DISABLE:RTS_CONTROL_HANDSHAKE;
      dcb.fAbortOnError     = False;
      dcb.wReserved         = 0;
      dcb.ByteSize          = o->line.bits;

      if( o->line.parity == even )
        dcb.Parity = EVENPARITY;
      else if( o->line.parity == odd )
        dcb.Parity = ODDPARITY;
      else if( o->line.parity == none )
        dcb.Parity = NOPARITY;

      if( o->line.stopbits == onestopbit )
        dcb.StopBits = ONESTOPBIT;
      if( o->line.stopbits == twostopbits )
        dcb.StopBits = TWOSTOPBITS;

      if( o->line.bps > 256000 ) {
        COMMCONFIG cc;
        int size = sizeof(COMMCONFIG);
        DWORD confSize = sizeof(COMMCONFIG);
        memset((void *)(&cc), 0, size);
        GetCommConfig(o->handle, &cc, &confSize);
        cc.dcb.DCBlength         = sizeof(DCB) ;
        cc.dcb.BaudRate          = o->line.bps;
        cc.dcb.fBinary           = True;
        cc.dcb.fParity           = False;
        cc.dcb.fOutxCtsFlow      = o->line.flow == cts ? True:False;
        cc.dcb.fOutxDsrFlow      = o->line.flow == dsr ? True:False;
        cc.dcb.fDtrControl       = o->line.flow == dsr ? DTR_CONTROL_HANDSHAKE:DTR_CONTROL_DISABLE;
        cc.dcb.fDsrSensitivity   = False;
        cc.dcb.fTXContinueOnXoff = False;
        cc.dcb.fOutX             = o->line.flow == xon ? True:False;
        cc.dcb.fInX              = o->line.flow == xon ? True:False;
        cc.dcb.fErrorChar        = False;
        cc.dcb.fNull             = False;
        cc.dcb.fRtsControl       = o->line.rtsdisabled ? RTS_CONTROL_DISABLE:RTS_CONTROL_HANDSHAKE;
        cc.dcb.fAbortOnError     = False;
        cc.dcb.wReserved         = 0;
        cc.dcb.ByteSize          = o->line.bits;
        SetCommConfig(o->handle, &cc, sizeof(COMMCONFIG));
      }
      else {
        lineSet = SetCommState( o->handle, &dcb );
      }
      rc = GetLastError();
      TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "Serial[%s] line setted.[rc=%d]", o->device, rc );
    }
    return True;
  }

#endif
  return False;
}

void rocs_serial_setRTS( iOSerial inst, Boolean rts ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  int func = rts?SETRTS:CLRRTS;
  o->rc = 0;
  EscapeCommFunction( o->handle, func );
  /*
   * by Nicola Testoni (2015.05.29)
   * Store the modified value of the RTS pin
   * to prevent port reset after SetCommState.
   */
    rocs_serial_RTS = rts;
#else

  return;
#endif
}

void rocs_serial_setCTS( iOSerial inst, Boolean cts ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  /* TODO: set CTS */
#else

  return;
#endif
}

void rocs_serial_setDTR( iOSerial inst, Boolean dtr ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  int func = dtr?SETDTR:CLRDTR;
  int rc = EscapeCommFunction( o->handle, func );
  o->rc = 0;
  if( rc == 0 ) {
    rc = GetLastError();
    TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "Serial[%s] setDTR [error=%d][function=%d]", o->device, rc, func );
    o->rc = rc;
  }
  /*
   * by Nicola Testoni (2015.05.29)
   * Store the modified value of the DTR pin
   * to prevent port reset after SetCommState.
   */
    rocs_serial_DTR = dtr;
#else
  return;
#endif
}

Boolean rocs_serial_isCTS( iOSerial inst ) {
  long state = 0;
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  o->rc = 0;
  GetCommModemStatus( o->handle, &state );
#endif

  return state & MS_CTS_ON ? True:False;
}

Boolean rocs_serial_isDSR( iOSerial inst ) {
  long state = 0;
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  o->rc = 0;
  GetCommModemStatus( o->handle, &state );
#endif

  return state & MS_DSR_ON ? True:False;
}

Boolean rocs_serial_isRI( iOSerial inst ) {
  long state = 0;
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  o->rc = 0;
  if (o->directIO) {
    int msr = SystemOp.readPort( o->portbase + 6 );
    if( msr & 0x04 ) /* RI changed */
      return True;
  }
  GetCommModemStatus( o->handle, &state );
  return state & MS_RING_ON ? False:True;
#endif
}

int rocs_serial_getWaiting( iOSerial inst ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  o->rc = 0;
  if (o->blocking) {
    //      int lsr = SystemOp.readPort( o->portbase + 5 );
    /* 0x40 = Transmitter Holding Register is empty and the shift register too */
    /* this flag turns high on empty */
    //      return (lsr & 0x40) ? 0:1;
    return 0;  /*When using blocking io there are no waiting bytes, as write hangs until empty.*/
  }
  else {
    COMSTAT comStat;
    DWORD   dwErrors;
    // Get and clear current errors on the port.
    ClearCommError(o->handle, &dwErrors, &comStat);
    return comStat.cbOutQue;
  }
#endif
}


Boolean rocs_serial_isUartEmpty( iOSerial inst, Boolean soft ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  o->rc = 0;
  if (o->blocking) {
    return True; /*When using blocking io there are no waiting bytes, as write hangs until empty.*/
  }
  else {
    if ((o->directIO) || (!soft)) {
      if (!rocs_serial_getWaiting(inst)) {
        int lsr = SystemOp.readPort( o->portbase + 5 );
        /* 0x40 = Transmitter Holding Register is empty and the shift register too */
        /* this flag turns high on empty */
        return (lsr & 0x40) ? True:False;
      }
      else
        return False;
    }
    else {
      if (!rocs_serial_getWaiting(inst))
        return True; //TODO: add code for non-directIO.
      else
        return False;
    }
  }
#endif
}


void rocs_serial_setOutputFlow( iOSerial inst, Boolean flow ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  int rc = 0;
  o->rc = 0;
  /* TODO: output flow on/off */
#endif
}


void rocs_serial_flush( iOSerial inst ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  int rc = PurgeComm( o->handle, PURGE_TXABORT | PURGE_TXCLEAR );
  o->rc = 0;
  if( rc == 0 ) {
    rc = GetLastError();
    TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "Serial[%s] Flush error [error=%d]", o->device, rc );
    o->rc = rc;
  }
#endif
}



Boolean rocs_serial_write( iOSerial inst, char* buffer, int size ) {
  int rc     = 0;
#ifdef __ROCS_SERIAL__

  iOSerialData o = Data(inst);
  long sended = 0;
  int ok     = 0;
  o->rc = 0;

  if (o->blocking) {
    ok = WriteFile( o->handle, buffer, size, &sended, NULL );
  }
  else {
    ok = WriteFile( o->handle, buffer, size, &sended, o->overlapped );
  }
  if( !ok ) {
    rc = GetLastError();
    //    SerialOp.available( inst );
  }

  if( o->blocking && sended != size )
    TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "Serial[%s] %d of %d sent.[rc=%d]", o->device, sended, size, rc );
  else
    TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "Serial[%s] %d sent.[rc=%d]", o->device, sended, rc );
  if (rc != ERROR_IO_PENDING) {
    o->ioState = ok;
    o->rc = rc;
    return rc > 0 ? False:True;
  }
  else {
    o->ioState = 1;
    o->rc = 0;
    return True;
  }
#endif
}

int rocs_serial_avail( iOSerial inst ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  DWORD etat;
  struct _COMSTAT comstat;
  int rc = ClearCommError( o->handle, &etat, &comstat );
  o->rc = 0;
  if( rc == 0 ) {
    /*
      CE_BREAK    0x0010 The hardware detected a break condition.
      CE_FRAME    0x0008 The hardware detected a framing error.
      CE_OVERRUN  0x0002 A character-buffer overrun has occurred. The next character is lost.
      CE_RXOVER   0x0001 An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.
      CE_RXPARITY 0x0004 The hardware detected a parity error.
     */
    TraceOp.trc( name, TRCLEVEL_EXCEPTION, __LINE__, 9999, "Serial[%s] error=0x%04X", o->device, etat );
    o->rc = etat;
    return -1;
  }
  else
    return comstat.cbInQue;
#endif
}


Boolean rocs_serial_read( iOSerial inst, char* buffer, int size ) {
  int rc     = 0;
#ifdef __ROCS_SERIAL__

  iOSerialData o = Data(inst);
  long readcnt = 0;
  int  ok     = 0;
  long cnt    = 0;
  int  tries  = 0;

  o->read = 0;
  o->rc = 0;

  do {
    if (o->blocking) {
      ok = ReadFile( o->handle, buffer, size, &cnt, NULL );
    } else {
      ok = ReadFile( o->handle, buffer, size, &cnt, o->overlapped );
    }

    if( !ok ) {
      rc = GetLastError();
      SerialOp.available( inst );
      o->rc = rc;
    }
    if( rc == 0 )
      readcnt += cnt;
    /* Check for timeout: */
    if( rc == 0 && cnt == 0 ) {
      tries++;
    }
  } while( rc == 0 && readcnt < size && tries < 3 );

  if( readcnt != size && rc == 0 )
    TraceOp.trc( name, TRCLEVEL_EXCEPTION, __LINE__, 9999, "Timeout on serial read[%s] %d of %d read.[rc=%d] tries=%d", o->device, readcnt, size, rc, tries );
  else if( rc > 0 )
    TraceOp.trc( name, TRCLEVEL_EXCEPTION, __LINE__, 9999, "Serial[%s] %d of %d read.[rc=%d] tries=%d", o->device, readcnt, size, rc, tries );
  else
    TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "Serial[%s] %d read.[rc=%d]", o->device, readcnt, rc );

  o->rc = 0;
  o->ioState = ok;
  o->read = readcnt;
  return readcnt == size ? True:False;
#else

  return False;
#endif
}

void rocs_serial_setSerialMode( iOSerial inst, serial_mode mode ) {
  iOSerialData o = Data(inst);
  DCB   dcb;
  int rc = 0;

  /*
   * by Nicola Testoni 2015.05.29
   * Avoid unnecessary resets of the serial port.
   */
  if (mode==rocs_serial_mode) return;

  o->rc = 0;
  if (!o->directIO) {
    memset( &dcb, 0, sizeof( dcb ) );
    if (!GetCommState( o->handle, &dcb )) {
      rc = GetLastError();
      TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "GetCommState failed.[rc=%d]", rc );
      return;
    }
  }
  switch (mode) {
  case mm:
    /* Set Uart register for 38400baud Marklin/Motorola*/
    if (o->currserialmode != mm) {
      o->currserialmode = mm;
      if (o->directIO) {
        SystemOp.writePort( o->portbase + 3, 0x80 );
        SystemOp.writePort( o->portbase + 0, 0x03 );
        SystemOp.writePort( o->portbase + 1, 0x00 );
        SystemOp.writePort( o->portbase + 3, 0x01 );
      }
      else {
        dcb.BaudRate = 38400;
        dcb.ByteSize = 6;
        dcb.Parity = NOPARITY;
        dcb.StopBits = ONESTOPBIT;
      }
    }
    break;
  case dcc:
    /* Set Uart register for 19200baud NMRA DCC */
    if (o->currserialmode != dcc) {
      o->currserialmode = dcc;
      if (o->directIO) {
        SystemOp.writePort( o->portbase + 3, 0x80 );
        SystemOp.writePort( o->portbase + 0, 0x06 );
        SystemOp.writePort( o->portbase + 1, 0x00 );
        SystemOp.writePort( o->portbase + 3, 0x03 );
      }
      else {
        dcb.BaudRate = 17241; //19200;
        dcb.ByteSize = 8;
        dcb.Parity = NOPARITY;
        dcb.StopBits = ONESTOPBIT;
      }
    }
    break;
  case mma:
    /* Set Uart register for 115200baud Marklin/Motorola Accessory */
    if (o->currserialmode != mma) {
      o->currserialmode = mma;
      if (o->directIO) {
        SystemOp.writePort( o->portbase + 3, 0x80 );
        SystemOp.writePort( o->portbase + 0, 0x01 );
        SystemOp.writePort( o->portbase + 1, 0x00 );
        SystemOp.writePort( o->portbase + 3, 0x1F );
      }
      else {
        dcb.BaudRate = 115200;
        dcb.ByteSize = 8;
        dcb.Parity = EVENPARITY;
        dcb.StopBits = TWOSTOPBITS;
      }
      break;
    }
    default: TraceOp.trc( __FILE__, TRCLEVEL_ERROR, __LINE__, 9999, "Error setting Serial mode!");
  }
  /* set attribute now */
  if (!o->directIO && !SetCommState( o->handle, &dcb )) {
    rc = GetLastError();
    TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "SetCommState failed.[rc=%d]", rc );
    o->rc = rc;
  }
  //        tcgetattr( o->sh, &tio );
  //    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "Current output baud rate is %d\n", (int) cfgetospeed(&tio) );

  /*
   * by Nicola Testoni (2015.05.29)
   * Since SetCommState resets the serial port RTS and DTR pins,
   * it is necessary to restore the values they had before
   * the call of rocs_serial_setSerialMode. Then the current
   * serial mode is updated.
   */
  rocs_serial_setRTS(inst,rocs_serial_RTS);
  rocs_serial_setDTR(inst,rocs_serial_DTR);
  rocs_serial_mode = mode;
}

void rocs_serial_waitMM( iOSerial inst, int usperiod, int uspause  ) {
  iOSerialData o = Data(inst);
  o->rc = 0;
  if( o->directIO ) {
    while( !SerialOp.isUartEmpty( inst, True ) )
      ;
    if (usperiod>16000) /*If wait is longer than a process time slice, use normal sleep*/
      ThreadOp.sleep(uspause/1000);
    else
      SystemOp.uBusyWait(uspause);
  } else {
    if (usperiod>16000) /*If wait is longer than a process time slice, use normal sleep*/
      ThreadOp.sleep(usperiod/1000);
    else
      SystemOp.uBusyWait(usperiod);
  }
}


#endif
ntestoni
 

Re: [solved] Issues with WIN 8 and FTDI USB-to-RS232 convert

Postby ntestoni » 30.03.2016, 09:46

Just look for the comment blocks starting with "by Nicola Testoni" :mrgreen:
NT
ntestoni
 

Re: [solved] Issues with WIN 8 and FTDI USB-to-RS232 convert

Postby rjversluis » 30.03.2016, 10:10

Tnx,

I just merge this functionality in a none static way.
Best Regards, Rob.
:!: PS: Do not forget to attach the usual files.
:!: PS: Nicht vergessen die übliche Dateien an zu hängen.
[ macOS - Linux] - [ N: CBUS - CANGCx ] - [ G: CBUS - CANGCx ]
rjversluis
Site Admin
 

Re: [solved] Issues with WIN 8 and FTDI USB-to-RS232 convert

Postby ntestoni » 30.03.2016, 10:14

You're welcome! :thumb_up:
Happy to help. :-)

NT
ntestoni
 


Return to ddx