Solved

A Visual Basic Source Code is required to be converted into powerbuilder 7.

Posted on 2004-08-23
4
1,486 Views
Last Modified: 2013-12-26
Hi experts:

I am converting a vb source code into pb7 and having problems in some area.

Here is the vb source code:

'Inp and Out declarations for port I/O using inpout32.dll.

Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32"  (ByVal PortAddress As Integer)  As Integer
   
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32"  (ByVal PortAddress As Integer,  ByVal Value As Integer)

Dim Rpm, rpm1 As Integer
Dim picksinsec As Integer
Dim picks, picks1 As Integer
Dim address As Byte
Dim secrpm(10) As Byte
Dim cunt, a As Byte                      
Dim elevenbytes(11) As Byte          (***)
Dim checksum As Integer

Private Sub Form_Load()
    Out &H378, 0
    address = 1
    Rpm = 0
    TxtAdd.Text = address
End Sub

Private Sub Timer1_Timer()
    cunt = cunt + 1
    secrpm(cunt) = picksinsec * 6
    If cunt = 9 Then
        cunt = 0
    End If
    picksinsec = 0
    Rpm = 0
    For a = 0 To 9
        Rpm = Rpm + secrpm(a)
    Next a
    elevenbytes(0) = address
    elevenbytes(1) = readvalue
    elevenbytes(2) = 0
    elevenbytes(3) = Rpm And 255
    rpm1 = Rpm
    rpm1 = rpm1 / 256
    elevenbytes(4) = rpm1 And 255       (***)
    elevenbytes(5) = picks And 255      
    picks1 = picks
    picks1 = picks1 / 256
    elevenbytes(6) = picks1 And 255
    elevenbytes(7) = 0
    elevenbytes(8) = 0
    elevenbytes(9) = 0
    For a = 0 To 9
        checksum = checksum + elevenbytes(a)
    Next a
    checksum = checksum Mod 256  (***)
    elevenbytes(10) = checksum
    Debug.Print "Address : " & elevenbytes(0)
    Debug.Print "Error Code : " & elevenbytes(1)
    Debug.Print "Blank : " & elevenbytes(2)
    Debug.Print "RPM Low: " & elevenbytes(3)
    Debug.Print "RPM High: " & elevenbytes(4)
    Debug.Print " Picks Low : " & elevenbytes(5)
    Debug.Print " Picks Middle : " & elevenbytes(6)
    Debug.Print " Picks High : " & elevenbytes(7)
    Debug.Print " Blank : " & elevenbytes(8)
    Debug.Print " Blank : " & elevenbytes(9)
    Debug.Print " Checksum : " & elevenbytes(10)
End Sub

Private Sub Timer2_Timer()
    readvalue = Inp(&H379) And &H78  (***)
    Text2.Text = readvalue
    picksinsec = picksinsec + 1
    picks = picks + 1
    TxtRPM.Text = Rpm
    Txtpicks.Text = picks
End Sub

The prblem areas for me are (marked above as (***)):

Dim elevenbytes(11) As Byte          (***)
elevenbytes(4) = rpm1 And 255       (***)
checksum = checksum Mod 256  (***)
readvalue = Inp(&H379) And &H78  (***)

and how to declare following functions in pb7.
Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32"  (ByVal PortAddress As Integer)  As Integer
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32"  (ByVal PortAddress As Integer,  ByVal Value As Integer)

0
Comment
Question by:Mateen
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Vikas_Dixit earned 500 total points
ID: 11875167
Hi,

The functions can be declared as :

Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32"  (ByVal PortAddress As Integer)  As Integer
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32"  (ByVal PortAddress As Integer,  ByVal Value As Integer)

Are to be declared as :

public Function integer Inp(int PortAddress) Library "inpout32.dll" Alias for "Inp32"
Public Subroutine Out (int PortAddress) Library "inpout32.dll" Alias for "Out32"

etc.

Dim elevenbytes(11) As Byte          (***)
As :
char elevenbytes[11]


rest of them are bitwise operations.. if you are using pfc, these methods are available in the numerical service..

elevenbytes(4) = rpm1 And 255       (***)
is just converting the rpm1 ( an integer ) to byte and assigning it to 4th element  ( assuming array index starts at 1 like pb). so this should work :

elevenbytes[4] = rpm1

checksum = checksum Mod 256  (***)

I think there is a function for Mod ( ) in powerbuilder.. please look in PB help..

readvalue = Inp(&H379) And &H78  (***)

are :
readvalue = Inp(889) And 120  ( 01111000) ** for this AND operation you may need to take help of PFC..

Hope this is of some help..
Regards
Vikas






0
 

Author Comment

by:Mateen
ID: 11879992
Hi vikas:

Thanks 4 your answer.
I want to know  if char in pb is exact equivalent of byte in vb.
0
 
LVL 8

Expert Comment

by:Vikas_Dixit
ID: 11885504
Not sure.......... It can be 2 bytes also......

Instead you can also use a blob of specified size..... and use the blob function ( blobmid etc ) to access specific locations.
a blob of size  1 should be equal to one byte.......

Regards
--Vikas
0
 

Author Comment

by:Mateen
ID: 11889777
Hi vikas:
This issue may take very long.

readvalue = Inp(889)  suggested by u is working. It is giving value of 128  whereas it should have been 8
and this value of 8 is correctly returned by the statement  readvalue = Inp(&H379) And &H78  in vb.
I am unable to use and operator.

I am also unable to code  Out &H378, 0.

Please note that the out subroutine has got two arguments.

Thanks 4 your kind co-operation.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now