Solved

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

Posted on 2004-08-23
4
1,500 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

726 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