Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using Mscomm32.ocx for serial port communication

2,524 views
Skip to first unread message

Hans

unread,
Dec 22, 2007, 4:48:34 AM12/22/07
to
Hi all,

I have a cash drawer and and opener device connected to a USB port that is
bridged to a COM16 serial port. According to the vendor I just need to send
char(27)+char(53) down the serial port andit will open the cash drawer.

They provide a MS Excel VBA sample which uses MScomm32.ocx and it works. But I
have difficulties using that ocx file in PB 8.

Is there someone here who can give me the required steps to implement and use
that ocx in PB? Even better would be a code example.

Someone suggested to create a window, do insert-->control-->OLE and select the
MScomm32.ocx file. So I did that and created a command button with the code to
open the com port and send the string. But all I get is an error of something
like "invalid access of object property".

If someone could help me with this that would be great.

Thanks for thinking about it.

Hans
---== Posted via the PFCGuide Web Newsreader ==---
http://www.pfcguide.com/_newsgroups/group_list.asp

fisher

unread,
Dec 22, 2007, 4:55:45 AM12/22/07
to
Hi Hans,

First, could you please help us help you and give more details about
your env. - PB Version/Build. Mscomm32 version ?

Finally could you send code you have for opening port and sending codes ?
Regards


Hans pisze:

Hans

unread,
Dec 22, 2007, 5:33:13 AM12/22/07
to
Sorry, here's the details:

Powerbuilder version 8.0.3 build 9704
Mscomm32.ocx version 6.0.81.69

The prodedure was this:

in VBA insert a use form
click on "additional controls" on the controls window
select the ocx.file from the following dialogue
insert the new control on the user form
right click the new control and select properties
set RThrshhold to 1
set SThreshhold to 1
set Inputmode to 1
insert a command button on the use form
run the code

And here's the code

'*** Open Com port ***
Sub open_com(cm As Integer)

Dim pp As Integer, temp As String, outbyte(1) As Byte, t As Single, rsdata() As
Integer

'Get com selected text
temp = "com16"

'Check text first
If Left$(temp, 3) <> "com" Then
GoTo comerr
End If

'Check com number
pp = Val(Right$(temp, Len(temp) - 3))
If pp = 0 Or pp > 16 Then
GoTo comerr
End If

'Open com port
MSComm1.CommPort = pp
MSComm1.InputMode = 1
MSComm1.Settings = "9600,n,8,1"

'Check com port exist ?
On Error Resume Next
MSComm1.PortOpen = True
If Err Then
MsgBox "This Com port not exist on this system !"
GoTo subend
End If


'If error happend (ex: no RS232 data in ) then end
On Error GoTo subend

'Set first byte = [ESC] (ASCII code is 27)
outbyte(0) = 27
'Set second byte = option ASCII (See the manual for command)
outbyte(1) = cm

'Send data to com port
MSComm1.Output = outbyte

'If command is detect status
If cm = 58 Or cm = 59 Then

'Clear label
Select Case cm
Case 58
'LabelS1.Caption = "Status :"
Case 59
'LabelS2.Caption = "Status :"
End Select

'Delay for receive data
t = Timer
Do While t + 0.5 > Timer
DoEvents
Loop

'Get data from com
rsdata = MSComm1.Input

'Check command "[ESC]"
If rsdata(0) = 27 And (rsdata(1) = 52 Or rsdata(1) = 53) Then

If rsdata(2) = 65 Then
temp = "Status : Closed"
End If

If rsdata(2) = 66 Then
temp = "Status : Opened"
End If

'Show status
Select Case cm
Case 58
'LabelS1.Caption = temp
Case 59
'LabelS2.Caption = temp
End Select

End If

End If
GoTo subend

'Com port open error
comerr:
MsgBox "Open Com port Error !"


' End of Sub
' Check com port open ? if yes then close com port
subend:
If MSComm1.PortOpen Then
MSComm1.PortOpen = False
End If

End Sub

On 22 Dec 2007 01:55:45 -0800,
in sybase.public.powerbuilder.ole-ocx-activex

Roland Smith [TeamSybase]

unread,
Dec 26, 2007, 11:27:18 AM12/26/07
to
I tried some things and this works. ole_1 is the control which I created and
placed on the window.

Boolean lb_rtn

