1. Reply to Newbie - help with pointers
Kenley Lim:
Maybe this will help
-- ================ Warning code under construction ====================== --
include win32lib.ew
atom ad32
atom Status
atom OpenBoard
atom BoardIn
atom float64number
atom DeviceNumber
atom ConfigInfoPtr
atom IpDioReadBitPtr
integer SizeOfConfigInfoStruct
integer SizeOfPT_DioReadbitStruct
-- First tell windows to load the ADAPI32.DLL containing
-- the DRV_DeviceOpen function and DRV_DioReadBit function
--
ad32 = open_dll("ADAPI32.DLL")
-- Define the DRV_DeviceOpen function as OpenBoard
-- DRV_DeviceOpen(unsigned long DeviceNum, long *DriverHandle)
-- Not sure on return-type because the information did not specify
--
OpenBoard = define_c_func(ad32, "DRV_DeviceOpen", {C_ULONG, C_POINTER},
C_LONG) -- return value
-- Define the DRV_DioReadBit function as BoardIn
-- DRV_DioReadBit(long *DriverHandle, long *IpDioReadBit)
-- Not sure on return-type because the information did not specify
--
BoardIn = define_c_func(ad32, "DRV_DioReadBit", {C_POINTER, C_POINTER},
C_LONG) -- return value
-- Allocate Configuration Information Structure
-- I don't know what other Functions you can use with the PCL-722 Controller
-- but I would guess that use this same structure to change the EH Registers
-- by placing new board settings in this structure and using some function
-- to call the board.
--
SizeOfConfigInfoStruct = 8 -- Structure Not describe in your examples
DriverHandlePtr = allocate(SizeOfConfigInfoStruct) -- MEMORY for structure
-- Next you have to fill the structure by using POKES but be SURE that you
-- use the BYTE ORDER THAT IS USED BY THE CONTROLLER which may or may not
-- be the same byte order as the PC you are using to operate the board.
-- This would have to be done her if you were using a FUNCTION to
-- configure the Controller. Initialize to zeros because were getting EH
-- Register information from the card with this function
DriverHandlePtr = repeat(0, SizeOfConfigInfoStruct) -- Initialize to zeros
-- Using the OpenBoard function will take EH Register information and
-- place it into the Configuration Information Structure
--
DeviceNumber = 0
Status = c_func(OpenBoard, {DeviceNumber, DriverHandlePtr})
-- check the status here to be sure it worked
-- Allocate PT_DioReadbit Structure --Structure Not described in your examples
-- I dont know how this Structure is layed out, but I know that it
-- contains storage for port# 0 - 17, bits and state
--
SizeOfPT_DioReadbitStruct = 8 -- What ever size Structure You Need
IpDioReadBit = allocate(SizeOfPT_DioReadbitStruct) -- MEMORY for structure
IpDioReadBit = repeat(0, SizeOfPT_DioReadbitStruct) -- Initialize to zeros
-- Using the BoardIn (or Digin) function when it's called will place the
-- digital information into the PT_DioReadbit Structure for the device number
-- that was specified in the Configuration Information Structure returned
-- by the call to DRV_DeviceOpen function.
status = c_func(BoardIn, {DriverHandlePtr, IpDioReadBitPtr})
-- check the status here to be sure it worked
-- Now you have to PEEK into the PT_DioReadbit Structure BYTE locations
-- and take your readings and convert them from MEMORY BYTES to
-- a form that can be used by Eupohoria with bytes_to_int, bits_to_int,
-- and ( ONLY if your controller fills the Structure in standard
-- IEEE floating-point format ) float64_to_atom, float32_to_atom.
-- SUMMARY of using the ADAPI32.DLL
--
-- This is how I think the DLL and the PCL-722 Controller work togather
-- You create a STRUCTURE of Configuration Information Structure for
-- EACH DEVICE that you want to use in the Controller. You use EACH
-- of these specific structures to SETUP or GET information about a DEVICE
-- by passing the POINTER the specific Configuration Information Structure
-- that YOU ASSIGNED to that DEVICE. DriverHandle IS the POINTER to the
-- Configuration Information Structure ( BLOCK OF MEMORY USE ALLOCATED ).
-- To GET DIGITAL DATA information from the controller YOU ASSIGN ANOTHER
-- PT_DioReadbit Structure to each DEVICE.
-- To get some information from DEVICE#1 YOU CALL DRV_DioReadBit with the
-- first POINTER SET to DEVICE#1's Configuration Information Structure
-- second POINTER SET to DEVICE#1's PT_DioReadbit Structure
-- And the controller will look at Configuration Information Structure
-- decide which device to use and put the reading in the PT_DioReadbit
-- Structure. The Pointer is the name that you assigned the block of memory
-- that you allocated.
--
-- Remember that I am guessing about alot of this because I don't have
-- the Manual or PCL-722 Controller to try to use it
--
--
-- I hope this will help you some
-- Bernie