Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mscomm HELP

Status
Not open for further replies.

Newf69

Technical User
Mar 27, 2003
7
CA
I need a way to detect if there is a voltage of 3.5V dc present on the Com port input line.

I have used a comparitor to convert the 3.5Vdc to serial data. What i need to know is what command do i have to use to check the com port for that 3.5 Vdc or see if there is nothing there???????

Thankx
 
What exactly is the output of the comparitor?

You see, how a COM port works is that it sees a value on the pins of the port. This value can be 0 VDC ( essentially ground ) and this is seen as a LOW. A HIGH would be +5VDC.

Since 3.5V is between these two, the port might not read this correctly as a HIGH state on a pin.

So, if your comparitor puts out 5V when you have 3.5 coming into it, and 0 volts for 0 coming into it, what you can do is connect the output up to one of the signal lines ( such as DSR ) and ground, and change the state of this line.

In the program, you would check the status of that line like this ( with MSComm1 being the name of the com control on your form):

If MSComm1.DSRHolding = True Then
' code here for line is HIGH
Else
' code here for line is LOW
End If


Hope this helps,

Robert
 
Ok I can get that to work!! Now can you help me \.
I need to know what to type in the MSComm1.output = ???
to get "Caution Ahead" to be displayed on the LCD

Thankx
 
What do i use to display Caution Ahead on the Display??

I'm trying MSComm1.output = ???

Will this work or do i use some other code??

Thankyou
 
That's a bit more difficult. What type of interface does the LCD display have? Does it accept RS-232 serial data? In what format? Do you have a spec sheet or anything?

LCD displays don't just "hook up" to a RS232 port. Most displays are matrix type devices, and you have to have a driver that accepts the data and puts the appropriate message on the screen.

Robert
 
I have no trouble writing to the display it has it's own microcontroller

I just use SER_SEND dll before but i don't know how to Put that in the code

Here is what i have so far
Option Explicit
Private Declare Function SER_OPEN& Lib "SERSEN04.DLL" (ByVal commPort&, ByVal baudRate&)
Private Declare Function SER_CLOSE& Lib "SERSEN04.DLL" ()
Private Declare Sub SER_SEND Lib "SERSEN04.DLL" (theString$)
Private Declare Sub SER_RAWSEND Lib "SERSEN04.DLL" (theString$)
Dim intEnd As Integer

Private Sub cmdExit_Click()
intEnd = 1
End

End Sub

Private Sub cmdStart_Click()


Do Until MSComm1.DSRHolding = True Or intEnd = 1
Delay 1
Dim message
Dim message2
Loop
If MSComm1.DSRHolding = True Then
MSComm1.Output = message
message = Text1.Text
Else

If MSComm1.DSRHolding = False Then
MSComm1.Output = message
message2 = Text2.Text
End If
End If
End Sub

Private Sub Form_Load()
frmCaution.Top = (Screen.Height - frmCaution.Height) / 2
frmCaution.Left = (Screen.Width - frmCaution.Width) / 2

End Sub


Private Sub Delay(HowLong As Date)
Dim TempTime As Date
TempTime = DateAdd("s", HowLong, Now)
While TempTime > Now
DoEvents 'Allows windows to handle other stuff
Wend

End Sub
Thnakyou
 
>>You see, how a COM port works is that it sees a value on the pins of the port. This value can be 0 VDC ( essentially ground ) and this is seen as a LOW. A HIGH would be +5VDC.

That would be a parrelel port high-low difference.


It is my understanding that high-low levels on a COM port vary from -12 to 12 Volts.
Greetings,
Rick
 
LazyMe,

You are correct. I'm getting my ports mixed up...

Newf69,

Now that I have been straightened out, the voltage you will need outputted from your comparitor will need to be 12VDC, not 5VDC as I said before.

On to the code.

I don't think the SER_Send DLL that you show is necessary. Is it just supposed to open and close a port, and send data? You do that with the MSComm control, so you don't need an extra DLL for that.

You need to add a reference to the MSCOMM control in your project, then place one of them on your form. Then you can open the port that you want and read / transmit data.

You have to open the port before it will send anything out.

Please look through the MSDN help and look up the MScomm control, and read up on it.

You are sending the output of the Mscomm control as the variable "message", but you don't set that variable until after you are doing the output. You have to set the variable *before* you send it.

Plus, you are setting the variable "message" but outputting "message2" at one point.

What is the line "Delay 1" for?

Also, you have:

Do Until MSComm1.DSRHolding = True Or intEnd = 1

As a check for your loop. If you think that pressing the exit key will set that intEnd variable when your loop is running, it will not, because you will not get the event for the button click until after the loop ends. You could use DoEvents in the loop to get the button click though, but you should avoid that if possible. I would use a timer to check the state of the DSR line, and not put the code in a loop.

The other problem is that the next line of code in your exit click event is "END". The program will stop right there.

Incidentally, you should practically never use END to stop a program. Use "Unload" instead.

If you still have questions, then please ask us.

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top