ole_1.Object.CommPort = 16
ole_1.Object.InputMode = 1
ole_1.Object.Settings = "9600,n,8,1"

// open the port
try
lb_rtn = ole_1.Object.PortOpen = True
catch ( runtimeerror rte1 )
MessageBox("Port Open Failed", rte1.Text, StopSign!)
Return
end try

// close the port
lb_rtn = ole_1.Object.PortOpen = False

Return


Hans

unread,
Dec 30, 2007, 11:26:31 AM12/30/07
to
Hi Roland,

Thanks for responding. Unfortunately this doesn't work for me.

I put the MSCOMM32.ocx into c:\windows\system32, put an OLE control on a window
(insert-->control-->ole, created a command button and for that a script with the
commands you suggested. But it comes back with "invalid external function
property for the first command.

I did NOT declare any global functions. So the question is, did you and wich
ones?

Regards

Hans


On 26 Dec 2007 08:27:18 -0800,
in sybase.public.powerbuilder.ole-ocx-activex

Hans

unread,
Dec 30, 2007, 11:31:22 AM12/30/07
to
Sorry, I forgot to mention that when creating the control, on the selection
window I chose "create from file" and "place an icon".


Hans


On 26 Dec 2007 08:27:18 -0800,
in sybase.public.powerbuilder.ole-ocx-activex
Roland Smith [TeamSybase] <rsmith_at_trusthss_dot_com> wrote:

Roland Smith [TeamSybase]

unread,
Dec 31, 2007, 8:24:10 AM12/31/07
to
Did you run regsvr32 on MSCOMM32.ocx ?

I did this from a new app specifically for trying this out. Here are my
steps:

Open the New window and go to the 'PB Object' tab
Choose Standard Visual and click OK
Choose olecontrol and click OK
Switch to the Insert Control tab
Scroll down and select Microsoft Communications Control
Click OK
Save the object as u_mscomm32
Place the object on a window with the control name ole_1

"Hans" <m...@anywhere.com> wrote in message news:4777c6b7$1@forums-1-dub...

Hans

unread,
Dec 31, 2007, 12:31:40 PM12/31/07
to
That is GREAT!!!

Not sure what I did wrong when I tried it but it works!!!

Only thing I can't do is read from the port. The connected device sends a status
back wich is 'ESC + 60' if the drawer is open.

In order to read I did this (after opening the port of course):

blob rsdata
string data

rsdata = ole_1.object.input
data = string (rsdata)

The program runs over the statements and does not give any error message but the
variabe is empty.

If you could help me also with this I would be infinitely grateful.


On 31 Dec 2007 05:24:10 -0800,

Roland Smith [TeamSybase]

unread,
Jan 3, 2008, 8:00:11 AM1/3/08
to
Hans,

I did some searching and found this.

Set RThreshold and SThreshold to 1.

Add this code to the OnComm event of the object:

Constant Integer comEvReceive = 2

choose case this.Object.CommEvent
case comEvReceive
MessageBox("Received", String(this.Object.Input))
end choose


Roland Smith [TeamSybase]

unread,
Jan 3, 2008, 8:07:17 AM1/3/08
to
Take a look at this example:

http://www.developerfusion.co.uk/show/21/6/

With RThreshold and SThreshold to 1 the event will get triggered as each
byte is received. It might be better to set the threshold to the number of
bytes expected.


"Roland Smith [TeamSybase]" <rsmith_at_trusthss_dot_com> wrote in message
news:477cdc5b$1@forums-1-dub...

Hans

unread,
Jan 3, 2008, 5:37:02 PM1/3/08
to
Thanks Roland,

I'll try it tomorrow first thing. Would be smashing if it worked. I'm almost
down to my nerves. :-)

On 3 Jan 2008 05:00:11 -0800,


in sybase.public.powerbuilder.ole-ocx-activex
Roland Smith [TeamSybase] <rsmith_at_trusthss_dot_com> wrote:

Hans

unread,
Jan 10, 2008, 7:25:40 AM1/10/08
to
Hi Roland,

I tried your proposal but unfortunately it did not work out for me.

Meanwhile the supplier of the CasH Drawer has provide dme with a DLL that works
and the problem is solved.

Thank you again for your help.

Best regards

Hans

On 3 Jan 2008 05:07:17 -0800,
in sybase.public.powerbuilder.ole-ocx-activex

0 new messages