As we know that VB can’t program to connect through Parallel Port directly. In the book, there will be explanation that we create DLL files that can write by using whatever language that has the function connecting to port. This website I have ever presented programming by C++, using Inp function for getting value along port and out is sending value out along port.

So now, we will introduce creating DLL file (Dynamic LInk LIbrary) by Borland Delphi, using Assembly programming to help for connecting through port by using the function of Assembly.

IN AL,DX

Get value at port’s position according to value in DX that is kept at AL

OUT DX,AL

Send value in AL to port’s position according to value in DX

push dx

mov dx,AddressPort ; AddressPort variable that get value from calling function

mov al,ValueByte ; ValueByte variable that get value from calling function

out dx,al

pop dx

  1. In the part of INPUT is the function of Assembly, reading value from input port that has value of port at 0 - 65,535 that will be used in Delphi that has the function like this,

push dx

mov dx,AddressPort ; AddressPort variable that get value from calling function.

in al,dx

mov ValueByte,al ; ValueByte variable that send value back when call function.

pop dx

So now, we begin in the part of Delphi. Start opening New file in Pascal. We will not mention the other details, we will show just Code that is the function only, then copy to put on code in Delphi that in the part of output per is programmed as Procedure. For input, using programming as Function.

Library InOutVB; { set library name}

Uses SysUtils;

{procedure for sending value at port}

Procedure

OutVB(AddressPort:smallint ; ValUse:smallint);stdcall;export

Var

ValueByte:Byte;

Begin

ValurByte:=Byte(ValUse);

{ type asm function in order to be the part of program that is written by Assembly }

asm

push dx

mov dx,AddressPort

mov al,ValueByte

out dx,al

pop dx

End;

End ;

Function InVB(AddressPort:smallint):smallint;stdcall;export;

Var

ValueByte:Byte;

Begin

asm

push dx

mov dx,AddressPort

in al,dx

mov ValueByte,al

pop dx

End;

InVB:=smallint(ValueByte) and $00FF; { feedback to the function.

End

Exports

InWin ;

OutWin ;

Begin

End

We can comply program as DLL file, for convenience, you can copy code in TextBox below.

When we begin to use in VIsaul BasIc program, we have to declare the function in module (.BAS) that has the form like this,

Declare Function InVB LIB “InOutVB” (Byval port As Integer) As Long

Declare Function OutVB LIB “InOutVB” (Byval port As Integer, Byval bytedata As Long) As Long

For example, using the function to program connecting Printer port in Visual Basic

Label1.Caption=InVB(&H378) ‘ get value from Printer port.

OutVB (&H378,H&08) ’send value to Printer port.

All are the fundamental that can be used to program by Delphi in other types. After using the ready-made function is port in Pascal. Now, we try to program as Assembly for using.

Tags: plc
pac
pc
port
vb
vc
c#
parallel
serial
com
usb