|
-
Sep 14th, 2009, 09:06 PM
#1
Thread Starter
Stack Overflow moderator
[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?
-
Sep 15th, 2009, 01:08 PM
#2
Thread Starter
Stack Overflow moderator
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?
-
Sep 15th, 2009, 03:52 PM
#3
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.
-
Sep 15th, 2009, 05:34 PM
#4
Thread Starter
Stack Overflow moderator
-
Sep 15th, 2009, 06:22 PM
#5
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.
-
Sep 16th, 2009, 02:19 AM
#6
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
-
Sep 16th, 2009, 06:37 PM
#7
Thread Starter
Stack Overflow moderator
Re: Ports
Is there a class I can use that can read raw values?
-
Sep 17th, 2009, 05:47 PM
#8
Thread Starter
Stack Overflow moderator
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?
-
Sep 17th, 2009, 07:06 PM
#9
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:
Private Sub SerialPort1_PinChanged(ByVal sender As Object, ByVal e As System.IO.Ports.SerialPinChangedEventArgs) Handles SerialPort1.PinChanged
If e.EventType = IO.Ports.SerialPinChange.CtsChanged Then
'doing something
End If
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
-
Sep 18th, 2009, 01:08 PM
#10
Thread Starter
Stack Overflow moderator
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?
-
Sep 18th, 2009, 01:10 PM
#11
Thread Starter
Stack Overflow moderator
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?
-
Sep 18th, 2009, 02:56 PM
#12
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
-
Sep 18th, 2009, 08:46 PM
#13
Thread Starter
Stack Overflow moderator
Re: Ports
I can adapt it for +3V and -3V, no problem. Thanks!
-
Sep 18th, 2009, 08:49 PM
#14
Re: Ports
 Originally Posted by minitech
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
-
Sep 18th, 2009, 08:53 PM
#15
Thread Starter
Stack Overflow moderator
Re: Ports
So ground would be the - side and CTS is the input?
-
Sep 18th, 2009, 08:57 PM
#16
Thread Starter
Stack Overflow moderator
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.
-
Sep 18th, 2009, 09:09 PM
#17
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
-
Sep 19th, 2009, 06:56 PM
#18
Thread Starter
Stack Overflow moderator
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|