Theme
EcMccApi取説
ELMEC wanglinqaing 2022年4月21日
修正履歴
| No. | Version | Date | manager | Contents |
|---|---|---|---|---|
| 1 | 1.00 | 2022/04/21 | wang linqiang | 新規作成(複数のMCC 1608FS-Plus同時サンプリングを対応ため) |
| 2 | ||||
| 3 |
概要
EcMccApi LibararyはMCC(Measurement Computing Company)社開から発されたデバイスを対応ため、ELMEC社開発されたものです。
開発環境
- VS2019 C++言語
- MCC社のLibararyを使う
主なく機能
- MCC社向けのデバイスを対応です
- 1台PCに複数アプリ同時使うができます
- 1台PCに一つアプリで複数デバイス使うができます
- チャンネル数を増えるため、複数デバイス同期サンプリングができます(条件あり)
関数定義一覧
cpp
unsigned MccCreate(int id, void* userlog_folder);
unsigned MccDelete(int id);
unsigned MccOpen(int id, void* parameter);
unsigned MccClose(int id);
unsigned MccAInStart(int id);
unsigned MccAInStop(int id);
unsigned MccAInStatus(int id, int* count, int* status);
unsigned MccAInRead(int id, int* count, int offset);
unsigned MccDInBit(int id, int bit, unsigned short* in);
unsigned MccDOutBit(int id, int bit, unsigned short out);
unsigned MccDIn16(int id, unsigned short* in);
unsigned MccDOut16(int id, unsigned short out);
unsigned MccAOut(int id, int ch, int range, unsigned short out);関数使用フロー
基本フロー
flowchart LR
create=>start: MccCreate
delete=>end: MccDelete
open=>operation: MccOpen
close=>operation: MccClose
do=>subroutine: To Do
create(right)->open(right)->do(right)->close(right)->delete
To Do
アナログ入力
MccAInStart, MccAInStop, MccAInStatus, MccAInReadデジタル制御
MccDInBit, MccDOutBit, MccDIn16, MccDOut16アナログ出力
MccAOut
関数詳細
重要1
すべて関数の戻るはunsigned形式です、0は関数実行正常、ほかの値は下記の[Error Code](#Error Code)にご参考ください
重要2
すべて関数のint idパラメータは一つアプリ複数デバイス時使うです、設定値は0から3まで、普通は0に設定してください
MccCreate
関数
cppunsigned MccCreate(int id, void* userlog_folder);概要
Mcc Objectを新規、idの設定は0から3まで、MccOpen前、必ずMccCreateを実行してください。userlog_folder
ログ出力のフォルダーです、DLL内部がchar*で処理する、設定値0(NULL)ならアプリのフォルダーで使うです。
ログ出力名はUserLogEcMccApi_X.txt、Xはint idと一致。
MccDelete
関数
cppunsigned MccDelete(int id);概要
MCC Objectを削除。
MccOpen
関数
cppunsigned MccOpen(int id, void* parameter);概要
MCCデバイスを開く。parameter重要3
DLL内部処理はMCC_PAPA*です、詳しくは[パラメータ詳細](# 5. パラメータ詳細)にご覧ください。
MccClose
関数
cppunsigned MccClose(int id);概要
MCCデバイスを閉める
MccAInStart
関数
cppunsigned MccAInStart(int id);概要
A/Dサンプリングをスタートする
MccAInStop
関数
cppunsigned MccAInStop(int id);概要
A/Dサンプリングを停止する
MccAInStatus
関数
cppunsigned MccAInStatus(int id, int* count, int* status);概要
A/Dサンプリング状態を取るcount
上位機に返信、現在サンプリングされたデータ個数、返信値は一つチャンネル分のデータ数です。status
上位機に返信、現在A/Dの状態(0=停止、1=動作中)
MccAInRead
関数
cppunsigned MccAInRead(int id, int* count, int offset);概要
A/Dサンプリングデータは上位機のメモリに書くcount
上位機新規されメモリに保存データ数、設定値は一つチャンネル分のデータ数です。offset
上位機新規されメモリに保存データの場所(offset)、設定値は一つチャンネル分の位置です。連続読み込み時、0に設定ください。
注意
MccDInBit
関数
cppunsigned MccDInBit(int id, int bit, unsigned short* in);概要
指定デジタルビットを入力するbit
デジタル入力ビット番号(0から)in
指定されたデジタルビット状態は上位機に返信(0=OFF, 1=ON)
MccDOutBit
関数
cppunsigned MccDOutBit(int id, int bit, unsigned short out);概要
指定デジタルビットを出力するbit
デジタル出力ビット番号(0から)out
デジタル出力ビット値(0=OFF, 1=ON)
MccDIn16
関数
cppunsigned MccDIn16(int id, unsigned short* in);概要
最大16個デジタルビットを一括入力するin
返信値、最大16ビット対応(返信値の各bit 0=OFF, 1=ON)
MccDOut16
関数
cppunsigned MccDOut16(int id, unsigned short out);概要
最大16個デジタルビットを一括出力するout
出力値、最大16ビット対応(出力値の各bit 0=OFF, 1=ON)
MccAOut
関数
cppunsigned MccAOut(int id, int ch, int range, unsigned short out);概要
アナログデータを出力するch
D/Aチャネル番号。 最大許容チャネルは、使用されているD/Aボードのタイプによって異なります。range
D/A範囲コード。 D/Aチャネルの出力範囲は、ボードでサポートされている任意の範囲に設定できます。 D/Aボードにプログラム可能な範囲がない場合、この引数は無視されます。 設定値は下記の[Analog Output Range](#Analog Output Range)ご参考。out
D/A出力値。 0〜nの範囲内である必要があります。ここで、nはコンバータの値です。
パラメータ詳細
下記のパラメータ構造体はMccOpen関数で使う
cpp
typedef struct
{
int device_num;
char device_id[256];
int channel;
int sampling;
int range;
int clock;
int clock_output;
int input_mode;
int trigger_mode;
int trigger_digital_mode;
int trigger_analog_mode;
int slice_lo;
int slice_hi;
int digital_bit_num;
unsigned digital_bit_dir;
int ch_size;
int buffer_mode;
void* buffer;
int slave_mode;
int spare[256];
} MCC_PARA;デバイスの個数です、設定値は0から4
設定値0: デバイス個数 = 1
設定値1: デバイス個数 = 1
設定値2: デバイス個数 = 2
設定値3: デバイス個数 = 3
設定値4: デバイス個数 = 4
設定値0の場合、下記のchar device_id[256]は無効にする。
設定値0以外、下記のchar device_id[256]は有効にする。
※ PCで1台MCCデバイスしかないの場合、0に設定してください。
※ 多チャンネル数を対応ため、複数デバイス(同型番)は同期サンプリングの場合は、2以上に設定してください。複数デバイスを使う時、切り分けため、デバイスの識別番号かシリアル番号かここち設定してください。最大4台デバイス対応
device_id[0]から64byte:1番目デバイス(Master device)
device_id[64]から64byte:2番目デバイス(Slave device)
device_id[128]から64byte:3番目デバイス(Slave device)
device_id[192]から64byte:3番目デバイス(Slave device)A/Dのチャンネル数を指定、設定値は一枚A/Dのチャンネル数です
A/Dのサンプリング周波数を指定、設定値は一つチャンネルのサンプリング周波数です、全体サンプリング数は[channel * sampling]です。
A/Dの入力電圧範囲番号、詳しく[Analog Input Range](#Analog Input Range)に参考。
A/Dサンプリングタイマーを選択:0=内部クロック、1=外部クロック
A/Dの内部クロックが出力するかどうかを選択:0=機能なし、1=出力禁止、2=出力有効
A/Dのチャンネル入力モードを選択:0=単端、1=両端(差分)
※両端モードの最大チャンネル数は単端モードの半分になるトリガ(外部スタート)モードを選択:0=なし、1=デジタル、2=アナログ
trigger_modeは1設定時有効、デジタルトリガモードは下記の[Digital Trigger Mode](#Digital Trigger Mode)に参考。
trigger_modeは2設定時有効、アナログトリガモードは下記の[Analog Trigger Mode](#Analog Trigger Mode)に参考。
trigger_modeは2設定時有効、アナログトリガのロースライス値(A/D値)
trigger_modeは2設定時有効、アナログトリガのハイスライス値(A/D値)
デジタルビット個数、0設定の場合、デジタル機能は無効にする
デジタル各ビットのI/O状態設定、各ビット値の設定値0の時入力状態、1の時出力状態、例えば
digital_bit_num = 4
digital_bit_dir = 0x05 = 0101(binary)
の場合、bit0とbit2は出力状態、bit1とbit3は入力状態- 重要4
上位機から新規されたメモリサイズです、設定値に一つチャンネルのサイズです。
注意
将来対応、現在未使用
- 重要5
上位機から新規された全チャンネルのメモリポイント、現在内部処理はWORD*です。
将来対応、現在未使用
Example
cpp
enum DO_MODES
{
DO_ONE_ONE, // 1台サンプリング、PCに1台MCCデバイスしかない
DO_ONE_MULT, // 1台サンプリング、PCに複数台MCCデバイスがあり
DO_THREE, // 3台同期サンプリングとデジタルトリガ
};
DO_MODES do_mode = DO_THREE;
// -----------------------------------------------------------
// MCC object id
int id = 0;
// Parameter initialization
MCC_PARA Para;
memset(&Para, 0x00, sizeof(MCC_PARA));
switch (do_mode)
{
case DO_ONE_ONE:
Para.device_num = 0;
break;
case DO_ONE_MULT:
Para.device_num = 1;
strcpy(&Para.device_id[0], "F0AABB13");
break;
case DO_THREE:
Para.device_num = 3;
strcpy(&Para.device_id[0], "F0AABB13"); // Master
strcpy(&Para.device_id[64], "F0AABB14"); // Slave
strcpy(&Para.device_id[128], "F0AABB15"); // slave
Para.trigger_mode = 1; // Digital trigger mode
Para.trigger_digital_mode = _DT_EDGE_NEG; // Edge down mode
Para.clock_output = 2; // Clock output is enable
break;
}
int device_num = Para.device_num;
if (device_num == 0)
{
device_num = 1;
}
Para.channel = 8;
Para.sampling = 1000;
Para.ch_size = 4 * Para.sampling; // 4sec
WORD* pMem = new WORD[device_num * Para.channel* Para.ch_size];
Para.buffer = pMem;
// MCC object create
MccCreate(id, NULL);
// MCC device open
MccOpen(id, &Para);
int nLen, nStatus;
int nSaveSize = 3 * Para.sampling; // 3Sec
// A/D sampling start
MccAInStart(id);
for (;;)
{
Sleep(1);
// Get A/D sampling data size
MccAInStatus(id, &nLen, &nStatus);
if (nLen >= nSaveSize)
{
// Read A/D sampling data, Save to Para.buffer
MccAInRead(id, &nSaveSize, 0);
break;
}
}
// A/D sampling stop
MccAInStop(id);
// MCC device close
MccClose(id);
// MCC Object delete
MccDelete(id);
delete []pMem;参考
Error Code
| Code | Define | Comment |
|---|---|---|
| 0 | _ERR_NONE | No error has occurred |
| 2000 | _ERR_MCCOBJ_ID | MccObj id Error |
| 2001 | _ERR_NONE_MCCOBJ | MccObj is NULL |
| 2002 | _ERR_NONE_DEVICE | None device |
| 2003 | _ERR_DEVICE_NUM | device numbers error |
| 2004 | _ERR_PARA | parameter have error, pls check parameter setting |
| Others | 開発者にご連絡 |
Analog Input Range
| Code | Define | Range |
|---|---|---|
| 0 | _AI_VOLT5 | ±5V |
| 1 | _AI_VOLT10 | ±10V |
| 2 | _AI_VOLT2_5 | ±2.5V |
| 3 | _AI_VOLT1_25 | ±1.25V |
| 4 | _AI_VOLT1 | ±1V |
| 5 | _AI_VOLT0_625 | ±0.625V |
| 6 | _AI_VOLT0_5 | ±0.5V |
| 7 | _AI_VOLT0_1 | ±0.1V |
| 8 | _AI_VOLT0_05 | ±0.05V |
| 9 | _AI_V0LT0_01 | ±0.01V |
| 10 | _AI_VOLT0_005 | ±0.005V |
| 11 | _AI_VOLT1_67 | ±1.67V |
| 12 | _AI_VOLT0_25 | ±0.25V |
| 13 | _AI_VOLT0_2 | ±0.2V |
| 14 | _AI_VOLT2 | ±2.0V |
| 15 | _AI_VOLT20 | ±20V |
| 16 | _AI_VOLT4 | ±4V |
| 17 | _AI_VOLT0_312 | ±0.312V |
| 18 | _AI_VOLT0_156 | ±0.156V |
| 19 | _AI_VOLT0_078 | ±0.078V |
| 20 | _AI_VOLT60 | ±60V |
| 21 | _AI_VOLT15 | ±15V |
| 22 | _AI_VOLT0_125 | ±0.125V |
| 23 | _AI_VOLT30 | ±30V |
Analog Output Range
| Code | Define | Range |
|---|---|---|
| 0 | _AO_VOLT10 | 0 to 10 Volts |
| 1 | _AO_VOLT5 | 0 to 5 Volts |
| 2 | _AO_VOLT2_5 | 0 to 2.5 Volts |
| 3 | _AO_VOLT2 | 0 to 2 Volts |
| 4 | _AO_VOLT1_25 | 0 to 1.25 Volts |
| 5 | _AO_VOLT1 | 0 to 1 Volt |
| 6 | _AO_VOLT0_1 | 0 to .1 Volt |
| 7 | _AO_VOLT0_01 | 0 to .01 Volt |
| 8 | _AO_VOLT0_02 | 0 to .02 Volt |
| 9 | _AO_VOLT1_67 | 0 to 1.67 Volts |
| 10 | _AO_VOLT0_5 | 0 to .5 Volt |
| 11 | _AO_VOLT0_25 | 0 to 0.25 Volt |
| 12 | _AO_VOLT0_2 | 0 to .2 Volt |
| 13 | _AO_VOLT0_05 | 0 to .05 Volt |
| 14 | _AO_VOLT4 | 0 to 4 Volts |
Digital Trigger Mode
| Value | Define | Comment |
|---|---|---|
| 0 | _DT_GATE_HIGH | Scanning is enabled as long as the external digital trigger input is 5V (logic HIGH or '1'). |
| 1 | _DT_GATE_LOW | Scanning is enabled as long as the external digital trigger input is 0V (logic LOW or '0'). |
| 2 | _DT_TRIG_HIGH | Scanning begins when the external digital trigger is 5V (logic HIGH or '1'). Once conversions are enabled, the external trigger is ignored. |
| 3 | _DT_TRIG_LOW | Scanning begins when the external digital trigger is 0V (logic LOW or '0'). Once conversions are enabled, the external trigger is ignored. |
| 4 | _DT_EDGE_POS | Scanning begins when the external digital trigger transitions from 0V to 5V (logic LOW to HIGH). Once conversions are enabled, the external trigger is ignored. |
| 5 | _DT_EDGE_NEG | Scanning begins when the external digital trigger transitions from 5V to 0V (logic HIGH to LOW). Once conversions are enabled, the external trigger is ignored. |
Analog Trigger Mode
| Value | Define | Comment |
|---|---|---|
| 0 | _AT_GATE_NEG | Scanning is enabled as long as the external analog trigger input is more positive than HighThreshold. Hysteresis is the level between LowThreshold and HighThreshold. |
| 1 | _AT_GATE_POS | Scanning is enabled as long as the external analog trigger input is more negative than LowThreshold. Hysteresis is the level between LowThreshold and HighThreshold. |
| 2 | _AT_GATE_ABOVE | Scanning is enabled as long as the external analog trigger input is more positive than HighThreshold. |
| 3 | _AT_GATE_BELOW | Scanning is enabled as long as the external analog trigger input is more negative than LowThreshold. |
| 4 | _AT_TRIG_ABOVE | Scanning begins when the external analog trigger input transitions from below HighThreshold to above. Once conversions are enabled, the external trigger is ignored. |
| 5 | _AT_TRIG_BELOW | Scanning begins when the external analog trigger input transitions from above LowThreshold to below. Once conversions are enabled, the external trigger is ignored. |
| 6 | _AT_TRIG_RISING | Scanning begins when the external analog trigger input transitions from below LowThreshold to above HighThreshold. Once conversions are enabled, the external trigger is ignored. |
| 7 | _AT_TRIG_FALLING | Scanning begins when the external analog trigger input transitions from above HighThreshold to below LowThreshold. Once conversions are enabled, the external trigger is ignored. |