1
QB64 Discussion / Re: USING DLL FOR C++ IN QB64
« on: August 18, 2020, 09:11:40 pm »
$RESIZE:SMOOTH
DECLARE DYNAMIC LIBRARY "ASICamera2"
FUNCTION ASIGetNumOfConnectedCameras& () REM
FUNCTION ASIOpenCamera& (BYVAL iCameraID AS INTEGER)
FUNCTION ASIGetID& (BYVAL iCameraID AS INTEGER, BYVAL pID AS _OFFSET)
FUNCTION ASICloseCamera& (BYVAL iCameraID AS INTEGER)
FUNCTION ASIGetCameraProperty& (BYVAL info AS _OFFSET, BYVAL id AS INTEGER)
FUNCTION ASIStartExposure& (BYVAL iCameraID AS INTEGER)
FUNCTION ASIStopExposure& (BYVAL iCameraID AS INTEGER)
FUNCTION ASIGetDataAfterExp& (BYVAL iCameraID AS INTEGER, BYVAL buffer AS _OFFSET, BYVAL buffersize AS LONG)
FUNCTION ASIInitCamera& (BYVAL iCameraID AS INTEGER)
END DECLARE
DECLARE DYNAMIC LIBRARY "EFW_filter"
FUNCTION EFWGetNum& () REM int EFWGetNum() return number of filter wheels
FUNCTION EFWOpen& (BYVAL a AS INTEGER) REM EFW_ERROR_CODE EFWOpen(int ID)
FUNCTION EFWGetID& (BYVAL a AS INTEGER, BYVAL i AS _OFFSET) REM int index: the index of filter wheel, from 0 to N - 1, N is returned by EFWGetNum()
FUNCTION EFWSetPosition& (BYVAL i AS INTEGER, BYVAL p AS INTEGER)
FUNCTION EFWClose& (BYVAL i AS INTEGER) REM EFW_ERROR_CODE EFWClose(int ID)
FUNCTION EFWGetProperty& (BYVAL i AS INTEGER, BYVAL info AS _OFFSET) REM EFW_ERROR_CODE EFWGetProperty(int ID, EFW_INFO *pInfo)
FUNCTION EFWGetPosition& (BYVAL i AS INTEGER, BYVAL p AS _OFFSET)
END DECLARE
DECLARE CUSTOMTYPE LIBRARY
SUB memcpy (BYVAL dest AS _OFFSET, BYVAL source AS _OFFSET, BYVAL bytes AS LONG)
END DECLARE
DIM SHARED ap AS _OFFSET
CONST BUFFERSIZE = 16389120
CONST TRUE = 1
CONST FALSE = 0
DEFINT A-Z
TYPE efwinfo
ID AS STRING * 4
EFWname AS STRING * 64
slotnumber AS STRING * 4
END TYPE
TYPE camerainfo
NM AS STRING * 64
ID AS STRING * 4
MAXH AS STRING * 4
MAXL AS STRING * 4
ISCOLOR AS STRING * 1
BAYER AS STRING * 4
SUPPORTBIN AS STRING * 64
IMAGETYPE AS STRING * 8
PIXELSIZE AS STRING * 8
ISSHUTTER AS _BIT * 1
ST4PORT AS _BIT * 1
ISCOOL AS _BIT * 1
ISUSB3HOST AS _BIT * 1
ISUSBCAMERA AS _BIT * 1
ELEEPERADU AS STRING * 4
BITDEPTH AS STRING * 4
TRIGGER AS _BIT * 1
UNUSED AS STRING * 16
END TYPE
TYPE ASIBUFF
BUFF AS STRING * BUFFERSIZE
END TYPE
DIM SHARED cinfo AS camerainfo
DIM SHARED finfo AS efwinfo
DIM SHARED CID AS INTEGER
DIM SHARED MYBUFF AS ASIBUFF
DIM SHARED CX AS INTEGER
DIM SHARED CY AS INTEGER
IF ASIGetNumOfConnectedCameras > FALSE THEN cerror (ASIGetCameraProperty(_OFFSET(cinfo), 0)): memcpy _OFFSET(CID), _OFFSET(cinfo.ID), 4: cerror (ASIOpenCamera(CID)): ELSE cerror (ASICloseCamera(CID)): cerror (1)
cerror (ASIInitCamera(CID))
REM get sensor size
memcpy _OFFSET(CX), _OFFSET(cinfo.MAXL), 4
memcpy _OFFSET(CY), _OFFSET(cinfo.MAXH), 4
DIM SHARED C&
DIM SHARED S&
REM display screen size
DIM SX AS _UNSIGNED INTEGER
DIM SY AS _UNSIGNED INTEGER
SX = 1024: SY = 768
C& = _NEWIMAGE(CX, CY, 32)
S& = _NEWIMAGE(SX, SY, 32)
SCREEN S&
_DEST C&
DIM pix AS _UNSIGNED _BYTE
DIM OC AS _UNSIGNED LONG
WHILE (1)
takephoto
REM PCOPY C&, S&
_PUTIMAGE (0, 0)-(SX * .5, SY * .5), C&, 0, (0, 0)-(CX, CY)
WEND
END
startfw: REM start filter
filterdisplay
FOR X = 0 TO 10
filterslot (RND * 8 + 1)
filterdisplay
NEXT X
ferror (EFWClose(ASC(finfo.ID)))
END
SUB filterslot (slot)
IF ASC(finfo.ID) > -1 THEN fwinfo.werror = EFWSetPosition(ASC(finfo.ID), slot - 1)
WHILE (EFWSetPosition(ASC(finfo.ID), slot - 1) > 0)
SLEEP 1
WEND
END SUB
SUB startfw ()
IF EFWGetNum - 1 < 0 THEN PRINT "no filter": efwinfo.ID = -1
IF efwinfo.ID > -1 THEN ferror (EFWGetID(0, _OFFSET(efwinfo.ID))): ferror (EFWOpen(INT(ASC(finfo.ID)))): ferror (EFWGetProperty(ASC(finfo.ID), _OFFSET(finfo)))
END SUB
SUB filterdisplay
ferror (EFWGetPosition(efwinfo.ID, _OFFSET(P)))
LOCATE 7, 12
PRINT "Filter Pseition"; P + 1
END SUB
SUB cerror (E)
IF E = 1 THEN PRINT "no camera connected or index value out of boundary": SLEEP: END
IF E = 2 THEN PRINT "INVALID ID": SLEEP: END
IF E = 3 THEN PRINT "INVALID CONTROL TYPE": SLEEP: END
IF E = 4 THEN PRINT "CAMERA DID NOT OPEN": SLEEP: END
IF E = 5 THEN PRINT "UNABLE TO FIND CAMERA": SLEEP: END
IF E = 6 THEN PRINT "COULD NOT FIND PATH OF FILE": SLEEP: END
IF E = 7 THEN PRINT "INVALID FILE FORMAT": SLEEP: END
IF E = 8 THEN PRINT "WRONG VIDEO FORMAT SIZE": SLEEP: END
IF E = 9 THEN PRINT "UNSUPPORTED IMAGE FORMAT": SLEEP: END
IF E = 10 THEN PRINT "THE START POSITION OUT SIDE BOUNDARY": SLEEP: END
IF E = 11 THEN PRINT "TIME OUT": SLEEP: END
IF E = 12 THEN PRINT "STOP CAPTURE FIRST": SLEEP: END
IF E = 13 THEN PRINT "BUFFER NOT BIG ENOUGH": SLEEP: END
IF E = 14 THEN PRINT "VIDEO_MODE_ACTIVE": SLEEP: END
IF E = 15 THEN PRINT "EXPOSURE_IN_PROGRESS": SLEEP: END
IF E = 16 THEN PRINT "GENERAL ERROR": SLEEP: END
IF E = 17 THEN PRINT "ERROR END": SLEEP: END
END SUB
SUB ferror (E)
IF E = 1 THEN PRINT "INVALID INDEX": SLEEP: END
IF E = 2 THEN PRINT "INVALID ID": SLEEP: END
IF E = 3 THEN PRINT "INVALID VALUE": SLEEP: END
IF E = 4 THEN PRINT "CLOSED": SLEEP: END
REM IF E = 5 THEN PRINT "UNABLE TO FIND FILTER WHEEL": SLEEP: END
IF E = 5 THEN PRINT "FILTER WHEEL MOVING": SLEEP: END
IF E = 7 THEN PRINT "OTHER ERROR": SLEEP: END
IF E = 8 THEN PRINT "CLOSED": SLEEP: END
IF E = -1 THEN PRINT "END": SLEEP: END
END SUB
SUB takephoto ()
DIM PIX AS INTEGER
amp = 1: m = 1: nh = 0
DIM os AS LONG
cerror (ASIStartExposure(CID))
SLEEP 1
REM PRINT _OFFSET(MYBUFF.BUFF), CX, CY
REM GOTO over
cerror (ASIStopExposure(CID))
cerror (ASIGetDataAfterExp(CID, _OFFSET(MYBUFF.BUFF), BUFFERSIZE))
os = 0
FOR Y = 0 TO CY - 1
FOR X = 0 TO CX - 1
memcpy _OFFSET(PIX), _OFFSET(MYBUFF.BUFF) + os, 1: os = os + 1
PIX = PIX * m
PSET (X, Y), _RGB(PIX, PIX, PIX): REM 8 bit per pixel
NEXT X
NEXT Y
over:
END SUB
DECLARE DYNAMIC LIBRARY "ASICamera2"
FUNCTION ASIGetNumOfConnectedCameras& () REM
FUNCTION ASIOpenCamera& (BYVAL iCameraID AS INTEGER)
FUNCTION ASIGetID& (BYVAL iCameraID AS INTEGER, BYVAL pID AS _OFFSET)
FUNCTION ASICloseCamera& (BYVAL iCameraID AS INTEGER)
FUNCTION ASIGetCameraProperty& (BYVAL info AS _OFFSET, BYVAL id AS INTEGER)
FUNCTION ASIStartExposure& (BYVAL iCameraID AS INTEGER)
FUNCTION ASIStopExposure& (BYVAL iCameraID AS INTEGER)
FUNCTION ASIGetDataAfterExp& (BYVAL iCameraID AS INTEGER, BYVAL buffer AS _OFFSET, BYVAL buffersize AS LONG)
FUNCTION ASIInitCamera& (BYVAL iCameraID AS INTEGER)
END DECLARE
DECLARE DYNAMIC LIBRARY "EFW_filter"
FUNCTION EFWGetNum& () REM int EFWGetNum() return number of filter wheels
FUNCTION EFWOpen& (BYVAL a AS INTEGER) REM EFW_ERROR_CODE EFWOpen(int ID)
FUNCTION EFWGetID& (BYVAL a AS INTEGER, BYVAL i AS _OFFSET) REM int index: the index of filter wheel, from 0 to N - 1, N is returned by EFWGetNum()
FUNCTION EFWSetPosition& (BYVAL i AS INTEGER, BYVAL p AS INTEGER)
FUNCTION EFWClose& (BYVAL i AS INTEGER) REM EFW_ERROR_CODE EFWClose(int ID)
FUNCTION EFWGetProperty& (BYVAL i AS INTEGER, BYVAL info AS _OFFSET) REM EFW_ERROR_CODE EFWGetProperty(int ID, EFW_INFO *pInfo)
FUNCTION EFWGetPosition& (BYVAL i AS INTEGER, BYVAL p AS _OFFSET)
END DECLARE
DECLARE CUSTOMTYPE LIBRARY
SUB memcpy (BYVAL dest AS _OFFSET, BYVAL source AS _OFFSET, BYVAL bytes AS LONG)
END DECLARE
DIM SHARED ap AS _OFFSET
CONST BUFFERSIZE = 16389120
CONST TRUE = 1
CONST FALSE = 0
DEFINT A-Z
TYPE efwinfo
ID AS STRING * 4
EFWname AS STRING * 64
slotnumber AS STRING * 4
END TYPE
TYPE camerainfo
NM AS STRING * 64
ID AS STRING * 4
MAXH AS STRING * 4
MAXL AS STRING * 4
ISCOLOR AS STRING * 1
BAYER AS STRING * 4
SUPPORTBIN AS STRING * 64
IMAGETYPE AS STRING * 8
PIXELSIZE AS STRING * 8
ISSHUTTER AS _BIT * 1
ST4PORT AS _BIT * 1
ISCOOL AS _BIT * 1
ISUSB3HOST AS _BIT * 1
ISUSBCAMERA AS _BIT * 1
ELEEPERADU AS STRING * 4
BITDEPTH AS STRING * 4
TRIGGER AS _BIT * 1
UNUSED AS STRING * 16
END TYPE
TYPE ASIBUFF
BUFF AS STRING * BUFFERSIZE
END TYPE
DIM SHARED cinfo AS camerainfo
DIM SHARED finfo AS efwinfo
DIM SHARED CID AS INTEGER
DIM SHARED MYBUFF AS ASIBUFF
DIM SHARED CX AS INTEGER
DIM SHARED CY AS INTEGER
IF ASIGetNumOfConnectedCameras > FALSE THEN cerror (ASIGetCameraProperty(_OFFSET(cinfo), 0)): memcpy _OFFSET(CID), _OFFSET(cinfo.ID), 4: cerror (ASIOpenCamera(CID)): ELSE cerror (ASICloseCamera(CID)): cerror (1)
cerror (ASIInitCamera(CID))
REM get sensor size
memcpy _OFFSET(CX), _OFFSET(cinfo.MAXL), 4
memcpy _OFFSET(CY), _OFFSET(cinfo.MAXH), 4
DIM SHARED C&
DIM SHARED S&
REM display screen size
DIM SX AS _UNSIGNED INTEGER
DIM SY AS _UNSIGNED INTEGER
SX = 1024: SY = 768
C& = _NEWIMAGE(CX, CY, 32)
S& = _NEWIMAGE(SX, SY, 32)
SCREEN S&
_DEST C&
DIM pix AS _UNSIGNED _BYTE
DIM OC AS _UNSIGNED LONG
WHILE (1)
takephoto
REM PCOPY C&, S&
_PUTIMAGE (0, 0)-(SX * .5, SY * .5), C&, 0, (0, 0)-(CX, CY)
WEND
END
startfw: REM start filter
filterdisplay
FOR X = 0 TO 10
filterslot (RND * 8 + 1)
filterdisplay
NEXT X
ferror (EFWClose(ASC(finfo.ID)))
END
SUB filterslot (slot)
IF ASC(finfo.ID) > -1 THEN fwinfo.werror = EFWSetPosition(ASC(finfo.ID), slot - 1)
WHILE (EFWSetPosition(ASC(finfo.ID), slot - 1) > 0)
SLEEP 1
WEND
END SUB
SUB startfw ()
IF EFWGetNum - 1 < 0 THEN PRINT "no filter": efwinfo.ID = -1
IF efwinfo.ID > -1 THEN ferror (EFWGetID(0, _OFFSET(efwinfo.ID))): ferror (EFWOpen(INT(ASC(finfo.ID)))): ferror (EFWGetProperty(ASC(finfo.ID), _OFFSET(finfo)))
END SUB
SUB filterdisplay
ferror (EFWGetPosition(efwinfo.ID, _OFFSET(P)))
LOCATE 7, 12
PRINT "Filter Pseition"; P + 1
END SUB
SUB cerror (E)
IF E = 1 THEN PRINT "no camera connected or index value out of boundary": SLEEP: END
IF E = 2 THEN PRINT "INVALID ID": SLEEP: END
IF E = 3 THEN PRINT "INVALID CONTROL TYPE": SLEEP: END
IF E = 4 THEN PRINT "CAMERA DID NOT OPEN": SLEEP: END
IF E = 5 THEN PRINT "UNABLE TO FIND CAMERA": SLEEP: END
IF E = 6 THEN PRINT "COULD NOT FIND PATH OF FILE": SLEEP: END
IF E = 7 THEN PRINT "INVALID FILE FORMAT": SLEEP: END
IF E = 8 THEN PRINT "WRONG VIDEO FORMAT SIZE": SLEEP: END
IF E = 9 THEN PRINT "UNSUPPORTED IMAGE FORMAT": SLEEP: END
IF E = 10 THEN PRINT "THE START POSITION OUT SIDE BOUNDARY": SLEEP: END
IF E = 11 THEN PRINT "TIME OUT": SLEEP: END
IF E = 12 THEN PRINT "STOP CAPTURE FIRST": SLEEP: END
IF E = 13 THEN PRINT "BUFFER NOT BIG ENOUGH": SLEEP: END
IF E = 14 THEN PRINT "VIDEO_MODE_ACTIVE": SLEEP: END
IF E = 15 THEN PRINT "EXPOSURE_IN_PROGRESS": SLEEP: END
IF E = 16 THEN PRINT "GENERAL ERROR": SLEEP: END
IF E = 17 THEN PRINT "ERROR END": SLEEP: END
END SUB
SUB ferror (E)
IF E = 1 THEN PRINT "INVALID INDEX": SLEEP: END
IF E = 2 THEN PRINT "INVALID ID": SLEEP: END
IF E = 3 THEN PRINT "INVALID VALUE": SLEEP: END
IF E = 4 THEN PRINT "CLOSED": SLEEP: END
REM IF E = 5 THEN PRINT "UNABLE TO FIND FILTER WHEEL": SLEEP: END
IF E = 5 THEN PRINT "FILTER WHEEL MOVING": SLEEP: END
IF E = 7 THEN PRINT "OTHER ERROR": SLEEP: END
IF E = 8 THEN PRINT "CLOSED": SLEEP: END
IF E = -1 THEN PRINT "END": SLEEP: END
END SUB
SUB takephoto ()
DIM PIX AS INTEGER
amp = 1: m = 1: nh = 0
DIM os AS LONG
cerror (ASIStartExposure(CID))
SLEEP 1
REM PRINT _OFFSET(MYBUFF.BUFF), CX, CY
REM GOTO over
cerror (ASIStopExposure(CID))
cerror (ASIGetDataAfterExp(CID, _OFFSET(MYBUFF.BUFF), BUFFERSIZE))
os = 0
FOR Y = 0 TO CY - 1
FOR X = 0 TO CX - 1
memcpy _OFFSET(PIX), _OFFSET(MYBUFF.BUFF) + os, 1: os = os + 1
PIX = PIX * m
PSET (X, Y), _RGB(PIX, PIX, PIX): REM 8 bit per pixel
NEXT X
NEXT Y
over:
END SUB