Results 1 to 18 of 18

Thread: [RESOLVED] Ports

  1. #1

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Resolved [RESOLVED] Ports

    I have this light sensor circuit that will return positive voltage or negative voltage. I want to plug it into the 9-pin D-Sub port on my computer. I already have a male connector. How do I connect the circuit to the D-Sub connector, and how do I read the value and convert it to a Boolean in a program? How do I set up the cables? It only returns one 1 or 0 value. Is it possible, even?

  2. #2

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    Ok, I'm going to switch to USB because it seems easier to hook up to the other end. I've got the circuit part of it working, now. The device will return around +5V or 0V. How do I convert this into a Boolean, and how do I read the port?

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Ports

    To read from a USB port, you will need a driver. The sensor manufacturer may provide examples on how to read the data using the USB port.

  4. #4

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    I made the sensor.

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Ports

    Well then ask yourself for the code example .

    I am fairly certain you need some sort of driver to handle the USB communication. You might be able to do something with the serialport control, but I would be doubtful.

  6. #6
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: Ports

    Not sure what version VB you use. You can use the handshake lines of the serial port to monitor. Not sure what you mean by USB port. You mean a convertor from serial to USB? If not you need a microcontroller with USB and a driver for Windows.
    If you want to go via serial look at this old tread. Its however in VB6 and needs to converted to .NET.
    http://www.vbforums.com/showthread.p...61#post2407061

  7. #7

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    Is there a class I can use that can read raw values?

  8. #8

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    Should I use D-Sub instead? Is that easier to work with on the programming side? If I should switch, does anyone know where I can find a pinout for it? I've already googled it and I can't find anything.\

    Also, how do I use the SerialPort control?

  9. #9
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Ports

    Did you try googling Serial Port Pinout?

    The D-Sub is the type of connector used and has nothing to do with how data is transmitted. Serial data is normally used with d-sub connector with either 9 or 25 pins (although you really only need 2 pins to send data, 3 to send and receive). The serial port connector on your computer is a 9 pin D-sub.

    Anyway... the first link on that search talks about the serial port. I would probably use the ClearToSend line, and have your device set it (or reset it) depending on the boolean value you need to transmit. Then in software, drop a serialport object on the form and check the CTS line using ...

    vb Code:
    1. Private Sub SerialPort1_PinChanged(ByVal sender As Object, ByVal e As System.IO.Ports.SerialPinChangedEventArgs) Handles SerialPort1.PinChanged
    2.         If e.EventType = IO.Ports.SerialPinChange.CtsChanged Then
    3.                 'doing something
    4.  
    5.         End If
    6.     End Sub

    As far as using usb to transmit a single bit would be overkill. You don't simply send a bit on usb... you send packets with predifnedprotocols.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  10. #10

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    No, I googled D-Sub pinout.
    I meant that USB has specific wires for power, data + and data -, and I had no idea how to connect D-Sub. I thought I should use USB because it seems simpler on the device side. I've never done anything like this before, so I didn't know that USB was more complicated.

    I have no idea how to use the ClearToSend line or anything from my device, can you help?

  11. #11

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    On the pinout that you mentioned, it says that only 3 pins out of 9 are fixed use. Can I just ignore the rest, then? Also, what do I use for a power source?

    EDIT:
    Can I also ignore the Transmit Data pin, too, because I won't use it?

  12. #12
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Ports

    assuming you are using the 9 pin connector....

    You must connect pins 5 (ground) to your sensor or nothing else will work. Since you only need to convey a single bit of information (i.e your boolean variable) you only need to be concerned with the CTS line (pin 8) and ground. So you connect your sensor's ground and output to the the D-sub ground and CTS connections.

    You say you sensor puts out +5V and 0V, so it may work, but may not you'll have to just try it. (the rs232 standard says the logic states are +3V or higher and or -3V or lower)

    Unless you are savvy with electronics, power you sensor from an independent source... a wall transformer or batteries.
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  13. #13

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    I can adapt it for +3V and -3V, no problem. Thanks!

  14. #14
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Ports

    Quote Originally Posted by minitech View Post
    I can adapt it for +3V and -3V, no problem. Thanks!
    i would recommend you read the rs232 spec (or at least part of it) and adapt to it. the +-3V is minimum (I think)
    GL
    Kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  15. #15

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    So ground would be the - side and CTS is the input?

  16. #16

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    Oh, and could you give me some example code for reading the values? I've found some online, but they don't explain what BaudRate and other obscure properties mean.

  17. #17
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Ports

    I assume the obscure property you mean are parity, data bit, stop bits, baud etc. These are all settings for sending data on the Tx and Rx lines, none of which are relevant for your application. The only serial port setting that matters is the port number.
    And sorry, the only code I can give you is what I post earlier, but it should be enough.

    I would also mention that if you miss wire things, you run the risk of blowing your port permanently.

    <declaimer>
    If you are not certain about what you are doing regarding hardware, I would suggest using a usb to serial port converter, that way if you make a mistake, you only blow the converter.
    </disclaimer>
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  18. #18

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Ports

    Wait, according to the pinout CTS is Clear To Send. So which one do I use for input?

    Should I use Tx?

    EDIT:
    Ohh, so use the CtsHolding value to get the Boolean? That's much easier. Thanks, I'll try it out soon!
    Last edited by minitech; Sep 19th, 2009 at 07:25 PM.

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