Page 1 of 2
Convert code to FWH
Posted: Fri Apr 28, 2023 9:26 pm
by cdmmaui
Happy Friday Everyone,
Could someone help me convert this code to FWH? I would happy to pay you for your time.
Thank you!
#define AddrPort 0x2e
#define DataPort 0x2f
#define SIO_UnLock_Value 0x87
#define SIO_Lock_Value 0xaa
#define SIO_LDN_GPIO 0x07
#define GPIO_Port 0xF1
// Enter_Config
WriteByte (AddrPort , SIO_UnLock_Value);
WriteByte (AddrPort , SIO_UnLock_Value);
WriteByte (AddrPort , 0x07);
WriteByte (DataPort , SIO_LDN_GPIO);
//Set OUT1~OUT8Value
WriteByte( AddrPort , GPIO_Port);
WriteByte (DataPort , 0x00); //set OUT1~OUT8 value, OUT1=Bit0, OUT2=Bit1
// Read In1~In8 value
WriteByte( AddrPort, 0xED);
Data=ReadByte DataPort ); //Read In1~In8 value
// close config mode
WriteByte( AddrPort , SIO_Lock_Value);
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 4:29 am
by Antonio Linares
Dear Darrell,
What C compiler are you using ?
Are you using 32 or 64 bits ?
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 4:31 am
by cdmmaui
Hi Antonio,
Borland
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 4:36 am
by Antonio Linares
32 bits ?
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 4:42 am
by cdmmaui
Hi Antonio,
Yes
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 5:11 am
by Antonio Linares
Dear
Darrell,
Please download this zip file:
https://github.com/starofrainnight/wini ... /WinIo.zip
And try this initial version:
Code: Select all | Expand
#include "FiveWin.ch"
#include "dll.ch"
#define AddrPort 0x2e
#define DataPort 0x2f
#define SIO_UnLock_Value 0x87
#define SIO_Lock_Value 0xaa
#define SIO_LDN_GPIO 0x07
#define GPIO_Port 0xF1
static hDll
function Main()
local Data
hDLL = LoadLibrary( "winio.dll" )
InitializeWinIO()
// Enter_Config
WriteByte (AddrPort , SIO_UnLock_Value)
WriteByte (AddrPort , SIO_UnLock_Value)
WriteByte (AddrPort , 0x07)
WriteByte (DataPort , SIO_LDN_GPIO)
//Set OUT1~OUT8Value
WriteByte( AddrPort , GPIO_Port)
WriteByte (DataPort , 0x00) //set OUT1~OUT8 value, OUT1=Bit0, OUT2=Bit1
// Read In1~In8 value
WriteByte( AddrPort, 0xED)
Data=ReadByte( DataPort ) //Read In1~In8 value
// close config mode
WriteByte( AddrPort , SIO_Lock_Value)
ShutDownWinIo()
FreeLibrary( hDLL )
MsgInfo( "ok" )
return nil
DLL FUNCTION InitializeWinIO() AS BOOL FROM "InitializeWinIo" LIB hDLL
DLL FUNCTION WriteByte( nPort AS _INT, nValue AS _INT ) AS BOOL FROM "SetPortVal" LIB hDLL
DLL FUNCTION ReadByte( nPort AS _INT ) AS _INT FROM "GetPortVal" LIB hDLL
DLL FUNCTION ShutdownWinIo() AS VOID FROM "ShutdownWinIo" LIB hDLL
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 5:17 am
by Antonio Linares
Please replace this line:
InitializeWinIO()
with:
MsgInfo( InitializeWinIO() )
to check if the DLL properly initializes
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 5:19 am
by Antonio Linares
After running it please check if there is a hb_out.log file
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 5:32 am
by Antonio Linares
There is something else to implement, doing it...
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 5:41 am
by Antonio Linares
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 5:57 am
by Antonio Linares
This should be the right code:
winio32.dll and winio32.sys should be where your EXE is placed.
ports.prg
Code: Select all | Expand
#include "FiveWin.ch"
#include "dll.ch"
#define AddrPort 0x2e
#define DataPort 0x2f
#define SIO_UnLock_Value 0x87
#define SIO_Lock_Value 0xaa
#define SIO_LDN_GPIO 0x07
#define GPIO_Port 0xF1
static hDll
function Main()
local Data
hDLL = LoadLibrary( "winio32.dll" )
MsgInfo( hDLL )
MsgInfo( InstallWinIoDriver( "WinIo32.sys", .T. ) )
MsgInfo( InitializeWinIO() )
// Enter_Config
WriteByte (AddrPort , SIO_UnLock_Value)
WriteByte (AddrPort , SIO_UnLock_Value)
WriteByte (AddrPort , 0x07)
WriteByte (DataPort , SIO_LDN_GPIO)
//Set OUT1~OUT8Value
WriteByte( AddrPort , GPIO_Port)
WriteByte (DataPort , 0x00) //set OUT1~OUT8 value, OUT1=Bit0, OUT2=Bit1
// Read In1~In8 value
WriteByte( AddrPort, 0xED)
Data=ReadByte( DataPort ) //Read In1~In8 value
// close config mode
WriteByte( AddrPort , SIO_Lock_Value)
ShutDownWinIo()
FreeLibrary( hDLL )
MsgInfo( "ok" )
return nil
DLL FUNCTION InstallWinIoDriver( cPath AS LPSTR, lIsDemandLoaded AS BOOL ) AS BOOL FROM "InitializeWinIo" LIB hDLL
DLL FUNCTION InitializeWinIO() AS BOOL FROM "InitializeWinIo" LIB hDLL
DLL FUNCTION WriteByte( nPort AS _INT, nValue AS _INT ) AS BOOL FROM "SetPortVal" LIB hDLL
DLL FUNCTION ReadByte( nPort AS _INT ) AS _INT FROM "GetPortVal" LIB hDLL
DLL FUNCTION ShutdownWinIo() AS VOID FROM "ShutdownWinIo" LIB hDLL
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 6:03 am
by Antonio Linares
A brief explanation:
A Windows app can't directly manage the ports for security reasons, it must use a driver.
WinIO32.sys is the driver and WinIO32.DLL is the DLL to manage such driver
This WinIO was developed by
http://www.sysinternals.com but lately was bought by Microsoft and they dropped it.
Thats why this free github repo has implemented it:
https://github.com/starofrainnight/winio
Re: Convert code to FWH
Posted: Sat Apr 29, 2023 12:18 pm
by cdmmaui
Hello Antonio,
Thank you so much! Initially we are looking to read certain values to determine status of a device, simply 0 or 1 (on or off).
Thank you again!
Re: Convert code to FWH
Posted: Sun Apr 30, 2023 9:13 pm
by Jimmy
hi,
i like to know what Hardware do you use with this CODE
Re: Convert code to FWH
Posted: Sun Apr 30, 2023 10:14 pm
by cdmmaui
Hi Jimmy,
Nuvoton NCT6106D. We are looking to get status from specific pin, either on (1) or off (0).