Merge
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// Keyence Status class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_KEYENCE_STATUS_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_)
|
||||
#define AFX_KEYENCE_STATUS_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
enum KEYENCE_STATUS {
|
||||
KEYENCE_STATUS_NORMAL = 0,
|
||||
KEYENCE_STATUS_DATALINK_ERROR,
|
||||
KEYENCE_STATUS_SETUP_ASYNC_CONTEXT_ERROR,
|
||||
KEYENCE_STATUS_COMMAND_TIMEOUT,
|
||||
KEYENCE_STATUS_COMMAND_BUSY,
|
||||
KEYENCE_STATUS_REPLAY_FILE_ERROR,
|
||||
KEYENCE_STATUS_CONFIG_FILE_NOT_FOUND,
|
||||
KEYENCE_ERROR
|
||||
};
|
||||
#endif // !defined(AFX_KEYENCE_STATUS_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_)
|
||||
@@ -0,0 +1,307 @@
|
||||
#include "stdafx.h"
|
||||
#include "..\Tools\UsbUtility\Proto_Util.h"
|
||||
#include "KeyenceTM065_Proto.h"
|
||||
#include "KeyenceStatus.h"
|
||||
|
||||
#define MY_CONFIG 1
|
||||
#define MAX_DEVPATH_LENGTH 256
|
||||
#define ENDPOINT_TIMEOUT 500
|
||||
|
||||
//******************************************************************************
|
||||
//
|
||||
void CKeyenceTM065_Proto::_process_rcv_transfer_data()
|
||||
{
|
||||
switch (ep_buff._cmd0)
|
||||
{
|
||||
case _CMD0_0800:
|
||||
break;
|
||||
case _CMD0_0C00:
|
||||
switch (ep_buff._cmd1)
|
||||
{
|
||||
case _CMD1_0730:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
case _CMD0_100a:
|
||||
break;
|
||||
case _CMD0_1400:
|
||||
break;
|
||||
case _CMD0_3000:
|
||||
break;
|
||||
case _CMD0_4800:
|
||||
break;
|
||||
case _CMD0_4c00:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
_process_KEYENCE_CMD_GET_DATA();
|
||||
};
|
||||
|
||||
//******************************************************************************
|
||||
CKeyenceTM065_Proto::CKeyenceTM065_Proto()
|
||||
{
|
||||
ep_buff._buff = (unsigned char *)malloc(MAX_KEYENCE_EP_BUFF_SIZE);
|
||||
ep_buff._bin = (unsigned char *)malloc(MAX_KEYENCE_EP_BUFF_SIZE);
|
||||
ep_buff._send_size = 0;
|
||||
ep_buff._async_context = NULL;
|
||||
ep_buff._cmd0 = 0;
|
||||
ep_buff._cmd1 = 0;
|
||||
g_dev = NULL;
|
||||
};
|
||||
|
||||
//******************************************************************************
|
||||
CKeyenceTM065_Proto::~CKeyenceTM065_Proto()
|
||||
{
|
||||
free(ep_buff._buff);
|
||||
free(ep_buff._bin);
|
||||
}
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
//******************************************************************************
|
||||
|
||||
//******************************************************************************
|
||||
usb_dev_handle* CKeyenceTM065_Proto::_open_usb_dev(void)
|
||||
{
|
||||
struct usb_bus *bus = NULL;
|
||||
struct usb_device *dev = NULL;
|
||||
|
||||
for (bus = usb_get_busses(); bus; bus = bus->next)
|
||||
{
|
||||
for (dev = bus->devices; dev; dev = dev->next)
|
||||
{
|
||||
if (dev->descriptor.idVendor == KEYENCE_VID && dev->descriptor.idProduct == KEYENCE_PID)
|
||||
{
|
||||
return usb_open(dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int CKeyenceTM065_Proto::_usb_reset(void)
|
||||
{
|
||||
if (g_dev)
|
||||
{
|
||||
usb_reset(g_dev);
|
||||
g_dev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int CKeyenceTM065_Proto::Init_Keyence()
|
||||
{
|
||||
int usb_status = NULL;
|
||||
usb_init(); // initialize the library
|
||||
usb_status = usb_find_busses(); // find all busses
|
||||
usb_status = usb_find_devices(); // find all connected devices
|
||||
g_dev = _open_usb_dev();
|
||||
if (!g_dev)
|
||||
{
|
||||
MessageBox(NULL, _T("Unable to open device"), _T("Message"), MB_OK);
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
|
||||
if (usb_set_configuration(g_dev, MY_CONFIG) < 0)
|
||||
{
|
||||
MessageBox(NULL, _T("Unable to SET CONFIGURATION"), _T("Message"), MB_OK);
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
|
||||
if (usb_claim_interface(g_dev, 0) < 0)
|
||||
{
|
||||
usb_close(g_dev);
|
||||
MessageBox(NULL, _T("Unable to CLAIM DEVICE"), _T("Message"), MB_OK);
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int CKeyenceTM065_Proto::Exit_Keyence()
|
||||
{
|
||||
if (g_dev)
|
||||
{
|
||||
usb_release_interface(g_dev,0);
|
||||
usb_close(g_dev);
|
||||
g_dev = NULL;
|
||||
}
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
// This startup just kicks off the EP_KEYENCE_81 worker thread.
|
||||
//******************************************************************************
|
||||
int CKeyenceTM065_Proto::_start_machine()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//===============================================================================
|
||||
int CKeyenceTM065_Proto::_shutdown_machine()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//===============================================================================
|
||||
// Keyence Protocol - This can be processed serially.
|
||||
// Send data on EP_01 channel.
|
||||
// Receive data on EP_01.
|
||||
// Send data on EP_82 channel.
|
||||
// Receive data on EP_82 channel.
|
||||
// if more data needs to be received, send data to EP_82 channel.
|
||||
// (Note, we do not receive Image Data, so we will not receive 0x40000 bytes.
|
||||
// But we must make provision for receiving and sending 0x40000 bytes. (512x512).
|
||||
//
|
||||
// The following two commands is all we need:
|
||||
//
|
||||
// usb_bulk_write(g_dev, iEP, (char *)(ep_buff._buff+33), ep_buff._send_size, 5000);
|
||||
// iRcvSize = usb_bulk_read(g_dev, iEP, (char *)ep_buff._buff, MAX_KEYENCE_EP_BUFF_SIZE, 5000);
|
||||
//
|
||||
//===============================================================================
|
||||
int CKeyenceTM065_Proto::_send_usb_data()
|
||||
{
|
||||
int _ret;
|
||||
_ret = usb_bulk_setup_async(g_dev, &ep_buff._async_context, ep_buff._iEP);
|
||||
if (_ret < 0)
|
||||
{
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
_ret = usb_submit_async(ep_buff._async_context, (char *)ep_buff._bin, ep_buff._send_size);
|
||||
if (_ret < 0)
|
||||
{
|
||||
usb_free_async(&ep_buff._async_context);
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
_ret = usb_reap_async(ep_buff._async_context, 10000);
|
||||
if (_ret > 0)
|
||||
{
|
||||
ep_buff._recv_size = _ret;
|
||||
_process_rcv_transfer_data();
|
||||
usb_free_async(&ep_buff._async_context);
|
||||
}
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_send_cmd_KEYENCE_CMD_GET_DATA()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_process_KEYENCE_CMD_GET_DATA()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_get_image()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_put_program()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_init_program()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_get_program()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_read_env()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_write_env()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_set_config() // sets trigger etc.
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
//
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_replay_capture(CString s_replay_file)
|
||||
{
|
||||
//struct_ep ep_buff;
|
||||
//ep_buff._buff = (unsigned char *)malloc(MAX_KEYENCE_EP_BUFF_SIZE);
|
||||
//ep_buff._bin = (unsigned char *)malloc(MAX_KEYENCE_EP_BUFF_SIZE);
|
||||
char cTemp[9];
|
||||
FILE* pInFile;
|
||||
_wfopen_s(&pInFile, s_replay_file, _T("r"));
|
||||
if (pInFile == NULL)
|
||||
{
|
||||
return KEYENCE_STATUS_REPLAY_FILE_ERROR;
|
||||
};
|
||||
fgets((char *)ep_buff._buff, MAX_KEYENCE_EP_BUFF_SIZE, pInFile ); // pick up the first line
|
||||
TRACE("\nReading1 %s", ep_buff._buff);
|
||||
CProto_Util* _protoUtil = new CProto_Util();
|
||||
while (!feof(pInFile))
|
||||
{
|
||||
memset(cTemp, 0 , 9);
|
||||
memcpy(cTemp, ep_buff._buff+24, 8);
|
||||
sscanf_s(cTemp, "%8x", &ep_buff._send_size); // get the length of the transmission
|
||||
ep_buff._recv_size = ep_buff._send_size;
|
||||
memcpy(cTemp, ep_buff._buff+33, 8);
|
||||
sscanf_s(cTemp, "%8x", &ep_buff._cmd0);
|
||||
ep_buff._iEP = (*(ep_buff._buff+21) == '1') ? 0x01:0x82;
|
||||
if (*ep_buff._buff == '>')
|
||||
{
|
||||
if (ep_buff._iEP == 0x82)
|
||||
memset(ep_buff._bin, ep_buff._send_size, 0);
|
||||
else
|
||||
{
|
||||
_protoUtil->_char2bin(ep_buff._buff+33, ep_buff._bin, ep_buff._send_size);
|
||||
if (ep_buff._send_size == 0x200) // Temporary patch to see how Keyence behaves.
|
||||
{
|
||||
memset(ep_buff._bin+12, 0, 0x200);
|
||||
}
|
||||
};
|
||||
_send_usb_data();
|
||||
fgets((char *)ep_buff._buff, MAX_KEYENCE_EP_BUFF_SIZE, pInFile ); // skip the input line
|
||||
}
|
||||
fgets((char *)ep_buff._buff, MAX_KEYENCE_EP_BUFF_SIZE, pInFile ); // pick up the first line
|
||||
Sleep(50);
|
||||
};
|
||||
delete _protoUtil;
|
||||
fclose(pInFile);
|
||||
//free(ep_buff._buff);
|
||||
//free(ep_buff._bin);
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
//
|
||||
//==============================================================
|
||||
int CKeyenceTM065_Proto::_read_prs_file(CString cFileName)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(cFileName);
|
||||
return 0;
|
||||
};
|
||||
@@ -0,0 +1,213 @@
|
||||
// protocol for control SevenOcean's Machine
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifndef AFX_KEYENCE_Proto_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
||||
#define AFX_KEYENCE_Proto_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "..\..\..\..\..\ThirdParty\UsbSupport\LibUsb_Win\Include\lusb0_usb.h"
|
||||
#include "..\KeyenceTM065\KeyenceStatus.h"
|
||||
|
||||
#define _CMD0_0800 0x08000000
|
||||
#define _CMD0_0C00 0x0c000000 // -> 0704 Reply 0800 0705
|
||||
// -> 0710 Reply 0c00 0711
|
||||
// -> 071a Reply 8400 071b
|
||||
|
||||
#define _CMD0_100a 0x100a0000 // -> 0730 Reply 0c00 0731
|
||||
#define _CMD0_1400 0x14000000 // ???? Send 4 bytes 1400,
|
||||
// then send 200 bytes
|
||||
// Request 40000 bytes image
|
||||
#define _CMD0_3000 0x30000000 // -> 0730 Reply 0c00 0731
|
||||
#define _CMD0_4800 0x48000000 // -> 0730 Reply 0c00 0731
|
||||
#define _CMD0_4c00 0x4c000000 // -> 0730 Reply 0c00 0731
|
||||
|
||||
#define _CMD1_0730 0x07300000
|
||||
#define _CMD1_0731 0x07310000
|
||||
|
||||
#define MAX_KEYENCE_EP_BUFF_SIZE 0X40000
|
||||
|
||||
#define USB_ENDPOINT_TYPE_CONTROL 0
|
||||
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
|
||||
#define USB_ENDPOINT_TYPE_BULK 2
|
||||
#define USB_ENDPOINT_TYPE_INTERRUPT 3
|
||||
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 1
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
|
||||
|
||||
// Device configuration and interface id.
|
||||
#define KEYENCE_USB_CONFIG 1
|
||||
#define KEYENCE_USB_INTF 0
|
||||
|
||||
#define EP_KEYENCE_01 0x01
|
||||
#define EP_KEYENCE_82 0x82
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
|
||||
#define KEYENCE_VID 0x0720
|
||||
#define KEYENCE_PID 0x0015
|
||||
|
||||
struct struct_ep
|
||||
{
|
||||
unsigned char _iEP;
|
||||
unsigned char *_buff;
|
||||
BYTE *_bin;
|
||||
int _cmd0;
|
||||
int _cmd1;
|
||||
int _send_size;
|
||||
int _recv_size;
|
||||
void *_async_context;
|
||||
};
|
||||
|
||||
struct TM_PRS_BUFF {
|
||||
struct TM_PRS_HDR {
|
||||
char _tm_name[20];
|
||||
unsigned char _tm_id[4];
|
||||
} _tm_hdr;
|
||||
struct TM_PRS_PROG {
|
||||
unsigned char _pid[4];
|
||||
DWORD _nbr;
|
||||
char _name[16];
|
||||
BYTE _trigger_mode; // Ext/Cont
|
||||
BYTE _int_prevention; // ON/Off
|
||||
BYTE _trigger_rate; // ON/OFF
|
||||
BYTE _unk1;
|
||||
unsigned char _unk2[4];
|
||||
struct TM_HEAD {
|
||||
BYTE _x_measure_range;
|
||||
BYTE _y_measure_range;
|
||||
BYTE _threshold;
|
||||
BYTE _unk1; // Not used
|
||||
struct TM_MASK {
|
||||
BYTE _mk_type[4];
|
||||
short int _mk_x1; // Triangle has three pairs, rectangle has two pairs.
|
||||
short int _mk_y1;
|
||||
short int _mk_x2;
|
||||
short int _mk_y2;
|
||||
short int _mk_x3;
|
||||
short int _mk_y3;
|
||||
} _tm_mask[5];
|
||||
} _tm_head[2];
|
||||
BYTE _unk3[4];
|
||||
BYTE _unk4[4];
|
||||
struct TM_CORR {
|
||||
BYTE _unk1[4];
|
||||
short int _i1;
|
||||
short int _i2;
|
||||
short int _i3;
|
||||
short int _i4;
|
||||
BYTE _unk5[4];
|
||||
BYTE _unk6[4];
|
||||
BYTE _unk7[4];
|
||||
BYTE _unk8[4];
|
||||
BYTE _unk9[4];
|
||||
BYTE _unk10[4];
|
||||
} _tm_head_corr[2];
|
||||
struct TM_CORR1 {
|
||||
BYTE _img_reg;
|
||||
BYTE _img_src_speed;
|
||||
BYTE _img_src_ang;
|
||||
BYTE _img_corr_val;
|
||||
BYTE _unk4[4];
|
||||
short int _i[12];
|
||||
BYTE _unk5[4];
|
||||
BYTE _unk6[4];
|
||||
short int _i1[4];
|
||||
BYTE _unk7[4];
|
||||
BYTE _unk8[4];
|
||||
BYTE _unk9[4];
|
||||
} _tm_head_corr1[2];
|
||||
BYTE _meas_type;
|
||||
BYTE _unk_type_1;
|
||||
BYTE _a_b_calculation;
|
||||
BYTE _unk_type_3;
|
||||
BYTE _unk11[4];
|
||||
short int _x1;
|
||||
short int _y1;
|
||||
short int _x2;
|
||||
short int _y2;
|
||||
BYTE _unk5[1008];
|
||||
struct TM_OUT
|
||||
{
|
||||
char _out_name[16];
|
||||
BYTE _unk1[4];
|
||||
BYTE _ave_meas; // bin pos;
|
||||
BYTE _alarm;
|
||||
BYTE _meas_mode;
|
||||
BYTE _min_disp_unit;
|
||||
long _unk_scale1;
|
||||
long _meas_input_1_v1;
|
||||
long _meas_input_1_d1;
|
||||
long _meas_input_2_v2;
|
||||
long _meas_input_2_d2;
|
||||
long _unk_scale6;
|
||||
long _unk_scale7;
|
||||
long _offset;
|
||||
long _tol_upper_limit;
|
||||
long _tol_lower_limit;
|
||||
} _tm_out[16];
|
||||
BYTE _tm_timing_term_byte[16];
|
||||
BYTE _tm_zero_term_byte[16];
|
||||
BYTE _tm_binary_output_byte[16];
|
||||
BYTE _unk_flag[4];
|
||||
struct {
|
||||
long _meas_val_1;
|
||||
long _output_voltage_1;
|
||||
long _meas_val_2;
|
||||
long _output_voltage_2;
|
||||
} _tm_analog[2];
|
||||
BYTE _storage;
|
||||
BYTE _image_storage_head;
|
||||
BYTE _image_storage_mode;
|
||||
BYTE _unk_flag11;
|
||||
BYTE _image_storage_no_data_pts;
|
||||
BYTE _image_storage_skipping;
|
||||
BYTE _unk_flags2[2];
|
||||
BYTE _auto_send[16]; //
|
||||
BYTE _data_out_timing;
|
||||
BYTE _unk_flags3[3];
|
||||
long _checksum;
|
||||
} _tm_prs[16];
|
||||
BYTE _tm_unk[580];
|
||||
struct TM_TRLR {
|
||||
BYTE _aaa[4];
|
||||
DWORD _trailer[33*8];
|
||||
BYTE _a8a[4];
|
||||
} _tm_trailer;
|
||||
};
|
||||
|
||||
//======================================================================================
|
||||
class CKeyenceTM065_Proto
|
||||
{
|
||||
public:
|
||||
//
|
||||
CKeyenceTM065_Proto();
|
||||
virtual ~CKeyenceTM065_Proto();
|
||||
struct_ep ep_buff;
|
||||
usb_dev_handle *g_dev;
|
||||
int Init_Keyence();
|
||||
int Exit_Keyence();
|
||||
void _process_rcv_transfer_data();
|
||||
usb_dev_handle* _open_usb_dev(void);
|
||||
int _usb_reset(void);
|
||||
int _start_machine();
|
||||
int _shutdown_machine();
|
||||
int _send_usb_data();
|
||||
int _send_cmd_KEYENCE_CMD_GET_DATA();
|
||||
int _process_KEYENCE_CMD_GET_DATA();
|
||||
int _get_image();
|
||||
int _put_program();
|
||||
int _get_program();
|
||||
int _init_program();
|
||||
int _read_env();
|
||||
int _write_env();
|
||||
int _set_config(); // sets trigger etc.
|
||||
int _replay_capture(CString cFileName);
|
||||
int _read_prs_file(CString cFileName);
|
||||
TM_PRS_BUFF TM_Buff;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "StdAfx.h"
|
||||
#include "Keyence_Laser.h"
|
||||
|
||||
|
||||
|
||||
CKeyence_Laser::CKeyence_Laser()
|
||||
{
|
||||
}
|
||||
|
||||
CKeyence_Laser::~CKeyence_Laser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CKeyence_Laser::KeyenceLaserInit(void)
|
||||
{
|
||||
m_hLkif=LoadLibrary(_T("LkIF.dll"));
|
||||
if(m_hLkif)
|
||||
{
|
||||
m_pGetCalcData=(pLKIF_GetCalcData)GetProcAddress(m_hLkif,"LKIF_GetCalcData");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void CKeyence_Laser::Get_KeyenceLaserData(float *LaserValue1,float *LaserValue2)
|
||||
{
|
||||
*LaserValue1=10;
|
||||
*LaserValue2=10;
|
||||
LKIF_FLOATVALUE GetVal1,GetVal2;
|
||||
if((*m_pGetCalcData)(&GetVal1,&GetVal2)!=1)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
switch(GetVal1.FloatResult)
|
||||
{
|
||||
case LKIF_FLOATRESULT_RANGEOVER_P:
|
||||
{
|
||||
*LaserValue1=50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_RANGEOVER_N:
|
||||
{
|
||||
*LaserValue1=-50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_WAITING:
|
||||
{
|
||||
*LaserValue1=0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*LaserValue1=GetVal1.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(GetVal2.FloatResult)
|
||||
{
|
||||
case LKIF_FLOATRESULT_RANGEOVER_P:
|
||||
{
|
||||
*LaserValue2=50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_RANGEOVER_N:
|
||||
{
|
||||
*LaserValue2=-50;
|
||||
break;
|
||||
}
|
||||
case LKIF_FLOATRESULT_WAITING:
|
||||
{
|
||||
*LaserValue2=0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*LaserValue2=GetVal2.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// protocol for control SevenOcean's Machine
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifndef AFX_KEYENCE__LASER_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
||||
#define AFX_KEYENCE__LASER_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
||||
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "LkIF.h"
|
||||
|
||||
typedef BOOL (WINAPI* pLKIF_GetCalcData)(OUT LKIF_FLOATVALUE *CalcData1,OUT LKIF_FLOATVALUE *CalcData2);
|
||||
// Starting the Data Storage
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageStart)(void);
|
||||
// Stopping the Data Storage
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageStop)(void);
|
||||
// Initializing the Data Storage
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageInit)(void);
|
||||
// Outputting the Data Storage
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageGetData)(IN int OutNo,IN int NumOutBuffer,OUT LKIF_FLOATVALUE *OutBuffer,OUT int *NumReceived);
|
||||
// Data Storage Accumulation Status Output
|
||||
typedef BOOL (WINAPI* pLKIF_DataStorageGetStatus)(IN int OutNo,OUT BOOL *IsStorage,OUT int *NumStorageData);
|
||||
|
||||
|
||||
//======================================================================================
|
||||
class CKeyence_Laser
|
||||
{
|
||||
public:
|
||||
|
||||
CKeyence_Laser();
|
||||
virtual ~CKeyence_Laser();
|
||||
|
||||
//»ñÈ¡Êý¾ÝµÄº¯ÊýÖ¸Õë
|
||||
pLKIF_GetCalcData m_pGetCalcData;
|
||||
HINSTANCE m_hLkif;
|
||||
void KeyenceLaserInit(void);
|
||||
void Get_KeyenceLaserData(float *LaserValue1,float *LaserValue2);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,285 @@
|
||||
#include "stdafx.h"
|
||||
#include "Keyence_Proto.h"
|
||||
#include "KeyenceStatus.h"
|
||||
|
||||
#define MY_CONFIG 1
|
||||
#define MAX_DEVPATH_LENGTH 256
|
||||
#define ENDPOINT_TIMEOUT 500
|
||||
|
||||
//******************************************************************************
|
||||
// Look at the return data from EP_01
|
||||
// The result determines how many EP_82 we need to send out based on _cmd0 and _cmd1.
|
||||
//
|
||||
void CKeyence_Proto::_process_rcv_transfer_data_ep01()
|
||||
{
|
||||
switch (ep_buff_ep01._cmd0)
|
||||
{
|
||||
case _CMD0_0800:
|
||||
break;
|
||||
case _CMD0_0C00:
|
||||
switch (ep_buff_ep01._cmd1)
|
||||
{
|
||||
case _CMD1_0730:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
case _CMD0_100a:
|
||||
break;
|
||||
case _CMD0_1400:
|
||||
break;
|
||||
case _CMD0_3000:
|
||||
break;
|
||||
case _CMD0_4800:
|
||||
break;
|
||||
case _CMD0_4c00:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
//******************************************************************************
|
||||
void CKeyence_Proto::_process_rcv_transfer_data_ep82()
|
||||
{
|
||||
_process_KEYENCE_CMD_GET_LASER_DATA();
|
||||
};
|
||||
|
||||
//******************************************************************************
|
||||
CKeyence_Proto::CKeyence_Proto()
|
||||
{
|
||||
ep_buff_ep82._buff = (char *)malloc(MAX_KEYENCE_EP_01_BUFF_SIZE);
|
||||
ep_buff_ep01._buff = (char *)malloc(MAX_KEYENCE_EP_82_BUFF_SIZE);
|
||||
ep_buff_ep01._size = 0;
|
||||
ep_buff_ep82._size = 0;
|
||||
ep_buff_ep01._async_context = NULL;
|
||||
ep_buff_ep82._async_context = NULL;
|
||||
ep_buff_ep01._cmd0 = 0;
|
||||
ep_buff_ep82._cmd0 = 0;
|
||||
ep_buff_ep01._cmd1 = 0;
|
||||
ep_buff_ep82._cmd1 = 0;
|
||||
};
|
||||
|
||||
//******************************************************************************
|
||||
CKeyence_Proto::~CKeyence_Proto()
|
||||
{
|
||||
free(ep_buff_ep82._buff);
|
||||
free(ep_buff_ep01._buff);
|
||||
}
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
//******************************************************************************
|
||||
|
||||
//******************************************************************************
|
||||
usb_dev_handle* CKeyence_Proto::_open_usb_dev(void)
|
||||
{
|
||||
struct usb_bus *bus = NULL;
|
||||
struct usb_device *dev = NULL;
|
||||
|
||||
for (bus = usb_get_busses(); bus; bus = bus->next)
|
||||
{
|
||||
for (dev = bus->devices; dev; dev = dev->next)
|
||||
{
|
||||
if (dev->descriptor.idVendor == KEYENCE_VID && dev->descriptor.idProduct == KEYENCE_PID)
|
||||
{
|
||||
return usb_open(dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int CKeyence_Proto::_usb_reset(void)
|
||||
{
|
||||
if (g_dev)
|
||||
{
|
||||
usb_reset(g_dev);
|
||||
g_dev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int CKeyence_Proto::Init_Keyence()
|
||||
{
|
||||
int usb_status = NULL;
|
||||
usb_init(); // initialize the library
|
||||
usb_status = usb_find_busses(); // find all busses
|
||||
usb_status = usb_find_devices(); // find all connected devices
|
||||
g_dev = _open_usb_dev();
|
||||
if (!g_dev)
|
||||
{
|
||||
MessageBox(NULL, _T("Unable to open device"), _T("Message"), MB_OK);
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
|
||||
if (usb_set_configuration(g_dev, MY_CONFIG) < 0)
|
||||
{
|
||||
MessageBox(NULL, _T("Unable to SET CONFIGURATION"), _T("Message"), MB_OK);
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
|
||||
if (usb_claim_interface(g_dev, 0) < 0)
|
||||
{
|
||||
usb_close(g_dev);
|
||||
MessageBox(NULL, _T("Unable to CLAIM DEVICE"), _T("Message"), MB_OK);
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
int CKeyence_Proto::Exit_Keyence()
|
||||
{
|
||||
if (g_dev)
|
||||
{
|
||||
usb_release_interface(g_dev,0);
|
||||
usb_close(g_dev);
|
||||
g_dev = NULL;
|
||||
}
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
// This startup just kicks off the EP_KEYENCE_81 worker thread.
|
||||
//******************************************************************************
|
||||
int CKeyence_Proto::_start_machine()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//===============================================================================
|
||||
int CKeyence_Proto::_shutdown_machine()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//===============================================================================
|
||||
// Keyence Protocol - This can be processed serially.
|
||||
// Send data on EP_01 channel.
|
||||
// Receive data on EP_01.
|
||||
// Send data on EP_82 channel.
|
||||
// Receive data on EP_82 channel.
|
||||
// if more data needs to be received, send data to EP_82 channel.
|
||||
// (Note, we do not receive Image Data, so we will not receive 0x40000 bytes.
|
||||
// But we must make provision for receiving and sending 0x40000 bytes. (512x512).
|
||||
//===============================================================================
|
||||
int CKeyence_Proto::_send_usb_data()
|
||||
{
|
||||
int _ret;
|
||||
_ret = usb_bulk_setup_async(g_dev, &ep_buff_ep01._async_context, EP_KEYENCE_01);
|
||||
if (_ret < 0)
|
||||
{
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
_ret = usb_submit_async(ep_buff_ep01._async_context, ep_buff_ep01._buff, ep_buff_ep01._size);
|
||||
if (_ret < 0)
|
||||
{
|
||||
usb_free_async(&ep_buff_ep01._async_context);
|
||||
return KEYENCE_STATUS_DATALINK_ERROR;
|
||||
}
|
||||
_ret = usb_reap_async(ep_buff_ep01._async_context, 10000);
|
||||
if (_ret > 0)
|
||||
{
|
||||
_process_rcv_transfer_data_ep01();
|
||||
usb_free_async(&ep_buff_ep01._async_context);
|
||||
}
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
int CKeyence_Proto::_send_cmd_KEYENCE_CMD_GET_LASER_DATA()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyence_Proto::_process_KEYENCE_CMD_GET_LASER_DATA()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyence_Proto::_get_image()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyence_Proto::_put_program()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyence_Proto::_read_env()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyence_Proto::_write_env()
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
int CKeyence_Proto::_set_config() // sets trigger etc.
|
||||
{
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
};
|
||||
|
||||
//==============================================================
|
||||
//
|
||||
// The file must be in groups of 4s.
|
||||
//
|
||||
// > [82] Signal Receive Data
|
||||
//
|
||||
// > [endpoint 0x00000082] 0000000e
|
||||
// < [endpoint 0x00000082] 00000009 0800000007050500ff
|
||||
// > [endpoint 0x00000082] 00000005
|
||||
// < [endpoint 0x00000082] 00000000
|
||||
//
|
||||
// > Signals Send Data
|
||||
//
|
||||
// > [endpoint 0x00000001] 00000004 0c000000
|
||||
// < [endpoint 0x00000001] 00000004
|
||||
// > [endpoint 0x00000001] 00000200 0c00000007040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099972afd90d52afd3ff72afd49062bfd63142bfd3cff2afd81e42afd3abc2afdab802afdee0c2afdf93e29fd946227fde8a827fd212263fd6b7562fd237461fd9d4462fd708962fda6b462fd57db62fd99ed62fd96f462fdb2e362fda4c662fd53a162fd6a6962fd740e62fd266c61fd3f0a60fdd41360fdb9839afd06319afd259e99fdfd299afdf7689afd71979afd6cb69afd66c99afd64d09afd04be9afd8ba19afdfc7a9afd8b469afdcdfb99fd1c7b99fd2c7698fd3e5498fd46ffd1fd5eebd1fdcaa6d1fd4506d2fdbc3fd2fdb568d2fda982d2fdad8bd2fd8790d2fddd81d2fdc66cd2fd4a4bd2fd5e1ad2fd37d9d1fd3872d1fdd8b2d0fdaa74d0fdce9009fe8ba509fe749509fe18d809fe01050afe852a0afe1a3f0afe1e490afe4c4f0afece470afe96340afe84150afe48e609fe7ea909fe095609fed3c908fe697708fe433141fe105e41fe8b6d41fe2a9d41fe20c641feb0e241fe3af541fe98fe41fe11fe41feadf741feffe541fe8fce41feeaa841fec46f41feb72a41fe77c340feee6740fe23e978fe741a79fe363d79fe9c5e79fec27a79fe449679fe92a979fe1aae79fea9aa79fe0ca179fe219379fe
|
||||
// < [endpoint 0x00000001] 00000200
|
||||
//
|
||||
//
|
||||
//==============================================================
|
||||
int CKeyence_Proto::_replay_capture(CString s_replay_file)
|
||||
{
|
||||
char cSize[9];
|
||||
int iSendSize;
|
||||
int iRcvSize;
|
||||
FILE* pInFile;
|
||||
int iEP;
|
||||
_wfopen_s(&pInFile, s_replay_file, _T("r"));
|
||||
if (pInFile == NULL)
|
||||
return KEYENCE_STATUS_REPLAY_FILE_ERROR;
|
||||
fgets(ep_buff._buff, MAX_KEYENCE_EP_BUFF_SIZE, pInFile ); // pick up the first line
|
||||
while (!feof(pInFile))
|
||||
{
|
||||
memset(cSize, 0 , 9);
|
||||
memcpy(cSize, ep_buff._buff+24, 8);
|
||||
sscanf_s(cSize, "%8x", &iSendSize); // get the length of the transmission
|
||||
iEP = (*(ep_buff._buff+21) == '1') ? 0x01:0x82;
|
||||
if (*ep_buff._buff == '>')
|
||||
{
|
||||
fgets((char *)ep_buff._buff, MAX_KEYENCE_EP_BUFF_SIZE, pInFile ); // skip the input line
|
||||
usb_bulk_write(g_dev, iEP, (char *)(ep_buff._buff+33), iSendSize, 5000);
|
||||
iRcvSize = usb_bulk_read(g_dev, iEP, (char *)ep_buff._buff, MAX_KEYENCE_EP_BUFF_SIZE, 5000);
|
||||
}
|
||||
fgets((char *)ep_buff._buff, MAX_KEYENCE_EP_BUFF_SIZE, pInFile ); // pick up the first line
|
||||
};
|
||||
fclose(pInFile);
|
||||
return KEYENCE_STATUS_NORMAL;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// protocol for control SevenOcean's Machine
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifndef AFX_KEYENCE_Proto_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
||||
#define AFX_KEYENCE_Proto_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "..\..\..\..\..\ThirdParty\UsbSupport\LibUsb_Win\Include\lusb0_usb.h"
|
||||
#include "..\Keyence\KeyenceStatus.h"
|
||||
|
||||
#define _CMD0_0800 0x08000000
|
||||
#define _CMD0_0C00 0x0c000000 // -> 0704 Reply 0800 0705
|
||||
// -> 0710 Reply 0c00 0711
|
||||
// -> 071a Reply 8400 071b
|
||||
|
||||
#define _CMD0_100a 0x100a0000 // -> 0730 Reply 0c00 0731
|
||||
#define _CMD0_1400 0x14000000 // ???? Send 4 bytes 1400,
|
||||
// then send 200 bytes
|
||||
// Request 40000 bytes image
|
||||
#define _CMD0_3000 0x30000000 // -> 0730 Reply 0c00 0731
|
||||
#define _CMD0_4800 0x48000000 // -> 0730 Reply 0c00 0731
|
||||
#define _CMD0_4c00 0x4c000000 // -> 0730 Reply 0c00 0731
|
||||
|
||||
#define _CMD1_0730 0x07300000
|
||||
#define _CMD1_0731 0x07310000
|
||||
|
||||
#define MAX_KEYENCE_EP_01_BUFF_SIZE 0xC00 // enough for 512x512 bytes image
|
||||
#define MAX_KEYENCE_EP_82_BUFF_SIZE 0x40000 // enough for 512x512 bytes image
|
||||
#define MAX_KEYENCE_EP_BUFF_SIZE 0X40000
|
||||
|
||||
#define USB_ENDPOINT_TYPE_CONTROL 0
|
||||
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
|
||||
#define USB_ENDPOINT_TYPE_BULK 2
|
||||
#define USB_ENDPOINT_TYPE_INTERRUPT 3
|
||||
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 1
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
|
||||
|
||||
// Device configuration and interface id.
|
||||
#define KEYENCE_USB_CONFIG 1
|
||||
#define KEYENCE_USB_INTF 0
|
||||
|
||||
#define EP_KEYENCE_01 0x01
|
||||
#define EP_KEYENCE_82 0x82
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
|
||||
#define KEYENCE_VID 0x0720
|
||||
#define KEYENCE_PID 0x000A
|
||||
|
||||
struct struct_ep
|
||||
{
|
||||
char *_buff;
|
||||
DWORD _cmd0;
|
||||
DWORD _cmd1;
|
||||
int _size;
|
||||
void *_async_context;
|
||||
};
|
||||
|
||||
//======================================================================================
|
||||
class CKeyence_Proto
|
||||
{
|
||||
public:
|
||||
//
|
||||
CKeyence_Proto();
|
||||
virtual ~CKeyence_Proto();
|
||||
struct_ep ep_buff_ep01;
|
||||
union
|
||||
{
|
||||
struct_ep ep_buff_ep82;
|
||||
struct_ep ep_buff;
|
||||
};
|
||||
usb_dev_handle *g_dev;
|
||||
int Init_Keyence();
|
||||
int Exit_Keyence();
|
||||
void _process_rcv_transfer_data_ep01();
|
||||
void _process_rcv_transfer_data_ep82();
|
||||
usb_dev_handle* _open_usb_dev(void);
|
||||
int _usb_reset(void);
|
||||
int _start_machine();
|
||||
int _shutdown_machine();
|
||||
int _send_usb_data();
|
||||
int _send_cmd_KEYENCE_CMD_GET_LASER_DATA();
|
||||
int _process_KEYENCE_CMD_GET_LASER_DATA();
|
||||
int _get_image();
|
||||
int _put_program();
|
||||
int _read_env();
|
||||
int _write_env();
|
||||
int _set_config(); // sets trigger etc.
|
||||
int _replay_capture(CString cFileName);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,320 @@
|
||||
#ifndef LKIF_INCLUDED
|
||||
#define LKIF_INCLUDED
|
||||
|
||||
#ifdef I_AM_LKIF
|
||||
#define EXP __declspec(dllexport)
|
||||
#else
|
||||
#define EXP __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
// Measurement value structures
|
||||
typedef enum {
|
||||
LKIF_FLOATRESULT_VALID, // valid data
|
||||
LKIF_FLOATRESULT_RANGEOVER_P, // over range at positive (+) side
|
||||
LKIF_FLOATRESULT_RANGEOVER_N, // over range at negative (-) side
|
||||
LKIF_FLOATRESULT_WAITING, // comparator result
|
||||
} LKIF_FLOATRESULT;
|
||||
|
||||
typedef struct {
|
||||
LKIF_FLOATRESULT FloatResult; // valid or invalid data
|
||||
float Value; // measurement value during LKIF_FLOATRESULT_VALID.
|
||||
// Any other times will return an invalid value
|
||||
} LKIF_FLOATVALUE;
|
||||
///////////////////////////////////////////////
|
||||
// Measurement Control Command
|
||||
//
|
||||
// Measurement Value Output
|
||||
EXP BOOL WINAPI LKIF_GetCalcData(OUT LKIF_FLOATVALUE *CalcData1,OUT LKIF_FLOATVALUE *CalcData2);
|
||||
// Timing ON/OFF
|
||||
EXP BOOL WINAPI LKIF_SetTiming(IN int OutNo,IN BOOL IsOn);
|
||||
// Auto-zero ON/OFF
|
||||
EXP BOOL WINAPI LKIF_SetZero(IN int OutNo,IN BOOL IsOn);
|
||||
// Reset
|
||||
EXP BOOL WINAPI LKIF_SetReset(IN int OutNo);
|
||||
// Panel Lock
|
||||
EXP BOOL WINAPI LKIF_SetPanelLock(IN BOOL IsLock);
|
||||
// Program Change
|
||||
EXP BOOL WINAPI LKIF_SetProgramNo(IN int ProgramNo);
|
||||
// Program Check
|
||||
EXP BOOL WINAPI LKIF_GetProgramNo(OUT int *ProgramNo);
|
||||
// Statistical Results Output
|
||||
typedef struct {
|
||||
LKIF_FLOATVALUE ToleUpper; // tolerance upper limit
|
||||
LKIF_FLOATVALUE ToleLower; // tolerance lower limit
|
||||
LKIF_FLOATVALUE AverageValue; // average value
|
||||
LKIF_FLOATVALUE MaxValue; // maximum value
|
||||
LKIF_FLOATVALUE MinValue; // minimum value
|
||||
LKIF_FLOATVALUE DifValue; // maximum value - minimum value
|
||||
LKIF_FLOATVALUE SdValue; // standard deviation
|
||||
LONG DataCnt; // number of all data
|
||||
LONG HighDataCnt; // number of tolerance High data
|
||||
LONG GoDataCnt; // number of tolerance Go data
|
||||
LONG LowDataCnt; // number of tolerance Low data
|
||||
} LKIF_FIGUREDATA;
|
||||
EXP BOOL WINAPI LKIF_GetFigureData(IN int OutNo,OUT LKIF_FIGUREDATA *FigureData);
|
||||
// Clearing Statistics
|
||||
EXP BOOL WINAPI LKIF_ClearFigureData(void);
|
||||
// Starting the Data Storage
|
||||
EXP BOOL WINAPI LKIF_DataStorageStart(void);
|
||||
// Stopping the Data Storage
|
||||
EXP BOOL WINAPI LKIF_DataStorageStop(void);
|
||||
// Initializing the Data Storage
|
||||
EXP BOOL WINAPI LKIF_DataStorageInit(void);
|
||||
// Outputting the Data Storage
|
||||
EXP BOOL WINAPI LKIF_DataStorageGetData(IN int OutNo,IN int NumOutBuffer,OUT LKIF_FLOATVALUE *OutBuffer,OUT int *NumReceived);
|
||||
// Data Storage Accumulation Status Output
|
||||
EXP BOOL WINAPI LKIF_DataStorageGetStatus(IN int OutNo,OUT BOOL *IsStorage,OUT int *NumStorageData);
|
||||
// Receive Light Waveform
|
||||
EXP BOOL WINAPI LKIF_GetLight(IN int HeadNo,IN int PeekNo,OUT int *MeasurePosition,OUT int *NumReaded,OUT BYTE *Value);
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Change Parameter Command
|
||||
//
|
||||
// Display Panel Switch
|
||||
EXP BOOL WINAPI LKIF_SetPanel(IN int OutNo);
|
||||
// Set Tolerance
|
||||
EXP BOOL WINAPI LKIF_SetTolerance(IN int OutNo,IN int UpperLimit,IN int LowerLimit,IN int Hysteresis);
|
||||
// Set ABLE
|
||||
typedef enum {
|
||||
LKIF_ABLEMODE_AUTO, // automatic
|
||||
LKIF_ABLEMODE_MANUAL, // manual
|
||||
} LKIF_ABLEMODE;
|
||||
EXP BOOL WINAPI LKIF_SetAbleMode(IN int HeadNo,IN LKIF_ABLEMODE AbleMode);
|
||||
// Set ABLE Control Range
|
||||
EXP BOOL WINAPI LKIF_SetAbleMinMax(IN int HeadNo,IN int Min,IN int Max);
|
||||
// Set Measurement Mode
|
||||
typedef enum {
|
||||
LKIF_MEASUREMODE_NORMAL, // normal
|
||||
LKIF_MEASUREMODE_HALF_T, // translucent object
|
||||
LKIF_MEASUREMDOE_TRAN_1, // transparent object
|
||||
LKIF_MEASUREMODE_TRAN_2, // transparent object 2
|
||||
LKIF_MEASUREMODE_MRS, // multireflective object
|
||||
} LKIF_MEASUREMODE;
|
||||
EXP BOOL WINAPI LKIF_SetMeasureMode(IN int HeadNo,IN LKIF_MEASUREMODE MeasureMode);
|
||||
// Set Number of Times of Alarm Processing
|
||||
EXP BOOL WINAPI LKIF_SetNumAlarm(IN int HeadNo,IN int NumAlarm);
|
||||
// Set Alarm Level
|
||||
EXP BOOL WINAPI LKIF_SetAlarmLevel(IN int HeadNo,IN int AlarmLevel);
|
||||
// Starting the ABLE Calibration
|
||||
EXP BOOL WINAPI LKIF_AbleStart(IN int HeadNo);
|
||||
// Finishing the ABLE Calibration
|
||||
EXP BOOL WINAPI LKIF_AbleStop(void);
|
||||
// Stopping the ABLE Calibration
|
||||
EXP BOOL WINAPI LKIF_AbleCancel(void);
|
||||
// Set Mounting Mode
|
||||
typedef enum {
|
||||
LKIF_REFLECTIONMODE_DIFFUSION, // diffuse reflection
|
||||
LKIF_REFLECTIONMODE_MIRROR, // specular reflection
|
||||
} LKIF_REFLECTIONMODE;
|
||||
EXP BOOL WINAPI LKIF_SetReflectionMode(IN int HeadNo,IN LKIF_REFLECTIONMODE ReflectionMode);
|
||||
// Set Calculation Method
|
||||
typedef enum {
|
||||
LKIF_CALCMETHOD_HEADA, // head A
|
||||
LKIF_CALCMETHOD_HEADB, // head B
|
||||
LKIF_CALCMETHOD_HEAD_HEADA_PLUS_HEADB, // head A+head B
|
||||
LKIF_CALCMETHOD_HEAD_HEADA_MINUS_HEADB, // head A-head B
|
||||
LKIF_CALCMETHOD_HEAD_HEADA_TRANSPARENT, // head A transparent object
|
||||
LKIF_CALCMETHOD_HEAD_HEADB_TRANSPARENT, // head B transparent object
|
||||
} LKIF_CALCMETHOD;
|
||||
// Measurement target
|
||||
typedef enum {
|
||||
LKIF_CALCTARGET_PEAK_1, // peak 1
|
||||
LKIF_CALCTARGET_PEAK_2, // peak 2
|
||||
LKIF_CALCTARGET_PEAK_3, // peak 3
|
||||
LKIF_CALCTARGET_PEAK_4, // peak 4
|
||||
LKIF_CALCTARGET_PEAK_1_2, // peak 1-peak 2
|
||||
LKIF_CALCTARGET_PEAK_1_3, // peak 1-peak 3
|
||||
LKIF_CALCTARGET_PEAK_1_4, // peak 1-peak 4
|
||||
LKIF_CALCTARGET_PEAK_2_3, // peak 2-peak 3
|
||||
LKIF_CALCTARGET_PEAK_2_4, // peak 2-peak 4
|
||||
LKIF_CALCTARGET_PEAK_3_4, // peak 3-peak 4
|
||||
} LKIF_CALCTARGET;
|
||||
EXP BOOL WINAPI LKIF_SetCalcMethod(IN int OutNo,IN LKIF_CALCMETHOD CalcMethod,LKIF_CALCTARGET CalcTarget);
|
||||
// Set Scaling
|
||||
EXP BOOL WINAPI LKIF_SetScaling(IN int OutNo,IN int HeadNo,IN int InputValue1,IN int OutputValue1,IN int InputValue2,IN int OutputValue2);
|
||||
// Set Filter Mode
|
||||
typedef enum {
|
||||
LKIF_FILTERMODE_MOVING_AVERAGE, // moving average
|
||||
LKIF_FILTERMODE_LOWPASS, // low pass filter
|
||||
LKIF_FILTERMODE_HIGHPASS, // high pass filter
|
||||
} LKIF_FILTERMODE;
|
||||
EXP BOOL WINAPI LKIF_SetFilterMode(IN int OutNo,OUT LKIF_FILTERMODE FilterMode);
|
||||
// Set Number of Times for Averaging
|
||||
typedef enum {
|
||||
LKIF_AVERAGE_1, // 1 time
|
||||
LKIF_AVERAGE_4, //
|
||||
LKIF_AVERAGE_16, //
|
||||
LKIF_AVERAGE_64, //
|
||||
LKIF_AVERAGE_256, //
|
||||
LKIF_AVERAGE_1024, //
|
||||
LKIF_AVERAGE_4096, //
|
||||
LKIF_AVERAGE_16384, //
|
||||
LKIF_AVERAGE_65536, //
|
||||
LKIF_AVERAGE_262144, // 262144 times
|
||||
} LKIF_AVERAGE;
|
||||
EXP BOOL WINAPI LKIF_SetAverage(IN int OutNo,IN LKIF_AVERAGE Average);
|
||||
// Set Cutoff Frequency
|
||||
typedef enum {
|
||||
LKIF_CUTOFFFREQUENCY_1000, // 1000Hz
|
||||
LKIF_CUTOFFFREQUENCY_300, // 300Hz
|
||||
LKIF_CUTOFFFREQUENCY_100, // 100Hz
|
||||
LKIF_CUTOFFFREQUENCY_30, // 30Hz
|
||||
LKIF_CUTOFFFREQUENCY_10, // 10Hz
|
||||
LKIF_CUTOFFFREQUENCY_3, // 3Hz
|
||||
LKIF_CUTOFFFREQUENCY_1, // 1Hz
|
||||
LKIF_CUTOFFFREQUENCY_0_3, // 0.3Hz
|
||||
LKIF_CUTOFFFREQUENCY_0_1, // 0.1Hz
|
||||
} LKIF_CUTOFFFREQUENCY;
|
||||
EXP BOOL WINAPI LKIF_SetCutOffFrequency(IN int OutNo,IN LKIF_CUTOFFFREQUENCY CutOffFrequency);
|
||||
// Set Trigger Mode
|
||||
typedef enum {
|
||||
LKIF_TRIGGERMODE_EXT1, // external trigger 1
|
||||
LKIF_TRIGGERMODE_EXT2, // external trigger 2
|
||||
} LKIF_TRIGGERMODE;
|
||||
EXP BOOL WINAPI LKIF_SetTriggerMode(IN int OutNo,IN LKIF_TRIGGERMODE TriggerMode);
|
||||
// Set Offset
|
||||
EXP BOOL WINAPI LKIF_SetOffset(IN int OutNo,IN int Offset);
|
||||
// Set Analog Output Scaling
|
||||
EXP BOOL WINAPI LKIF_SetAnalogScaling(IN int OutNo,IN int InputValue1,IN int OutputVoltage1,IN int InputValue2,IN int OutputVoltage2);
|
||||
// Set Calculation Mode
|
||||
typedef enum {
|
||||
LKIF_CALCMODE_NORMAL, // normal
|
||||
LKIF_CALCMODE_PEAKHOLD, // peak hold
|
||||
LKIF_CALCMODE_BOTTOMHOLD, // bottom hold
|
||||
LKIF_CALCMODE_PEAKTOPEAKHOLD, // peak-to-peak hold
|
||||
LKIF_CALCMODE_SAMPLEHOLD, // sample hold
|
||||
LKIF_CALCMODE_AVERAGEHOLD, // average hold
|
||||
} LKIF_CALCMODE;
|
||||
EXP BOOL WINAPI LKIF_SetCalcMode(IN int OutNo,IN LKIF_CALCMODE CalcMode);
|
||||
// Set Minimum Display Unit
|
||||
typedef enum {
|
||||
LKIF_DISPLAYUNIT_0000_01MM, // 0.01mm
|
||||
LKIF_DISPLAYUNIT_000_001MM, // 0.001mm
|
||||
LKIF_DISPLAYUNIT_00_0001MM, // 0.0001mm
|
||||
LKIF_DISPLAYUNIT_0_00001MM, // 0.00001mm
|
||||
LKIF_DISPLAYUNIT_00000_1UM, // 0.1um
|
||||
LKIF_DISPLAYUNIT_0000_01UM, // 0.01um
|
||||
} LKIF_DISPLAYUNIT;
|
||||
EXP BOOL WINAPI LKIF_SetDisplayUnit(IN int OutNo,IN LKIF_DISPLAYUNIT DisplayUnit);
|
||||
// Set Analog-Through
|
||||
EXP BOOL WINAPI LKIF_SetAnalogThrough(IN int OutNo,IN BOOL IsOn);
|
||||
// Set Data Storage
|
||||
typedef enum {
|
||||
LKIF_TARGETOUT_NONE, // no target OUT
|
||||
LKIF_TARGETOUT_OUT1, // OUT1
|
||||
LKIF_TARGETOUT_OUT2, // OUT2
|
||||
LKIF_TARGETOUT_BOTH, // OUT1 and OUT2
|
||||
} LKIF_TARGETOUT;
|
||||
typedef enum {
|
||||
LKIF_STORAGECYCLE_1, // sampling rate x 1
|
||||
LKIF_STORAGECYCLE_2, // sampling rate x 2
|
||||
LKIF_STORAGECYCLE_5, // sampling rate x 5
|
||||
LKIF_STORAGECYCLE_10, // sampling rate x 10
|
||||
LKIF_STORAGECYCLE_20, // sampling rate x 20
|
||||
LKIF_STORAGECYCLE_50, // sampling rate x 50
|
||||
LKIF_STORAGECYCLE_100, // sampling rate x 100
|
||||
LKIF_STORAGECYCLE_200, // sampling rate x 200
|
||||
LKIF_STORAGECYCLE_500, // sampling rate x 500
|
||||
LKIF_STORAGECYCLE_1000, // sampling rate x 1000
|
||||
} LKIF_STORAGECYCLE;
|
||||
EXP BOOL WINAPI LKIF_SetDataStorage(IN LKIF_TARGETOUT TargetOut,IN int NumStorage,IN LKIF_STORAGECYCLE StorageCycle);
|
||||
// Set Sampling Rate
|
||||
typedef enum {
|
||||
LKIF_SAMPLINGCYCLE_20USEC, // 20us
|
||||
LKIF_SAMPLINGCYCLE_50USEC, // 50us
|
||||
LKIF_SAMPLINGCYCLE_100USEC, // 100us
|
||||
LKIF_SAMPLINGCYCLE_200USEC, // 200us
|
||||
LKIF_SAMPLINGCYCLE_500USEC, // 500us
|
||||
LKIF_SAMPLINGCYCLE_1MSEC, // 1ms
|
||||
} LKIF_SAMPLINGCYCLE;
|
||||
EXP BOOL WINAPI LKIF_SetSamplingCycle(IN LKIF_SAMPLINGCYCLE SamplingCycle);
|
||||
// Set Mutual Interference Prevention
|
||||
EXP BOOL WINAPI LKIF_SetMutualInterferencePrevention(IN BOOL IsOn);
|
||||
// Set Timing Synchronization
|
||||
typedef enum {
|
||||
LKIF_SYNCHRONIZATION_ASYNCHRONOUS, // asynchronous
|
||||
LKIF_SYNCHRONIZATION_SYNCHRONIZED, // synchronous
|
||||
} LKIF_SYNCHRONIZATION;
|
||||
EXP BOOL WINAPI LKIF_SetTimingSynchronization(IN LKIF_SYNCHRONIZATION Synchronization);
|
||||
// Set Comparator Output Format
|
||||
typedef enum {
|
||||
LKIF_TOLERANCE_COMPARATOR_OUTPUT_FORMAT_NORMAL, // normal
|
||||
LKIF_TOLERANCE_COMPARATOR_OUTPUT_FORMAT_HOLD, // hold
|
||||
LKIF_TOLERANCE_COMPARATOR_OUTPUT_FORMAT_OFF_DELAY, // off-delay
|
||||
} LKIF_TOLERANCE_COMPARATOR_OUTPUT_FORMAT;
|
||||
EXP BOOL WINAPI LKIF_SetToleranceComparatorOutputFormat(IN LKIF_TOLERANCE_COMPARATOR_OUTPUT_FORMAT ToleranceComparatorOutputFormat);
|
||||
// Set Strobe Time
|
||||
typedef enum {
|
||||
LKIF_STOROBETIME_2MS, // 2ms
|
||||
LKIF_STOROBETIME_5MS, // 5ms
|
||||
LKIF_STOROBETIME_10MS, // 10ms
|
||||
LKIF_STOROBETIME_20MS, // 20ms
|
||||
} LKIF_STOROBETIME;
|
||||
EXP BOOL WINAPI LKIF_SetStorobeTime(IN LKIF_STOROBETIME StorobeTime);
|
||||
///////////////////////////////////////////////
|
||||
// Check Parameter Command
|
||||
//
|
||||
// Display Panel Check
|
||||
EXP BOOL WINAPI LKIF_GetPanel(OUT int *OutNo);
|
||||
// Get Tolerance
|
||||
EXP BOOL WINAPI LKIF_GetTolerance(IN int OutNo,OUT int *UpperLimit,OUT int *LowerLimit,OUT int *Hysteresis);
|
||||
// Get ABLE
|
||||
EXP BOOL WINAPI LKIF_GetAbleMode(IN int HeadNo,OUT LKIF_ABLEMODE *AbleMode);
|
||||
// ABLE Control Range
|
||||
EXP BOOL WINAPI LKIF_GetAbleMinMax(IN int HeadNo,OUT int *Min,OUT int *Max);
|
||||
// Get Measurement Mode
|
||||
EXP BOOL WINAPI LKIF_GetMeasureMode(IN int HeadNo,OUT LKIF_MEASUREMODE *MeasureMode);
|
||||
// Get Number of Times of Alarm Processing
|
||||
EXP BOOL WINAPI LKIF_GetNumAlarm(IN int HeadNo,OUT int *NumAlarm);
|
||||
// Get Alarm Level
|
||||
EXP BOOL WINAPI LKIF_GetAlarmLevel(IN int HeadNo,OUT int *AlarmLevel);
|
||||
// Get Mounting Mode
|
||||
EXP BOOL WINAPI LKIF_GetReflectionMode(IN int HeadNo,OUT LKIF_REFLECTIONMODE *ReflectionMode);
|
||||
// Get Calculation Method
|
||||
EXP BOOL WINAPI LKIF_GetCalcMethod(IN int OutNo,OUT LKIF_CALCMETHOD *CalcMethod,LKIF_CALCTARGET *CalcTarget);
|
||||
// Get Scaling
|
||||
EXP BOOL WINAPI LKIF_GetScaling(IN int OutNo,IN int HeadNo,OUT int *InputValue1,OUT int *OutputValue1,OUT int *InputValue2,OUT int *OutputValue2);
|
||||
// Get Filter Mode
|
||||
EXP BOOL WINAPI LKIF_GetFilterMode(IN int OutNo,OUT LKIF_FILTERMODE *FilterMode);
|
||||
// Get Number of Times for Averaging
|
||||
EXP BOOL WINAPI LKIF_GetAverage(IN int OutNo,OUT LKIF_AVERAGE *Average);
|
||||
// Get Cutoff Frequency
|
||||
EXP BOOL WINAPI LKIF_GetCutOffFrequency(IN int OutNo,OUT LKIF_CUTOFFFREQUENCY *CutOffFrequency);
|
||||
// Get Trigger Mode
|
||||
EXP BOOL WINAPI LKIF_GetTriggerMode(IN int OutNo,OUT LKIF_TRIGGERMODE *TriggerMode);
|
||||
// Get Offset
|
||||
EXP BOOL WINAPI LKIF_GetOffset(IN int OutNo,IN int *Offset);
|
||||
// Get Analog Output Scaling
|
||||
EXP BOOL WINAPI LKIF_GetAnalogScaling(IN int OutNo,OUT int *InputValue1,OUT int *OutputVoltage1,OUT int *InputValue2,OUT int *OutputVoltage2);
|
||||
// Get Calculation Mode
|
||||
EXP BOOL WINAPI LKIF_GetCalcMode(IN int OutNo,OUT LKIF_CALCMODE *CalcMode);
|
||||
// Get Minimum Display Unit
|
||||
EXP BOOL WINAPI LKIF_GetDisplayUnit(IN int OutNo,OUT LKIF_DISPLAYUNIT *DisplayUnit);
|
||||
// Analog-Through
|
||||
EXP BOOL WINAPI LKIF_GetAnalogThrough(IN int OutNo,OUT BOOL *IsOn);
|
||||
// Get Data Storage
|
||||
EXP BOOL WINAPI LKIF_GetDataStorage(IN LKIF_TARGETOUT *TargetOut,OUT int *NumStorage,OUT LKIF_STORAGECYCLE *StorageCycle);
|
||||
// Get Sampling Rate
|
||||
EXP BOOL WINAPI LKIF_GetSamplingCycle(OUT LKIF_SAMPLINGCYCLE *SamplingCycle);
|
||||
// Get Mutual Interference Prevention
|
||||
EXP BOOL WINAPI LKIF_GetMutualInterferencePrevention(OUT BOOL *IsOn);
|
||||
// Get Timing Synchronization
|
||||
EXP BOOL WINAPI LKIF_GetTimingSynchronization(OUT LKIF_SYNCHRONIZATION *Synchronization);
|
||||
// Get Comparator Output Format
|
||||
EXP BOOL WINAPI LKIF_GetToleranceComparatorOutputFormat(OUT LKIF_TOLERANCE_COMPARATOR_OUTPUT_FORMAT *ToleranceComparatorOutputFormat);
|
||||
// Get Strobe Time
|
||||
EXP BOOL WINAPI LKIF_GetStorobeTime(OUT LKIF_STOROBETIME *StorobeTime);
|
||||
///////////////////////////////////////////////
|
||||
// Mode Change Command
|
||||
//
|
||||
// Mode Switch
|
||||
typedef enum {
|
||||
LKIF_MODE_NORMAL, // normal mode
|
||||
LKIF_MODE_COMMUNICATION, // setting mode
|
||||
} LKIF_MODE;
|
||||
EXP BOOL WINAPI LKIF_SetMode(IN LKIF_MODE Mode);
|
||||
} // extern "C"
|
||||
|
||||
#endif // LKIF_INCLUDED
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently,
|
||||
// but are changed infrequently
|
||||
|
||||
#include "stdafx_net.h"
|
||||
|
||||
#define _ATL_APARTMENT_THREADED
|
||||
|
||||
#include <afxwin.h>
|
||||
#include <afxodlgs.h> // MFC OLE dialog classes
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
@@ -0,0 +1,135 @@
|
||||
BYTE* buf = new BYTE[ 128 * 3 * SizeValue ];
|
||||
|
||||
int c = 0;
|
||||
|
||||
for ( int i = 0; i < SizeValue; i++ )
|
||||
{
|
||||
for ( int j = 0; j < 128; j++ )
|
||||
{
|
||||
unsigned char val =
|
||||
pmatrix[ i ][ j ] == 0 ? 0xFF : 0x00;
|
||||
|
||||
buf[ c + 0 ] = (BYTE) val;
|
||||
buf[ c + 1 ] = (BYTE) val;
|
||||
buf[ c + 2 ] = (BYTE) val;
|
||||
|
||||
c += 3;
|
||||
}
|
||||
}
|
||||
|
||||
SaveBitmapToFile( (BYTE*) buf,
|
||||
128,
|
||||
SizeValue,
|
||||
24,
|
||||
"C:\\MyFolder\\image_created.bmp" );
|
||||
|
||||
delete [] buf;
|
||||
|
||||
Saving the byte data as a bitmap file
|
||||
|
||||
Writing the array data as a bitmap file is accomplished by the SaveBitmapToFile module. This module essentially:
|
||||
|
||||
i. initializes a BITMAPINFOHEADER data structure with bitmap parameters (header size, padding, height, width, etc)
|
||||
|
||||
ii. initializes a BITMAPFILEHEADER structure in the appropriate way
|
||||
|
||||
iii. Creates a file handler and writes the file, bitmap info and pixel data into it to create the new bitmap file representation:
|
||||
|
||||
//
|
||||
// Save the bitmap to a bmp file
|
||||
//
|
||||
void CSimulationrun::SaveBitmapToFile( BYTE* pBitmapBits,
|
||||
LONG lWidth,
|
||||
LONG lHeight,
|
||||
WORD wBitsPerPixel,
|
||||
LPCTSTR lpszFileName )
|
||||
{
|
||||
// Some basic bitmap parameters
|
||||
unsigned long headers_size = sizeof( BITMAPFILEHEADER ) +
|
||||
sizeof( BITMAPINFOHEADER );
|
||||
unsigned long padding_size = ( 4 - ( ( lWidth * 3 ) % 4 ) ) % 4;
|
||||
unsigned long pixel_data_size = lHeight * ( ( lWidth * 3 ) + padding_size );
|
||||
|
||||
BITMAPINFOHEADER bmpInfoHeader = {0};
|
||||
|
||||
// Set the size
|
||||
bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
|
||||
// Bit count
|
||||
bmpInfoHeader.biBitCount = wBitsPerPixel;
|
||||
|
||||
// Use all colors
|
||||
bmpInfoHeader.biClrImportant = 0;
|
||||
|
||||
// Use as many colors according to bits per pixel
|
||||
bmpInfoHeader.biClrUsed = 0;
|
||||
|
||||
// Store as un Compressed
|
||||
bmpInfoHeader.biCompression = BI_RGB;
|
||||
|
||||
// Set the height in pixels
|
||||
bmpInfoHeader.biHeight = lHeight;
|
||||
|
||||
// Width of the Image in pixels
|
||||
bmpInfoHeader.biWidth = lWidth;
|
||||
|
||||
// Default number of planes
|
||||
bmpInfoHeader.biPlanes = 1;
|
||||
|
||||
// Calculate the image size in bytes
|
||||
bmpInfoHeader.biSizeImage = pixel_data_size;
|
||||
|
||||
BITMAPFILEHEADER bfh = {0};
|
||||
|
||||
// This value should be values of BM letters i.e 0x4D42
|
||||
// 0x4D = M 0¡Á42 = B storing in reverse order to match with endian
|
||||
bfh.bfType=0x4D42;
|
||||
/* or bfh.bfType = ¡®B¡¯+(¡®M¡¯ << 8);
|
||||
// <<8 used to shift ¡®M¡¯ to end */
|
||||
|
||||
// Offset to the RGBQUAD
|
||||
bfh.bfOffBits = headers_size;
|
||||
|
||||
// Total size of image including size of headers
|
||||
bfh.bfSize = headers_size + pixel_data_size;
|
||||
|
||||
// Create the file in disk to write
|
||||
HANDLE hFile = CreateFile( lpszFileName,
|
||||
GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL );
|
||||
|
||||
// Return if error opening file
|
||||
if( !hFile ) return;
|
||||
|
||||
DWORD dwWritten = 0;
|
||||
|
||||
// Write the File header
|
||||
WriteFile( hFile,
|
||||
&bfh,
|
||||
sizeof(bfh),
|
||||
&dwWritten ,
|
||||
NULL );
|
||||
|
||||
// Write the bitmap info header
|
||||
WriteFile( hFile,
|
||||
&bmpInfoHeader,
|
||||
sizeof(bmpInfoHeader),
|
||||
&dwWritten,
|
||||
NULL );
|
||||
|
||||
// Write the RGB Data
|
||||
WriteFile( hFile,
|
||||
pBitmapBits,
|
||||
bmpInfoHeader.biSizeImage,
|
||||
&dwWritten,
|
||||
NULL );
|
||||
|
||||
// Close the file handle
|
||||
CloseHandle( hFile );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user