1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

LPC1768 USB hangup

Discussion in 'Embedded' started by John Larkin, Jul 7, 2012.

  1. John Larkin

    John Larkin Guest

    We built a little picosecond pulse generator box with a USB interface.
    The USB is directly into an LPC1768 NXP ARM chip, and we're using the
    USB stack and inf file that Code Red provided. It enumerates as a
    serial port. It's "unsupported", which means it's *really*
    unsupported.

    Under Windows XP, there's a small glitch. I can plug/unplug the USB
    cable, and it always makes all the proper bleep/bloop
    connect/disconnect noises. It shows up as COM6 or some such. I can
    talk to it from Hyperterminal or from a PowerBasic program. But if I
    disconnect the USB cable while the port is open, it hangs up. The fix
    is to close the program, then go to Device Manager, disable it, and
    re-enable it.

    I've seen other USB devices behave this way, too.

    Anybody know what's going on, and maybe how to fix it?
     
    John Larkin, Jul 7, 2012
    #1
    1. Advertising

  2. John Larkin

    Stephen Pelc Guest

    On Sat, 07 Jul 2012 12:19:04 -0700, John Larkin
    <> wrote:

    >Under Windows XP, there's a small glitch. I can plug/unplug the USB
    >cable, and it always makes all the proper bleep/bloop
    >connect/disconnect noises. It shows up as COM6 or some such. I can
    >talk to it from Hyperterminal or from a PowerBasic program. But if I
    >disconnect the USB cable while the port is open, it hangs up. The fix
    >is to close the program, then go to Device Manager, disable it, and
    >re-enable it.


    The problem is that a USB serial device can be closed by disconnecting
    the device, whereas a real serial port cannot. The comms program has
    to be aware of USB serial ports. HyperTerm is just too old.

    Stephen

    --
    Stephen Pelc,
    MicroProcessor Engineering Ltd - More Real, Less Time
    133 Hill Lane, Southampton SO15 5AF, England
    tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
    web: http://www.mpeforth.com - free VFX Forth downloads
     
    Stephen Pelc, Jul 7, 2012
    #2
    1. Advertising

  3. John Larkin

    Phil Hobbs Guest

    Stephen Pelc wrote:
    >
    > On Sat, 07 Jul 2012 12:19:04 -0700, John Larkin
    > <> wrote:
    >
    > >Under Windows XP, there's a small glitch. I can plug/unplug the USB
    > >cable, and it always makes all the proper bleep/bloop
    > >connect/disconnect noises. It shows up as COM6 or some such. I can
    > >talk to it from Hyperterminal or from a PowerBasic program. But if I
    > >disconnect the USB cable while the port is open, it hangs up. The fix
    > >is to close the program, then go to Device Manager, disable it, and
    > >re-enable it.

    >
    > The problem is that a USB serial device can be closed by disconnecting
    > the device, whereas a real serial port cannot. The comms program has
    > to be aware of USB serial ports. HyperTerm is just too old.
    >
    > Stephen


    I'm a big fan of Putty for this sort of job.

    Cheers

    Phil Hobbs

    --
    Dr Philip C D Hobbs
    Principal Consultant
    ElectroOptical Innovations LLC
    Optics, Electro-optics, Photonics, Analog Electronics

    160 North State Road #203
    Briarcliff Manor NY 10510
    845-480-2058

    hobbs at electrooptical dot net
    http://electrooptical.net
     
    Phil Hobbs, Jul 7, 2012
    #3
  4. John Larkin

    John Larkin Guest

    On Sat, 07 Jul 2012 22:38:23 GMT, (Stephen
    Pelc) wrote:

    >On Sat, 07 Jul 2012 12:19:04 -0700, John Larkin
    ><> wrote:
    >
    >>Under Windows XP, there's a small glitch. I can plug/unplug the USB
    >>cable, and it always makes all the proper bleep/bloop
    >>connect/disconnect noises. It shows up as COM6 or some such. I can
    >>talk to it from Hyperterminal or from a PowerBasic program. But if I
    >>disconnect the USB cable while the port is open, it hangs up. The fix
    >>is to close the program, then go to Device Manager, disable it, and
    >>re-enable it.

    >
    >The problem is that a USB serial device can be closed by disconnecting
    >the device, whereas a real serial port cannot. The comms program has
    >to be aware of USB serial ports. HyperTerm is just too old.
    >
    >Stephen


    My PowerBasic program did the same thing. What do you mean by "be
    aware" ? What would a program do the prevent the hangup? Closing the
    open port after the disconnect is apparently too late.
     
    John Larkin, Jul 8, 2012
    #4
  5. John Larkin

    -for.us Guest

    On Saturday, July 7, 2012 3:58:39 PM UTC-7, Phil Hobbs wrote:
    > Stephen Pelc wrote:
    > >
    > > On Sat, 07 Jul 2012 12:19:04 -0700, John Larkin
    > > <> wrote:
    > >
    > > >Under Windows XP, there's a small glitch. I can plug/unplug the USB
    > > >cable, and it always makes all the proper bleep/bloop
    > > >connect/disconnect noises. It shows up as COM6 or some such. I can
    > > >talk to it from Hyperterminal or from a PowerBasic program. But if I
    > > >disconnect the USB cable while the port is open, it hangs up. The fix
    > > >is to close the program, then go to Device Manager, disable it, and
    > > >re-enable it.

    > >
    > > The problem is that a USB serial device can be closed by disconnecting
    > > the device, whereas a real serial port cannot. The comms program has
    > > to be aware of USB serial ports. HyperTerm is just too old.
    > >
    > > Stephen

    >
    > I'm a big fan of Putty for this sort of job.
    >


    Putty has the same issue. It's a window problem.
     
    -for.us, Jul 8, 2012
    #5
  6. John Larkin

    hamilton Guest

    On 7/7/2012 5:00 PM, John Larkin wrote:
    > On Sat, 07 Jul 2012 22:38:23 GMT, (Stephen
    > Pelc) wrote:
    >
    >> On Sat, 07 Jul 2012 12:19:04 -0700, John Larkin
    >> <> wrote:
    >>
    >>> Under Windows XP, there's a small glitch. I can plug/unplug the USB
    >>> cable, and it always makes all the proper bleep/bloop
    >>> connect/disconnect noises. It shows up as COM6 or some such. I can
    >>> talk to it from Hyperterminal or from a PowerBasic program. But if I
    >>> disconnect the USB cable while the port is open, it hangs up. The fix
    >>> is to close the program, then go to Device Manager, disable it, and
    >>> re-enable it.

    >>
    >> The problem is that a USB serial device can be closed by disconnecting
    >> the device, whereas a real serial port cannot. The comms program has
    >> to be aware of USB serial ports. HyperTerm is just too old.
    >>
    >> Stephen

    >
    > My PowerBasic program did the same thing. What do you mean by "be
    > aware" ? What would a program do the prevent the hangup? Closing the
    > open port after the disconnect is apparently too late.
    >
    >


    There is NO program on ANY operating system that can survive a USB
    serial port disconnect.

    I have tried many, wrote some of my own.

    Windoze, Linux, CE, none can survive without a program restart.

    hamilton
     
    hamilton, Jul 8, 2012
    #6
  7. [This followup was posted to sci.electronics.design and a copy was sent
    to the cited author.]

    In article <>,
    says...
    >
    > We built a little picosecond pulse generator box with a USB interface.
    > The USB is directly into an LPC1768 NXP ARM chip, and we're using the
    > USB stack and inf file that Code Red provided. It enumerates as a
    > serial port. It's "unsupported", which means it's *really*
    > unsupported.
    >
    > Under Windows XP, there's a small glitch. I can plug/unplug the USB
    > cable, and it always makes all the proper bleep/bloop
    > connect/disconnect noises. It shows up as COM6 or some such. I can
    > talk to it from Hyperterminal or from a PowerBasic program. But if I
    > disconnect the USB cable while the port is open, it hangs up. The fix
    > is to close the program, then go to Device Manager, disable it, and
    > re-enable it.
    >
    > I've seen other USB devices behave this way, too.
    >
    > Anybody know what's going on, and maybe how to fix it?


    This is an annoying and complex problem that, as far as I know, does not
    yet have a good solution from the operating system standpoint. I am not
    totally sure what the root of the problem is but it could very well be
    related to the type of combo drivers that are used to support USB/COMM
    port type devices.

    At the company where I work we had the very same problem as you have
    described with a USB port connected into an external box where the USB
    terminated into a 1->4 USB hub and then into an FT232R chip that then
    went TTL serial port to a SiLabs MCU. The fix that was used was to
    compose the host side program as multiple threads where the thread that
    managed the "virtual serial COM port out USB" could be unloaded and
    restarted from another monitoring thread. The monitoring thread kept an
    ongoing heartbeat packet sent to the external device whenever there was
    no normal serial traffic going on. If the serial traffic, either normal
    or the heartbeat type, ever encountered an error due to sudden removal
    of the USB cable the monitoring thread would unload the thread that
    owned the crashed virtual comm port. It would then use some API calls
    that are available to automate the same things you do in device manager
    to to disable/enable the port. Then finally it could reload the thread
    that managed the Comm port whilst it waited for the device to reappear
    as connected.

    Needless to say this was a complex solution to make the usage model of
    the software a whole lot more user friendly. Without that the use of USB
    Serial devices basically sucks if you suddenly unplug the USB cable
    whilst it is in use.

    Michael Karas


    --

    Michael Karas
    Carousel Design Solutions
    http://www.carousel-design.com
     
    Michael Karas, Jul 8, 2012
    #7
  8. John Larkin

    John Larkin Guest

    On Sat, 07 Jul 2012 19:03:57 -0600, hamilton <>
    wrote:

    >On 7/7/2012 5:00 PM, John Larkin wrote:
    >> On Sat, 07 Jul 2012 22:38:23 GMT, (Stephen
    >> Pelc) wrote:
    >>
    >>> On Sat, 07 Jul 2012 12:19:04 -0700, John Larkin
    >>> <> wrote:
    >>>
    >>>> Under Windows XP, there's a small glitch. I can plug/unplug the USB
    >>>> cable, and it always makes all the proper bleep/bloop
    >>>> connect/disconnect noises. It shows up as COM6 or some such. I can
    >>>> talk to it from Hyperterminal or from a PowerBasic program. But if I
    >>>> disconnect the USB cable while the port is open, it hangs up. The fix
    >>>> is to close the program, then go to Device Manager, disable it, and
    >>>> re-enable it.
    >>>
    >>> The problem is that a USB serial device can be closed by disconnecting
    >>> the device, whereas a real serial port cannot. The comms program has
    >>> to be aware of USB serial ports. HyperTerm is just too old.
    >>>
    >>> Stephen

    >>
    >> My PowerBasic program did the same thing. What do you mean by "be
    >> aware" ? What would a program do the prevent the hangup? Closing the
    >> open port after the disconnect is apparently too late.
    >>
    >>

    >
    >There is NO program on ANY operating system that can survive a USB
    >serial port disconnect.
    >
    >I have tried many, wrote some of my own.
    >
    >Windoze, Linux, CE, none can survive without a program restart.
    >
    >hamilton


    Going into Device Manager and disabling/enabling the port fixes the
    hangup. Maybe there is a command-line equivalent. If so, I could shell
    out to that.

    This maybe?

    http://support.microsoft.com/kb/311272
     
    John Larkin, Jul 8, 2012
    #8
  9. John Larkin

    Paul Guest

    In article <jtama2$9s1$>, says...
    >
    > On 7/7/2012 5:00 PM, John Larkin wrote:
    > > On Sat, 07 Jul 2012 22:38:23 GMT, (Stephen
    > > Pelc) wrote:
    > >
    > >> On Sat, 07 Jul 2012 12:19:04 -0700, John Larkin
    > >> <> wrote:
    > >>
    > >>> Under Windows XP, there's a small glitch. I can plug/unplug the USB
    > >>> cable, and it always makes all the proper bleep/bloop
    > >>> connect/disconnect noises. It shows up as COM6 or some such. I can
    > >>> talk to it from Hyperterminal or from a PowerBasic program. But if I
    > >>> disconnect the USB cable while the port is open, it hangs up. The fix
    > >>> is to close the program, then go to Device Manager, disable it, and
    > >>> re-enable it.
    > >>
    > >> The problem is that a USB serial device can be closed by disconnecting
    > >> the device, whereas a real serial port cannot. The comms program has
    > >> to be aware of USB serial ports. HyperTerm is just too old.
    > >>
    > >> Stephen

    > >
    > > My PowerBasic program did the same thing. What do you mean by "be
    > > aware" ? What would a program do the prevent the hangup? Closing the
    > > open port after the disconnect is apparently too late.
    > >
    > >

    >
    > There is NO program on ANY operating system that can survive a USB
    > serial port disconnect.
    >
    > I have tried many, wrote some of my own.
    >
    > Windoze, Linux, CE, none can survive without a program restart.
    >
    > hamilton


    Writing your own serial emulator talking to the device driver meant for
    a USB serial chip can help SOMETIMES.

    Otherwise checking handles, and device drivers before nearly every call
    or putting timeouts on serial port transactions can help. Make sure you
    have a tiemout handler to close and open device.

    Timeouts have existed on most serial ports and printer ports on most
    operating systems for a long time. How well they work depends on the
    operating system and its drivers as well as the USB driver.

    Some drivers have a call to cycle the device from the driver, which
    might help depending on how well written the driver is.

    --
    Paul Carpenter |
    <http://www.pcserviceselectronics.co.uk/> PC Services
    <http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font
    <http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
    <http://www.badweb.org.uk/> For those web sites you hate
     
    Paul, Jul 8, 2012
    #9
  10. "John Larkin" <> wrote in
    message news:...
    >
    >
    > We built a little picosecond pulse generator box with a USB interface.
    > The USB is directly into an LPC1768 NXP ARM chip, and we're using the
    > USB stack and inf file that Code Red provided. It enumerates as a
    > serial port. It's "unsupported", which means it's *really*
    > unsupported.
    >
    > Under Windows XP, there's a small glitch. I can plug/unplug the USB
    > cable, and it always makes all the proper bleep/bloop
    > connect/disconnect noises. It shows up as COM6 or some such. I can
    > talk to it from Hyperterminal or from a PowerBasic program. But if I
    > disconnect the USB cable while the port is open, it hangs up. The fix
    > is to close the program, then go to Device Manager, disable it, and
    > re-enable it.
    >
    > I've seen other USB devices behave this way, too.
    >
    > Anybody know what's going on, and maybe how to fix it?
    >
    >
    >


    I have a similar problem with a Microchip USB stack. It's not serial
    emulation.
    If the device is unplugged the calls on the host may hang, and the whole
    host controller is hung.
    Windows will not shutdown, and is stuck on the USB hung call.
    The multithreaded routine that Mike explains seem to be the only
    solution.
    You could do a 'try' 'catch', but if there is no exception thrown then
    it's useless.

    Cheers
     
    Martin Riddle, Jul 8, 2012
    #10
  11. John Larkin

    hamilton Guest

    On 7/7/2012 8:12 PM, John Larkin wrote:
    > On Sat, 07 Jul 2012 19:03:57 -0600, hamilton <>
    > wrote:
    >
    >> On 7/7/2012 5:00 PM, John Larkin wrote:
    >>> On Sat, 07 Jul 2012 22:38:23 GMT, (Stephen
    >>> Pelc) wrote:
    >>>
    >>>> On Sat, 07 Jul 2012 12:19:04 -0700, John Larkin
    >>>> <> wrote:
    >>>>
    >>>>> Under Windows XP, there's a small glitch. I can plug/unplug the USB
    >>>>> cable, and it always makes all the proper bleep/bloop
    >>>>> connect/disconnect noises. It shows up as COM6 or some such. I can
    >>>>> talk to it from Hyperterminal or from a PowerBasic program. But if I
    >>>>> disconnect the USB cable while the port is open, it hangs up. The fix
    >>>>> is to close the program, then go to Device Manager, disable it, and
    >>>>> re-enable it.
    >>>>
    >>>> The problem is that a USB serial device can be closed by disconnecting
    >>>> the device, whereas a real serial port cannot. The comms program has
    >>>> to be aware of USB serial ports. HyperTerm is just too old.
    >>>>
    >>>> Stephen
    >>>
    >>> My PowerBasic program did the same thing. What do you mean by "be
    >>> aware" ? What would a program do the prevent the hangup? Closing the
    >>> open port after the disconnect is apparently too late.
    >>>
    >>>

    >>
    >> There is NO program on ANY operating system that can survive a USB
    >> serial port disconnect.
    >>
    >> I have tried many, wrote some of my own.
    >>
    >> Windoze, Linux, CE, none can survive without a program restart.
    >>
    >> hamilton

    >
    > Going into Device Manager and disabling/enabling the port fixes the
    > hangup. Maybe there is a command-line equivalent. If so, I could shell
    > out to that.


    OK, I just tried this, did not work.

    Win7-32bit, Teraterm 3.13

    I unpluged a Prolific USB-to-Serial Comm Port device
    Re-plugged USB device Teraterm does not work.

    On the Prolific I have a PIC board that I reset to see Copyright message.

    But, this did work:

    In Teraterm,
    Setup-> Serial port select other serial port,
    got a Tera Term: Error Cannot open COM2 [OK]

    Setup-> Serial port select original serial port
    (no error)
    Serial port works.


    >
    > This maybe?
    >
    > http://support.microsoft.com/kb/311272


    I will look into this.

    Thanks
     
    hamilton, Jul 8, 2012
    #11
  12. John Larkin

    Jasen Betts Guest

    On 2012-07-08, hamilton <> wrote:

    > There is NO program on ANY operating system that can survive a USB
    > serial port disconnect.
    >
    > I have tried many, wrote some of my own.
    >
    > Windoze, Linux, CE, none can survive without a program restart.


    I figured out how to detect the unplug of PL2303 serial ports, (I
    think by looking at the errors returned when reading the port) but
    yeah my program just closes the port, exits and gets restarted. I
    haven't tried to wait and reopen the port

    --
    ⚂⚃ 100% natural

    --- Posted via news://freenews.netfront.net/ - Complaints to ---
     
    Jasen Betts, Jul 8, 2012
    #12
  13. John Larkin

    boB Guest

    On Sat, 7 Jul 2012 22:58:49 -0400, "Martin Riddle"
    <> wrote:

    >
    >"John Larkin" <> wrote in
    >message news:...
    >>
    >>
    >> We built a little picosecond pulse generator box with a USB interface.
    >> The USB is directly into an LPC1768 NXP ARM chip, and we're using the
    >> USB stack and inf file that Code Red provided. It enumerates as a
    >> serial port. It's "unsupported", which means it's *really*
    >> unsupported.
    >>
    >> Under Windows XP, there's a small glitch. I can plug/unplug the USB
    >> cable, and it always makes all the proper bleep/bloop
    >> connect/disconnect noises. It shows up as COM6 or some such. I can
    >> talk to it from Hyperterminal or from a PowerBasic program. But if I
    >> disconnect the USB cable while the port is open, it hangs up. The fix
    >> is to close the program, then go to Device Manager, disable it, and
    >> re-enable it.
    >>
    >> I've seen other USB devices behave this way, too.
    >>
    >> Anybody know what's going on, and maybe how to fix it?
    >>
    >>
    >>

    >
    >I have a similar problem with a Microchip USB stack. It's not serial
    >emulation.
    >If the device is unplugged the calls on the host may hang, and the whole
    >host controller is hung.
    >Windows will not shutdown, and is stuck on the USB hung call.
    >The multithreaded routine that Mike explains seem to be the only
    >solution.
    >You could do a 'try' 'catch', but if there is no exception thrown then
    >it's useless.
    >
    >Cheers
    >
    >


    I have a product with the LPC2368 that uses USB CDC Virtual comm that
    works OK but see the same exact issues. We also use the LPC1768. Very
    similar these 2 processors in their peripherals AFAIK.

    I am amazed that I got it to work in the first place, and then the
    ..inf file to use with Win 7 when that had to be done.

    I have tried and tried to find out how windows can tell things about
    this USB connection to say, find out automatically what comm port it
    is on without having to manually go to device manager etc, but I think
    that anybody that ever knew anything about this stuff is either dead
    or retired. Can't find anybody that knows anything about USB driver
    internals, etc or its interaction with the OS.

    I just wish I could do a reset of windows USB software or something
    like that when USB goes to hell.

    boB
     
    boB, Jul 8, 2012
    #13
  14. John Larkin wrote:
    > On Sat, 07 Jul 2012 22:38:23 GMT, (Stephen
    > Pelc) wrote:
    >>The problem is that a USB serial device can be closed by disconnecting
    >>the device, whereas a real serial port cannot. The comms program has
    >>to be aware of USB serial ports. HyperTerm is just too old.

    >
    > My PowerBasic program did the same thing. What do you mean by "be
    > aware" ? What would a program do the prevent the hangup? Closing the
    > open port after the disconnect is apparently too late.


    The point is detecting the hangup.

    When you disconnect the USB/serial dongle, the ReadFile system call
    returns with "ok, 0 bytes read". The correct reaction is to stop the
    program at this point, close the serial port, and offer the user a
    "reconnect" button.

    With a real serial port, you can assume that if it returns "ok", it also
    returns ">= 1 byte read", and you can call ReadFile again to wait for
    the next bytes. Programs not aware of USB/serial ports will thus call
    ReadFile again, receive the same reply again, and enter an infinite loop.


    Stefan
     
    Stefan Reuther, Jul 8, 2012
    #14
  15. John Larkin

    Nico Coesel Guest

    hamilton <> wrote:

    >On 7/7/2012 5:00 PM, John Larkin wrote:
    >> On Sat, 07 Jul 2012 22:38:23 GMT, (Stephen
    >> Pelc) wrote:
    >>
    >>> On Sat, 07 Jul 2012 12:19:04 -0700, John Larkin
    >>> <> wrote:
    >>>
    >>>> Under Windows XP, there's a small glitch. I can plug/unplug the USB
    >>>> cable, and it always makes all the proper bleep/bloop
    >>>> connect/disconnect noises. It shows up as COM6 or some such. I can
    >>>> talk to it from Hyperterminal or from a PowerBasic program. But if I
    >>>> disconnect the USB cable while the port is open, it hangs up. The fix
    >>>> is to close the program, then go to Device Manager, disable it, and
    >>>> re-enable it.
    >>>
    >>> The problem is that a USB serial device can be closed by disconnecting
    >>> the device, whereas a real serial port cannot. The comms program has
    >>> to be aware of USB serial ports. HyperTerm is just too old.
    >>>
    >>> Stephen

    >>
    >> My PowerBasic program did the same thing. What do you mean by "be
    >> aware" ? What would a program do the prevent the hangup? Closing the
    >> open port after the disconnect is apparently too late.
    >>
    >>

    >
    >There is NO program on ANY operating system that can survive a USB
    >serial port disconnect.
    >
    >I have tried many, wrote some of my own.
    >
    >Windoze, Linux, CE, none can survive without a program restart.


    Not true. For starters I use the wxSerial cross platform serial port
    control stack under Windows. Secondly you should make sure the USB
    device is disconnected for at least 5 seconds. This makes windows take
    the com port down so the program gets a proper error. In my USB
    gadgets I start the USB stack after 5 seconds. Oh and I just
    re-tested with Hyperterminal. Ofcourse you need to re-open the port.

    --
    Failure does not prove something is impossible, failure simply
    indicates you are not using the right tools...
    nico@nctdevpuntnl (punt=.)
    --------------------------------------------------------------
     
    Nico Coesel, Jul 8, 2012
    #15
  16. John Larkin

    Stephen Pelc Guest

    On Sat, 07 Jul 2012 16:00:36 -0700, John Larkin
    <> wrote:

    >>The problem is that a USB serial device can be closed by disconnecting
    >>the device, whereas a real serial port cannot. The comms program has
    >>to be aware of USB serial ports. HyperTerm is just too old.
    >>
    >>Stephen

    >
    >My PowerBasic program did the same thing. What do you mean by "be
    >aware" ? What would a program do the prevent the hangup? Closing the
    >open port after the disconnect is apparently too late.


    It's been a while since I rewrote our terminal emulator for USB.
    I think that we check the error code returned by ClearCommError(), and
    check for CE_MODE. If this is set, the channel has been disconnected
    and you should close the comms.

    Stephen

    --
    Stephen Pelc,
    MicroProcessor Engineering Ltd - More Real, Less Time
    133 Hill Lane, Southampton SO15 5AF, England
    tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
    web: http://www.mpeforth.com - free VFX Forth downloads
     
    Stephen Pelc, Jul 8, 2012
    #16
  17. John Larkin

    Stephen Pelc Guest

    On Sat, 07 Jul 2012 19:03:57 -0600, hamilton <>
    wrote:

    >Windoze, Linux, CE, none can survive without a program restart.


    Would you like me to demonstrate?

    Stephen

    --
    Stephen Pelc,
    MicroProcessor Engineering Ltd - More Real, Less Time
    133 Hill Lane, Southampton SO15 5AF, England
    tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
    web: http://www.mpeforth.com - free VFX Forth downloads
     
    Stephen Pelc, Jul 8, 2012
    #17
  18. John Larkin

    hamilton Guest

    On 7/8/2012 5:31 AM, Stephen Pelc wrote:
    > On Sat, 07 Jul 2012 19:03:57 -0600, hamilton <>
    > wrote:
    >
    >> Windoze, Linux, CE, none can survive without a program restart.

    >
    > Would you like me to demonstrate?
    >
    > Stephen
    >

    Sharing you code would be helpful.

    hamilton
     
    hamilton, Jul 8, 2012
    #18
  19. John Larkin

    Stephen Pelc Guest

    On Sun, 08 Jul 2012 06:26:49 -0600, hamilton <>
    wrote:

    >> Would you like me to demonstrate?
    >>
    >> Stephen
    >>

    >Sharing you code would be helpful.


    The important bits for Windows with VC6:

    // =================================================================
    // Serial line routines - these simulate the Forth KEY KEY? and EMIT
    // No attempt at efficiency is made - the PC always gets faster, and
    // we can improve these at a later date.
    // =================================================================

    int TargetError=0; // set when target reports
    error

    // return number of characters in serial input queue
    DWORD SerKeyQ( void )
    {
    DWORD ErrorCode;
    COMSTAT cstat;

    if (ThrowReason != 0)
    {
    ErrorCode=ThrowReason;
    ThrowReason = 0;
    throw( ErrorCode );
    }
    if (bClosing)
    return 0;
    if (hCom == INVALID_HANDLE_VALUE)
    return 0;
    if (hCom == NULL)
    return 0;
    if (!bConnected)
    return 0;

    ClearCommError( hCom, &ErrorCode, &cstat );
    if( ErrorCode & CE_MODE ) // check for close; SFP009
    {
    hCom=NULL; bConnected=FALSE;
    WriteStatus( "Comms closed", 1 );
    return 0;
    }
    return (cstat.cbInQue);
    }

    // return next character in serial input queue
    char SerKey( void )
    {
    DWORD bytesdone;
    char Buffer[4];

    while ( SerKeyQ()==0 )
    {
    if (hCom == INVALID_HANDLE_VALUE)
    return 0x0D;
    if (hCom == NULL)
    return 0x0D;
    if (!bConnected)
    return 0x0D;
    // Sleep(10);
    Sleep(5);
    if (bClosing)
    return 0x0D;
    }
    ReadFile( hCom, Buffer, 1, &bytesdone, NULL );
    return (Buffer[0]);
    }

    Showing you the whole lot will show you how to write a mixed Forth and
    C application which is now being converted to pure Forth because
    debugging this sort of stuff is so much easier in Forth than in C.

    Stephen

    --
    Stephen Pelc,
    MicroProcessor Engineering Ltd - More Real, Less Time
    133 Hill Lane, Southampton SO15 5AF, England
    tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
    web: http://www.mpeforth.com - free VFX Forth downloads
     
    Stephen Pelc, Jul 8, 2012
    #19
  20. John Larkin

    John Larkin Guest

    On Sun, 08 Jul 2012 11:30:50 GMT, (Stephen
    Pelc) wrote:

    >On Sat, 07 Jul 2012 16:00:36 -0700, John Larkin
    ><> wrote:
    >
    >>>The problem is that a USB serial device can be closed by disconnecting
    >>>the device, whereas a real serial port cannot. The comms program has
    >>>to be aware of USB serial ports. HyperTerm is just too old.
    >>>
    >>>Stephen

    >>
    >>My PowerBasic program did the same thing. What do you mean by "be
    >>aware" ? What would a program do the prevent the hangup? Closing the
    >>open port after the disconnect is apparently too late.

    >
    >It's been a while since I rewrote our terminal emulator for USB.
    >I think that we check the error code returned by ClearCommError(), and
    >check for CE_MODE. If this is set, the channel has been disconnected
    >and you should close the comms.
    >
    >Stephen


    I can close the port manually, and re-open it, or kill the program and
    restart it, but the thing is still hung. I have to use Device Manager
    to disable/reenable the comm port before it will work again.
     
    John Larkin, Jul 8, 2012
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. taharehman

    ARM LPC1768 Cortex M3 Project

    taharehman, Feb 16, 2011, in forum: Embedded
    Replies:
    4
    Views:
    1,720
    Chris Burrows
    Feb 17, 2011
  2. navman
    Replies:
    50
    Views:
    2,456
    Don Y
    Jun 22, 2011
  3. navman

    LPC1768 EXT0 interrupt huge lag

    navman, Jun 23, 2011, in forum: Embedded
    Replies:
    14
    Views:
    1,980
    Rich Webb
    Jul 8, 2011
  4. navman
    Replies:
    2
    Views:
    710
    Joe Chisolm
    Jul 5, 2011
  5. DSTWRT

    USB Composite LPC1768 CDC

    DSTWRT, Aug 30, 2011, in forum: Embedded
    Replies:
    0
    Views:
    604
    DSTWRT
    Aug 30, 2011
Loading...

Share This Page