Results 1 to 7 of 7

Thread: [vb.net] Turn off COMPORTS and turn it on

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2021
    Posts
    166

    [vb.net] Turn off COMPORTS and turn it on

    I have a led with a resistor soldered on a USB cable with a resistor when I put it on the USB comport1 it turns on, but I would like to turn it off or reduce to almost zero the power flow in the serial port, being able to turn it on and off, I looked for some articles but always take me to ardruinos or some other type of control board, I wanted something directly on the computer to turn the comport on and off, I am aware that this is dangerous and can damage it, but I want to test this directly on the computer is there any way to do it this with visual basic?

  2. #2
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    750

    Re: [vb.net] Turn off COMPORTS and turn it on

    You can toggle the state of the RTS line very easily. This will set it HIGH on COM1:

    Code:
    SerialPort1.PortName = 1
    SerialPort1.Open()
    SerialPort1.RtsEnable = True
    and closing the port will set it LOW:

    Code:
    SerialPort1.Close()
    Make sure you use the highest value resistor that still lights your LED. Com ports can only sink and source a couple of milliamps.

    EDIT: This assumes you are using a serial to USB converter that gives you all the standard serial port pins. It won't work with just a USB connection.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2021
    Posts
    166

    Re: [vb.net] Turn off COMPORTS and turn it on

    Quote Originally Posted by paulg4ije View Post
    You can toggle the state of the RTS line very easily. This will set it HIGH on COM1:

    Code:
    SerialPort1.PortName = 1
    SerialPort1.Open()
    SerialPort1.RtsEnable = True
    and closing the port will set it LOW:

    Code:
    SerialPort1.Close()
    Make sure you use the highest value resistor that still lights your LED. Com ports can only sink and source a couple of milliamps.

    EDIT: This assumes you are using a serial to USB converter that gives you all the standard serial port pins. It won't work with just a USB connection.
    well I used a cut USB cable with the led and the resistor so I assume it will work when I'm at home.

  4. #4
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    750

    Re: [vb.net] Turn off COMPORTS and turn it on

    It's not going to work without a serial to USB converter. USB is a bus, not a port.

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: [vb.net] Turn off COMPORTS and turn it on

    There is the serial bus portion of USB but there is also pins to provide ground and power for the device plugged in.
    I assume he is hooking the LED to the power pin. The USB device can provide a variable amount of current, which is usually negotiated by the device.
    There is probably a way to turn the power off and on programmatically, probably by enabling or disabling the USB port, but I haven't researched it.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  6. #6
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    750

    Re: [vb.net] Turn off COMPORTS and turn it on

    You can turn off a USB device, but I doubt there is an easy way to turn off the +5 volts on an individual USB port.

  7. #7
    Addicted Member
    Join Date
    Nov 2011
    Posts
    229

    Re: [vb.net] Turn off COMPORTS and turn it on

    Probably one of the better options is a USB to UART cable or development board that exposes its I/O. One of the more popular manufacturers is FTDI who make a 5v and 3.3v.

    Here is a link to a variety but if you google you can find them at many online stores:- https://ftdichip.com/product-categor...-cable-series/

    Once you have the cable then FTDI have libraries for VB.net and C# (with examples) that allow you to control the I/O lines from a PC.

    The methods include being able to configure the I/O as output and to switch them on and off

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width