OPC and VB6 MSCOMM COM port

glideratio

Member
Join Date
Feb 2009
Location
US
Posts
62
Hi all,
has anyone used MSCOMM in VB6 with OPC ?

I have a serious issue with KEPServerEX4.0, VB6 and MSCOMM (Microsoft Comm Control 6.0).
I'm using an MSCOMM1 in my application.
The task is to open a COM1 port in the event of OPC tag change.
Now, the problem is when I do it like that the COM port doesn't open. The program goes to debug mode.
I wrote a function to test whether the port is open or closed and the program says that the port is open and closed at the same time.
If I use just a regular command button on the form to open the COM1 port it works fine but it doesn't work if COM1 port opening Sub is triggered by an OPC tag.
I'm wondering is this a MicrosoftVB6 or Kepware or OPC bug ?
The code is as follows:
----------MSCOMM Sub-----------
Public Sub SF401_BalanceOpenPort()
MSComm1.CommPort = 1
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
' Tell the control to read entire buffer when Input
' is used.
MSComm1.InputLen = 0
' Open the port.
MSComm1.PortOpen = True

End Sub
---------------------------------
......
---------------------------------
Sub ConnectedGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, _
ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date) 'OPC Data change sub that updates the values
 
Dim X As Integer
For X = 1 To NumItems
Select Case ClientHandles(X)
Case 2
If ItemValues(X) = 20 Then
Call SF401_BalanceOpenPort 'this is where port opening sub is activated
End If
End Select
Next X
End Sub
---------------------------------
Can someone test this on his PC ?
Thank you
regards
 
What is the error that you get?

I would add to your sub:
'If Not MSComm1.PortOpen Then'

to make sure the port is not already opened.

Do a test:
Instead of directly calling the sub. from the datachange event, have the data change event start a short Timer. when the timer expires, then call the sub.
 
Tried both.
The error is:

Runtime error "8005"
Port already open
--------------------------------
I've also added a 'If Not MSComm1.PortOpen Then'
and what hapens is the program is going through this and then throws the same error.
Looks like it is open and closed at the same time
--------------------------------
Tried with timer - same story. Error
Runtime error "8005"
Port already open

Any other thoughts?

I'm sure Microsoft won't care if i write them about this error because it work fine without OPC.

Is there a technical support in OPC foundation or similar where i can address my question?
 
1 first if not close,close it

2 then if not open,open it

3 never reopen it in your program.
------------------

It doesn't work my friend.
I have a good experience in VB and I have tried the suggested stuff many times.

Any other ideas ?

Can someone try it on his pc using Kepware OPC and VB6 ?
 
Unless KepserverEx is using the COM port in one of its channels it is not something that the server is doing. My sugestion, and good coding practice, is to not make this call from the Data callback (data change event). Set a trigger that will be processed by a timer and let the call back event close. I suspect you will find that it works then.
 
I have noticed that in your ConnectedGroup_DataChange event handler sub Call SF401_BalanceOpenPort is called from within a For... Next loop.

Are you sure you are not trying to open the same port more than once?
 
Unless KepserverEx is using the COM port in one of its channels it is not something that the server is doing. My sugestion, and good coding practice, is to not make this call from the Data callback (data change event). Set a trigger that will be processed by a timer and let the call back event close. I suspect you will find that it works then.

I already tried to start a timer first instead of sub call. When timer is up it's calling the sub. It didn't work either.

Fred can you please give an example ?

I tried the following and it didn't work:

------------------------------------------

----------MSCOMM Sub-----------
Public Sub SF401_BalanceOpenPort()
MSComm1.CommPort = 1
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
' Tell the control to read entire buffer when Input
' is used.
MSComm1.InputLen = 0
' Open the port.
MSComm1.PortOpen = True

End Sub
---------------------------------
......
---------------------------------
Sub ConnectedGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, _
ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date) 'OPC Data change sub that updates the values
 
Dim X As Integer
For X = 1 To NumItems
Select Case ClientHandles(X)
Case 2
If ItemValues(X) = 20 Then
Timer1.enable=true
End If
End Select
Next X
End Sub

Sub Timer1 ()
Call SF401_BalanceOpenPort()
end sub
------------------------------------------
 
How to do it then ?
I need to open a COM port on event when a sensor goes from state false to true ?
Can you please give an example ?
 
Actually I have added a counter to the sub where COM port is called and the counter shows that this sub was called only one time ... there is No multiple calls from DataChangeEvent. It throws an error at the first attempt.

Thoughts?
 
So in the IF statement the MSCOMM1 object thinks the port is closed.
But when it actually tries to open the port, you get the error.

It does sound like another program has the port open.
I think there are some windows calls you can use to find out, unfortunately I don't know what they are, I work in .net land now.

It might be easier to use a port sniffer, something like this:
http://www.serial-port-monitor.com/




Tried both.
The error is:

Runtime error "8005"
Port already open
--------------------------------
I've also added a 'If Not MSComm1.PortOpen Then'
and what hapens is the program is going through this and then throws the same error.
Looks like it is open and closed at the same time
--------------------------------
Tried with timer - same story. Error
Runtime error "8005"
Port already open

Any other thoughts?

I'm sure Microsoft won't care if i write them about this error because it work fine without OPC.

Is there a technical support in OPC foundation or similar where i can address my question?
 
Fixed !!!

thanks to Gerry M for http://www.serial-port-monitor.com

I ran this Com port monitoring tool and it showed that when event was happening RSLINX classic was openning the port at the same time as VB6
"
Port opened by process "RSLINX.EXE" (PID: 5264)
"I looked in RSLINX and it was showing that there is a RS232 devices driver AB_DF1 is running on COM port 10 (I used it for Lantronix Serial To Ethernet device) but the port was in status - Conflict. So I deleted it from RSLINX drivers and VB6 opened the port without problems.
Thanks to all.
 

Similar Topics

G'day there, I want to send real time data to a VB6 application. It works in excel thanks to a previous response from member - plastic, but I...
Replies
0
Views
3,807
Hello I've been using RSLinx OPC Server to read/write tag values to/from a VB6 program, but we've been wanting to move to the...
Replies
4
Views
6,886
I am running CCW 13 trying to upload to a micro 820 vers.12 I get an output message OPC server is unable to load project controller. Please help!
Replies
5
Views
255
I know nothing about simaticnet OPC server. I do know Kepware. I would only ever scale raw to engineering in the PLC, but it is possible to scale...
Replies
5
Views
223
If anyone has a crack for IBH OPC Server, please send it to: [email protected] Urgently. Thanks in advance!
Replies
1
Views
134
Back
Top Bottom