|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
i've created a sensor circuit which produces a 10v "high" when its line of sight is intercepted and a 0v "low" when its not, this circuit is then connected to the com port of my computer, how do i write a program in vb to recognise whether the input into the com port is "high" or "low"? i'm using mscomm for the link from my program to the com port, but i've totally no idea what to do with the signal coming into the com port, any help?
|
|
#2
|
|||
|
|||
|
you need to place some code into the ONCOMM event and see what comes in when you set low and set high, you should then be able to make a judgement as to what to do once you get it.
|
|
#3
|
|||
|
|||
|
Plz say more about your solution!THx!It like http://forums.devshed.com/showthrea...hlight=com+port ??
|
|
#4
|
|||
|
|||
|
I assume you have the port open and the correct baud rate set.
Declare a variable say strIn then do somthing like strIn = mscomm.input. Place this in the oncomm event. When anything comes in through the COMM port, this event is fired automatically. so when it occurs, you do somthing based on the value of strIn. SO to start simply do something like msgbox strIn to see how the value is coming in if you dont know. Then when you have figured what values you are getting for a high and a low, change your code to a case or an if statement. |
|
#5
|
|||
|
|||
|
Thx for williamcrawley's detailed reply!.
|
|
#6
|
|||
|
|||
|
Quick question: how is the device connected? Does it go through a rs232 device or did you just randomly connect the output to two commport pins?
|
|
#7
|
||||
|
||||
|
with a 10h and a 10l, I would assume RS232 - first thing to do is to use a device manager such as Hyperterminal to see if you can establish a connection to the device... second.. what is the sensor reading, and what hardware stages do you have set to determine those readings?
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#8
|
|||
|
|||
|
0v low... that isn't recommended RS232
![]() Thats why I ask... I wonder if its just two voltage levels. If so, then the commport is the wrong port, although you can fake it using a handshaking line. I thijnk the mscomm lets you check one or two of them. It would be easier to use the joyport or centronics port. A simple optocoupler arrangement would make everthing safe from voltage levels, spikes, acts-of-god etc ![]() |
|
#9
|
||||
|
||||
|
my bad.. I was a bit tipsy when I replied last night
![]() |
|
#10
|
|||
|
|||
|
You don't want to feed 10v into a TTL device port like a centronics port.
Voltage between +3v and -3v are "undefined" RS232 signal states. Whether an input in this voltage range is interpreted as a mark or a space input is not guaranteed from com port to com port. |
|
#11
|
|||
|
|||
|
Thats why I suggested an optocoupler...
Also, RS232 is not just a set of voltage levels... It's also a protocol. There's start and stop bits and of course data bits Thats not gonna happen from a 10v=on, 0v=off' device. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > mscomm |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|