C++/CLI¶
開発環境の設定¶
-
YdxCLI.h をプロジェクトフォルダにコピーします。
-
YdxCLI.h をプロジェクトに追加します。
-
ソースファイルに YdxCLI.h をインクルードします。
-
usingディレクティブを使ってYdxCLIを宣言します。
コントロール¶
変数¶
int id;
実行結果の表示¶
private: System::Void ResultShow(String^ title, int resultCode)
{
StringBuilder ^resultString = gcnew StringBuilder(256);
YdxCnvResultToString(resultCode, resultString);
switch (resultCode)
{
case 0:
case YDX_RESULT_DI_EXCEED_DATA_NUM:
case YDX_RESULT_DI_EXCEED_BUF_SIZ:
MessageBox::Show(resultString->ToString(), title, MessageBoxButtons::OK, MessageBoxIcon::Asterisk);
break;
default:
MessageBox::Show(resultString->ToString(), title, MessageBoxButtons::OK, MessageBoxIcon::Hand);
break;
}
}
フォームロード¶
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
// ユニット識別スイッチ
unitSwitchComboBox->ResetText();
unitSwitchComboBox->Items->AddRange(gcnew array<String^> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" });
unitSwitchComboBox->SelectedIndex = 0;
// 型名
modelNameComboBox->ResetText();
modelNameComboBox->Items->AddRange(gcnew array<String^> { "DIO-16/16C-USC", "DIO-16/16D-UBC", "DIO-16/16D-USC" });
modelNameComboBox->SelectedIndex = 0;
// 入力チャネル
inputChannelComboBox->ResetText();
inputChannelComboBox->Items->AddRange(gcnew array<String ^>{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"});
inputChannelComboBox->SelectedIndex = 0;
// 出力チャネル
outputChannelComboBox->ResetText();
outputChannelComboBox->Items->AddRange(gcnew array<String ^>{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"});
outputChannelComboBox->SelectedIndex = 0;
// 出力データ
outputDataComboBox->ResetText();
outputDataComboBox->Items->AddRange(gcnew array<String ^>{"0", "1"});
outputDataComboBox->SelectedIndex = 0;
}
オープン¶
private: System::Void openButton_Click(System::Object^ sender, System::EventArgs^ e)
{
int getId;
int result = YdxOpen(unitSwitchComboBox->SelectedIndex, modelNameComboBox->Text, 0, &getId);
if(result != 0)
ResultShow("YdxOpen", result);
else
{
unitSwitchComboBox->Enabled = false;
modelNameComboBox->Enabled = false;
ResultShow("オープン", result);
id = getId;
}
}
デジタル入力¶
private: System::Void inputButton_Click(System::Object^ sender, System::EventArgs^ e)
{
int data[1];
int result = YdxDiInputBit(id, inputChannelComboBox->SelectedIndex, 1, 0, data);
if(result != 0)
ResultShow("YdxDiInputBit", result);
else
MessageBox::Show("データ : " + data[0].ToString(), "入力", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
デジタル出力¶
private: System::Void outputButton_Click(System::Object^ sender, System::EventArgs^ e)
{
int data[1];
data[0] = outputDataComboBox->SelectedIndex;
int result = YdxDoOutputBit(id, outputChannelComboBox->SelectedIndex, 1, data);
ResultShow("出力", result);
}
クローズ¶
private: System::Void closeButton_Click(System::Object^ sender, System::EventArgs^ e)
{
unitSwitchComboBox->Enabled = true;
modelNameComboBox->Enabled = true;
int result = YdxClose(id);
if(result != 0)
ResultShow("YdxClose", result);
else
ResultShow("クローズ", result);
}
フォームクローズ¶
private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e)
{
int result = YdxClose(id);
if((result != 0) && (result != YDX_RESULT_NOT_OPEN))
{
ResultShow("YdxClose", result);
}
}