Skip to content

Instantly share code, notes, and snippets.

@vector-kerr
Last active March 24, 2021 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vector-kerr/1bb701a7aec04d1dd5a0d7f434a24734 to your computer and use it in GitHub Desktop.
Save vector-kerr/1bb701a7aec04d1dd5a0d7f434a24734 to your computer and use it in GitHub Desktop.
ASI Capture Problem Demo

What is this?

This gist is here to demonstrate a difference in behaviour when running code using libASICamera2.so.

Testing Conditions

This program is run with my ASI294MM Pro, which is plugged directly into a dedicated USB 3 port on each machine. This program is built twice:

  • Once on an x64 desktop computer using lib/x64/libASICamera2.so
  • Once on a Raspberry Pi 4 (8GB Memory) lib/armv8/libASICamera2.so

Observed Outcomes

When running this program built with the x64 library on the desktop computer, it runs, and the exposure completes successfully every time. When running this program built with the armv8 library on the Raspberry Pi, it runs, but the exposure fails to complete every time.

Using This Gist

  1. Create a file called main.cpp and enter the content from the corresponding file below
  2. Create file called CMakeLists.txt and enter the content from the corresponding file below
  3. Update the CMakeLists.txt file to select the correct library for your system architecture
  4. Make a subdirectory called build and enter it in your terminal
  5. Run cmake .. from the build directory to prepare for building
  6. Run make to build the app
  7. Run ./main to execute the app, perform an image exposure, and see the success/failure of performing an exposure

Build notes

  • On my computers, I have placed the ASI SDK into /opt/asi, which has the following structure:
    • /opt/asi/include/ASICamera2.h
    • /opt/asi/lib/x64/libASICamera2.so
    • /opt/asi/lib/armv8/libASICamera2.so
  • The CMakeLists.txt file assumes the above but you can update it to point where-ever is required for your machine
  • You need to select the appropriate build architecture in the CMakeLists.txt file before you run cmake
pi@raspberrypi:~/development/asi-demo/build $ uname -a
Linux raspberrypi 5.10.17-v8+ #1403 SMP PREEMPT Mon Feb 22 11:37:54 GMT 2021 aarch64 GNU/Linux
pi@raspberrypi:~/development/asi-demo/build $ cmake ..
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/development/asi-demo/build
pi@raspberrypi:~/development/asi-demo/build $ make
Scanning dependencies of target main
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main
[100%] Built target main
pi@raspberrypi:~/development/asi-demo/build $ ./main
Camera count: 1
Using camera ZWO ASI294MM Pro
Maximum resolution: 8288 x 5644
Opening the camera... Done.
Initializing the camera... Done.
Setting control values... Done.
Setting Camera ROI... Done.
Starting the exposure... Done.
Waiting for the exposure to complete..................ERROR: EXPOSURE FAILED: 3
Stopping exposure and closing camera... Done.
pi@raspberrypi:~/development/asi-demo/build $ ./main
Camera count: 1
Using camera ZWO ASI294MM Pro
Maximum resolution: 8288 x 5644
Opening the camera... Done.
Initializing the camera... Done.
Setting control values... Done.
Setting Camera ROI... Done.
Starting the exposure... Done.
Waiting for the exposure to complete...................ERROR: EXPOSURE FAILED: 3
Stopping exposure and closing camera... Done.
pi@raspberrypi:~/development/asi-demo/build $ ./main
Camera count: 1
Using camera ZWO ASI294MM Pro
Maximum resolution: 8288 x 5644
Opening the camera... Done.
Initializing the camera... Done.
Setting control values... Done.
Setting Camera ROI... Done.
Starting the exposure... Done.
Waiting for the exposure to complete..................ERROR: EXPOSURE FAILED: 3
Stopping exposure and closing camera... Done.
pi@raspberrypi:~/development/asi-demo/build $ ./main
Camera count: 1
Using camera ZWO ASI294MM Pro
Maximum resolution: 8288 x 5644
Opening the camera... Done.
Initializing the camera... Done.
Setting control values... Done.
Setting Camera ROI... Done.
Starting the exposure... Done.
Waiting for the exposure to complete..................ERROR: EXPOSURE FAILED: 3
Stopping exposure and closing camera... Done.
pi@raspberrypi:~/development/asi-demo/build $
cmake_minimum_required(VERSION 2.8.9)
project (main)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
set ( PROJECT_LINK_LIBS libASICamera2.so )
# TODO: PICK THE CORRECT LIBRARY TO LINK AGAINST
#link_directories( /opt/asi/lib/x64 )
#link_directories( /opt/asi/lib/armv8 )
include_directories( /opt/asi/include )
set(SOURCES main.cpp)
add_executable(main ${SOURCES})
target_link_libraries( main ${PROJECT_LINK_LIBS} )
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <unistd.h>
#include "ASICamera2.h"
uint16_t exp_ms = 50;
uint8_t bandwidth = 40;
uint16_t gain = 250;
uint32_t width = 8288;
uint32_t height = 5644;
uint16_t bin = 1;
ASI_IMG_TYPE imageType = ASI_IMG_RAW16;
uint8_t bytesPerPixel = 1 + ((imageType == ASI_IMG_RAW16) ? 1 : 0);
uint32_t imgSize = width * height * bytesPerPixel;
uint8_t *imgBuf = new uint8_t[imgSize];
bool getCameraInfo(uint8_t cameraIndex) {
// Get camera info
ASI_CAMERA_INFO info;
ASIGetCameraProperty(&info, cameraIndex);
printf("Using camera %s\n", info.Name);
printf("Maximum resolution: %ld x %ld\n", info.MaxWidth, info.MaxHeight);
return true;
}
bool openCamera(uint8_t cameraIndex) {
printf("Opening the camera... ");
ASI_ERROR_CODE openCode;
if(ASI_SUCCESS != (openCode = ASIOpenCamera(cameraIndex)))
{
printf("ERROR: FAILED TO OPEN CAMERA (%d)\n", openCode);
return false;
}
printf("Done.\n");
return true;
}
bool initializeCamera(uint8_t cameraIndex) {
printf("Initializing the camera... ");
ASI_ERROR_CODE initCode;
if(ASI_SUCCESS != (initCode = ASIInitCamera(cameraIndex)))
{
printf("ERROR: FAILED TO INIT CAMERA (%d)\n", initCode);
return false;
}
printf("Done.\n");
return true;
}
bool setCameraControlValues(uint8_t cameraIndex) {
printf("Setting control values... ");
ASI_ERROR_CODE expCode = ASISetControlValue(cameraIndex, ASI_EXPOSURE, exp_ms * 1000, ASI_FALSE);
ASI_ERROR_CODE bwCode = ASISetControlValue(cameraIndex, ASI_BANDWIDTHOVERLOAD, bandwidth, ASI_FALSE);
ASI_ERROR_CODE gainCode = ASISetControlValue(cameraIndex, ASI_GAIN, gain, ASI_FALSE);
if(ASI_SUCCESS != expCode || ASI_SUCCESS != bwCode || ASI_SUCCESS != gainCode)
{
printf("ERROR: FAILED TO SET CONTROL VALUE: (%d ; %d ; %d)\n", expCode, bwCode, gainCode);
return false;
}
printf("Done.\n");
return true;
}
bool setCameraROI(uint8_t cameraIndex) {
printf("Setting Camera ROI... ");
ASI_ERROR_CODE roiCode;
if(ASI_SUCCESS != (roiCode = ASISetROIFormat(cameraIndex, width, height, bin, imageType)))
{
printf("ERROR: FAILED TO SET ROI: %d\n", roiCode);
return false;
}
printf(" Done.\n");
return true;
}
bool takeCameraExposure(uint8_t cameraIndex) {
printf("Starting the exposure... ");
ASI_ERROR_CODE exposureCode = ASIStartExposure(cameraIndex, ASI_FALSE);
if(ASI_SUCCESS != exposureCode) {
printf("ERROR: START EXPOSURE FAILED: %d\n", exposureCode);
return false;
}
printf("Done.\n");
printf("Waiting for the exposure to complete...");
fflush(stdout);
ASI_EXPOSURE_STATUS status = ASI_EXP_WORKING;
while (ASI_EXP_WORKING == status)
{
usleep(100000);
printf(".");
fflush(stdout);
ASIGetExpStatus(cameraIndex, &status);
}
if(ASI_EXP_SUCCESS != status) {
printf("ERROR: EXPOSURE FAILED: %d\n", status);
return false;
}
printf(" Done.\n");
return true;
}
bool retrieveCameraImage(uint8_t cameraIndex) {
printf("Retrieving image from camera into buffer... ");
ASI_ERROR_CODE retrieveCode;
if(ASI_SUCCESS != (retrieveCode = ASIGetDataAfterExp(cameraIndex, imgBuf, imgSize))) {
printf("ERROR: RETRIEVE FAILED: %d\n", retrieveCode);
return false;
}
printf(" Done.\n");
return true;
}
void close(uint8_t cameraIndex) {
printf("Stopping exposure and closing camera... ");
ASIStopExposure(cameraIndex);
ASICloseCamera(cameraIndex);
printf("Done.\n");
}
int main(int argc, char **argv) {
// Hard-wired to first (and only) camera
uint8_t cameraIndex = 0;
uint8_t cameraCount = ASIGetNumOfConnectedCameras();
printf("Camera count: %d\n", cameraCount);
if(!getCameraInfo(cameraIndex)) {
return EXIT_FAILURE;
}
if(!openCamera(cameraIndex)) {
return EXIT_FAILURE;
}
if(!initializeCamera(cameraIndex)) {
close(cameraIndex);
return EXIT_FAILURE;
}
if(!setCameraControlValues(cameraIndex)) {
close(cameraIndex);
return EXIT_FAILURE;
}
if(!setCameraROI(cameraIndex)) {
close(cameraIndex);
return EXIT_FAILURE;
}
if(!takeCameraExposure(cameraIndex)) {
close(cameraIndex);
return EXIT_FAILURE;
}
if(!retrieveCameraImage(cameraIndex)) {
close(cameraIndex);
return EXIT_FAILURE;
}
printf("Buffer size: %d\n", imgSize);
printf("First few bytes:\n");
for(uint8_t i = 0; i < 4; i++) {
printf("\t");
for(uint8_t j = 0; j < 8; j++) {
printf("%02x ", imgBuf[i * 8 + j]);
}
printf("\n");
}
close(cameraIndex);
return EXIT_SUCCESS;
}
vector@vector-lenovo-01:~/development/zwo-asi-test/vector-demo/build$ uname -a
Linux vector-lenovo-01 5.8.0-44-generic #50~20.04.1-Ubuntu SMP Wed Feb 10 21:07:30 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
vector@vector-lenovo-01:~/development/zwo-asi-test/vector-demo/build$ cmake ..
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vector/development/zwo-asi-test/vector-demo/build
vector@vector-lenovo-01:~/development/zwo-asi-test/vector-demo/build$ make
Scanning dependencies of target main
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main
[100%] Built target main
vector@vector-lenovo-01:~/development/zwo-asi-test/vector-demo/build$ ./main
Camera count: 1
Using camera ZWO ASI294MM Pro
Maximum resolution: 8288 x 5644
Opening the camera... Done.
Initializing the camera... Done.
Setting control values... Done.
Setting Camera ROI... Done.
Starting the exposure... Done.
Waiting for the exposure to complete............... Done.
Retrieving image from camera into buffer... Done.
Buffer size: 93554944
First few bytes:
70 00 00 00 a0 00 30 01
c0 00 a0 00 50 01 b0 01
c0 00 f0 00 10 01 60 00
10 00 90 01 00 00 d0 00
Stopping exposure and closing camera... Done.
vector@vector-lenovo-01:~/development/zwo-asi-test/vector-demo/build$ ./main
Camera count: 1
Using camera ZWO ASI294MM Pro
Maximum resolution: 8288 x 5644
Opening the camera... Done.
Initializing the camera... Done.
Setting control values... Done.
Setting Camera ROI... Done.
Starting the exposure... Done.
Waiting for the exposure to complete............... Done.
Retrieving image from camera into buffer... Done.
Buffer size: 93554944
First few bytes:
b0 00 70 00 60 00 70 01
f0 00 70 00 60 01 70 00
00 00 30 01 a0 00 00 00
00 00 40 00 80 00 50 01
Stopping exposure and closing camera... Done.
vector@vector-lenovo-01:~/development/zwo-asi-test/vector-demo/build$ ./main
Camera count: 1
Using camera ZWO ASI294MM Pro
Maximum resolution: 8288 x 5644
Opening the camera... Done.
Initializing the camera... Done.
Setting control values... Done.
Setting Camera ROI... Done.
Starting the exposure... Done.
Waiting for the exposure to complete.............. Done.
Retrieving image from camera into buffer... Done.
Buffer size: 93554944
First few bytes:
30 01 00 00 60 00 f0 00
40 01 a0 00 70 00 90 00
c0 00 20 00 80 01 c0 00
70 00 d0 00 d0 00 c0 01
Stopping exposure and closing camera... Done.
vector@vector-lenovo-01:~/development/zwo-asi-test/vector-demo/build$ ./main
Camera count: 1
Using camera ZWO ASI294MM Pro
Maximum resolution: 8288 x 5644
Opening the camera... Done.
Initializing the camera... Done.
Setting control values... Done.
Setting Camera ROI... Done.
Starting the exposure... Done.
Waiting for the exposure to complete.............. Done.
Retrieving image from camera into buffer... Done.
Buffer size: 93554944
First few bytes:
30 01 60 01 f0 00 10 00
90 00 00 00 60 01 00 01
d0 00 80 00 20 01 00 00
b0 00 a0 01 c0 00 50 00
Stopping exposure and closing camera... Done.
vector@vector-lenovo-01:~/development/zwo-asi-test/vector-demo/build$ ./main
Camera count: 1
Using camera ZWO ASI294MM Pro
Maximum resolution: 8288 x 5644
Opening the camera... Done.
Initializing the camera... Done.
Setting control values... Done.
Setting Camera ROI... Done.
Starting the exposure... Done.
Waiting for the exposure to complete.............. Done.
Retrieving image from camera into buffer... Done.
Buffer size: 93554944
First few bytes:
a0 00 00 00 a0 00 d0 00
e0 00 20 00 50 01 40 01
e0 00 a0 01 30 01 b0 01
90 00 c0 00 c0 01 40 01
Stopping exposure and closing camera... Done.
vector@vector-lenovo-01:~/development/zwo-asi-test/vector-demo/build$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment