// ApnCamera_NET.cpp: implementation of the CApnCamera_NET class. // // Copyright (c) 2003, 2004 Apogee Instruments, Inc. ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ApnCamera_NET.h" #include #include #include #include "ApogeeNet.h" #include "ApogeeNetErr.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// bool CApnCamera::InitDriver( unsigned long CamIdA, unsigned short CamIdB, unsigned long Option ) { char Hostname[25]; BYTE ipAddr[4]; int init; ipAddr[0] = (BYTE)(CamIdA & 0xFF); ipAddr[1] = (BYTE)((CamIdA >> 8) & 0xFF); ipAddr[2] = (BYTE)((CamIdA >> 16) & 0xFF); ipAddr[3] = (BYTE)((CamIdA >> 24) & 0xFF); sprintf( Hostname, "%u.%u.%u.%u:%u", ipAddr[3], ipAddr[2], ipAddr[1], ipAddr[0], CamIdB ); if ( ApnNetConnect( Hostname ) != APNET_SUCCESS ) { return false; } m_CameraInterface = Apn_Interface_NET; // Before trying to initialize, perform a simple loopback test unsigned short RegData; unsigned short NewRegData; RegData = 0x5AA5; if ( Write( FPGA_REG_SCRATCH, RegData ) != APNET_SUCCESS ) return false; if ( Read( FPGA_REG_SCRATCH, NewRegData ) != APNET_SUCCESS ) return false; if ( RegData != NewRegData ) return false; RegData = 0xA55A; if ( Write( FPGA_REG_SCRATCH, RegData ) != APNET_SUCCESS ) return false; if ( Read( FPGA_REG_SCRATCH, NewRegData ) != APNET_SUCCESS ) return false; if ( RegData != NewRegData ) return false; printf("Loopback test successful - ALTA-E detected at %u.%u.%u.%u:%u\n", ipAddr[3], ipAddr[2], ipAddr[1], ipAddr[0]); // The loopback test was successful. Proceed with initialization. init = InitDefaults(); if ( init != 0 ) { printf("Loopback test successful - InitDefaults FAILED\n"); return false; } printf("Loopback test successful - InitDefaults completed\n"); return true; } bool CApnCamera::CloseDriver() { ApnNetClose(); return true; } bool CApnCamera::GetImageData( unsigned short *pImageBuffer, unsigned short &Width, unsigned short &Height, unsigned long &Count ) { unsigned short Offset; unsigned short *pTempBuffer; long i, j; // Make sure it is okay to get the image data // The app *should* have done this on its own, but we have to make sure while ( !ImageReady() ) { Sleep( 50 ); read_ImagingStatus(); } Width = m_pvtWidth; Height = m_pvtHeight; if ( m_pvtBitsPerPixel == 16 ) Offset = 1; if ( m_pvtBitsPerPixel == 12 ) Offset = 10; Width -= Offset; // Calculate the true image width pTempBuffer = new unsigned short[(Width+Offset) * Height]; ApnNetGetImageTcp( pTempBuffer ); for ( i=0; i