Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: PC to USB SERIAL interface

  1. #1
    Member
    Join Date
    Feb 2015
    Location
    Rians in Provence, France
    Posts
    53

    PC to USB SERIAL interface

    Helle all,
    I'm planning to connect a TEENSY 3.2 or 5 to a PC.
    Teensy is declared as SERIAL
    Sytem configuration indicates COM16, but the CreateFile() function don't recognizes this port nor another port under WIN XP.
    Under WIN 10, there is no COM port indicated by the system.
    I'm using the USBDeview.exe for reading the available USB ports.
    Thanks for your help !
    -----------------------------------------------------------------------------------------------------------
    SOURCE CODE
    -----------------------------------------------------------------------------------------------------------


    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>

    //To cross-compile on Ubuntu:
    //sudo apt-get install mingw32 mingw32-binutils mingw32-runtime
    //i586-mingw32msvc-gcc -s -O3 -Wall -o serial_read.exe serial_read.c

    const char *begin_string="10 second speed test begins";
    const char *end_string="done!\r\n";
    #define END_LEN 7

    long i;
    char data;
    int numport;
    char carsynchro = {'@'};

    int main(void)
    {

    char bufferout[8] = {1,2,3,4,5,6,7,8};
    HANDLE port;
    COMMTIMEOUTS timeout;
    COMMCONFIG cfg;
    BOOL ret;
    DWORD n,sum=0;

    char com[16][32]={"COM16","COM1","COM2","COM3","COM4","COM5","COM6 ","COM7"};


    // TODO: check if the user typed "COM##" where the number is
    // greater than 9. If so, automatically reformat to \\.\COM##

    // Open the serial port

    for(numport = 0;numport<16;numport++)
    {
    port = CreateFile((char*)&com[numport][0], GENERIC_READ | GENERIC_WRITE,0, 0,OPEN_EXISTING, 0, NULL);

    if (port == INVALID_HANDLE_VALUE)
    {
    exit(1);
    }
    else
    goto porttrouve;
    }


    exit(900);
    porttrouve:
    // Configure the port
    GetCommConfig(port, &cfg, &n);
    cfg.dcb.BaudRate = 115200;
    cfg.dcb.fBinary = TRUE;
    cfg.dcb.fParity = FALSE;
    cfg.dcb.fOutxCtsFlow = FALSE;
    cfg.dcb.fOutxDsrFlow = FALSE;
    cfg.dcb.fDtrControl = DTR_CONTROL_ENABLE;
    cfg.dcb.fDsrSensitivity = FALSE;
    cfg.dcb.fTXContinueOnXoff = TRUE;
    cfg.dcb.fOutX = FALSE;
    cfg.dcb.fInX = FALSE;
    cfg.dcb.fErrorChar = FALSE;
    cfg.dcb.fNull = FALSE;
    cfg.dcb.fRtsControl = RTS_CONTROL_ENABLE;
    cfg.dcb.fAbortOnError = FALSE;
    cfg.dcb.XonLim = 0x8000;
    cfg.dcb.XoffLim = 20;
    cfg.dcb.ByteSize = 8;
    cfg.dcb.Parity = NOPARITY;
    cfg.dcb.StopBits = ONESTOPBIT;
    SetCommConfig(port, &cfg, n);
    GetCommTimeouts(port, &timeout);
    timeout.ReadIntervalTimeout = 250;
    timeout.ReadTotalTimeoutMultiplier = 1;
    timeout.ReadTotalTimeoutConstant = 500;
    timeout.WriteTotalTimeoutConstant = 2500;
    timeout.WriteTotalTimeoutMultiplier = 1;
    SetCommTimeouts(port, &timeout);

    // WRITEdata until we get a timeout or error or see the end string

    ret = WriteFile(port,bufferout,8,&n,NULL);

    fflush(stdout);

    CloseHandle(port);

    return 0;
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,932
    On Windows, to open COM ports higher than COM9 with WIN32 CreateFile(), you need this:

    https://support.microsoft.com/en-us/...rger-than-com9

    Yes, it's lame, but that's Microsoft.

  3. #3
    Member
    Join Date
    Feb 2015
    Location
    Rians in Provence, France
    Posts
    53
    Quote Originally Posted by PaulStoffregen View Post
    On Windows, to open COM ports higher than COM9 with WIN32 CreateFile(), you need this:

    https://support.microsoft.com/en-us/...rger-than-com9

    Yes, it's lame, but that's Microsoft.
    Thank you so much, Paul. It runs !

  4. #4
    Member
    Join Date
    Feb 2015
    Location
    Rians in Provence, France
    Posts
    53

    Usb 3.6 usb problem

    Hello all,

    TEENSY 3.6 controlling the Techtoys video board 8876 is running fine ONLY WHEN THE Teensy micro-USB1 plug is connected to a PC/USB 2.0
    (For information, the USB Host 5 pins connector (I call it USB2) is connected to the Tactile Screen USB output).
    When I try to connect the USB1 to a simple USB supply (no longer the PC), the Teensy don't runs. Strange.
    Because absolutely no program running on the PC is necessary for running my Teensy program. (Except the 5V supply replaced by a 5V classic USB charger!).
    Thanks for your help !
    Best regards,
    Pascal Leray

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,567
    Do you have a while(!Serial) in setup() ?
    If not, post your code..

  6. #6
    Member
    Join Date
    Feb 2015
    Location
    Rians in Provence, France
    Posts
    53
    Magic, It runs without !Serial !
    Thank you so much !

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,567
    Glad that it works

  8. #8
    Member
    Join Date
    Feb 2015
    Location
    Rians in Provence, France
    Posts
    53

    USB HOST PORT as Touchscreen Input TEENSY 3.6

    Quote Originally Posted by Frank B View Post
    Glad that it works
    Hello all,

    When I connect the TEENSY 3.6 USB HOST port to a touchscreen USB output with a BUYDISPLAY HDMI screen , all is running fine.
    But with another touchscreens such as the svga LG FLATRON T1710, no response.
    Of course, this screen runs normally with a PC.
    Thanks for your help !

    Pascal Leray

  9. #9
    Member
    Join Date
    Feb 2015
    Location
    Rians in Provence, France
    Posts
    53
    Quote Originally Posted by LERAY View Post
    Hello all,

    When I connect the TEENSY 3.6 USB HOST port to a touchscreen USB output with a BUYDISPLAY HDMI screen , all is running fine.
    But with another touchscreens such as the svga LG FLATRON T1710, no response.
    Of course, this screen runs normally with a PC.
    Thanks for your help !

    Pascal Leray
    I tried also with an ASUS VT207 : no response too. Is anyone has infos about Touchscreen USB interfaces ? Can we test something with the TEENSY 3.6 ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •