📄 dataaccess.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "DataAccess.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Timer1Timer(TObject *Sender)
{
long nResult;
long Counter;
// float AValue;
tagSIOMM_AnaInMod012 AnaInMod012Data;
long DigInMod_4_States;
char phBankDstates[32];
int Mstr_len;
AnsiString Mstring,InsertString ;
long ScratchBitHi,ScratchBitLow;
tagSIOMM_ScratchPadIntegerBlock ScratchIntBlock;
// Get the AnalogIn_Module 0,1,2 data
nResult = Form1->GetAna_inModule012Value(&AnaInMod012Data );
//显示0,1,2 MODULE 的模拟输入值
//AValue = AnaInMod012Data.fValue[0];
AnaModule0_1->Text = FormatFloat("0.00",AnaInMod012Data.fValue[0]); //四舍五入到小数点后两位
AnaModule0_2->Text = FormatFloat("0.00",AnaInMod012Data.fValue[1]);
AnaModule0_3->Text = FormatFloat("0.00",AnaInMod012Data.fValue[2]);
AnaModule0_4->Text = FormatFloat("0.00",AnaInMod012Data.fValue[3]);
// Get the 4-channel DigitalIn_Module 4 's data
nResult = Form1->GetDig_inModule_N_States(4,0,&DigInMod_4_States);
//显示 MODULE 4 的数字输入
itoa(DigInMod_4_States,phBankDstates,2);//将数据转为32BIT的二进制字符串
Mstring = phBankDstates;
Mstr_len = Mstring.Length();
InsertString = AnsiString::StringOfChar('0',32-Mstr_len);
Mstring.Insert(InsertString,1);
Mstring = Mstring.SubString(13,4);
DigModule4->Text = Mstring;
//Get the variants in the Scratch pad area
// Get all the bit variants ,that is 64 bits.
nResult = Form1->OptoSnapIoMemMapX1->GetScratchPadBitArea(&ScratchBitHi,&ScratchBitLow);//this is all of the bit variants in the ScratchPad.
ScratchbitRead->Text = "0x"+IntToHex((int)ScratchBitHi,8)+IntToHex((int)ScratchBitLow,8); //Display
// Get the 5th int variants in the 0 block.There are 10240 int variants in all,which means 40 blocks.
nResult = Form1->OptoSnapIoMemMapX1->GetScratchPadIntegerArea(0,&ScratchIntBlock);// get a integer 256 matrix once
ScratchRead_intN->Text = IntToStr(ScratchIntBlock.nValue[4]);
if (SIOMM_OK != nResult)
{
Form1->HandleError(nResult);
Form1->Show();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::AnaModule6_1_setClick(TObject *Sender)
{
long nResult;
tagSIOMM_AnaOutSingleMod AnaOutModSiData;
//Set the AnalogOut_Module 6 data
if(AnaModule6_1->Text == "")
{
Application->MessageBoxA("输出量不能为空!","Warning !",MB_OK);
return;
}
else
nResult = Form1->OptoSnapIoMemMapX1->SetAnaPtValue(6*4,StrToFloat(AnaModule6_1->Text));
if (SIOMM_OK != nResult)
{
Form1->HandleError(nResult);
Form1->Show();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::AnaModule6_2_setClick(TObject *Sender)
{
long nResult;
//Set the AnalogOut_Module 6 data
//AnaOutModSiData.fValue[0] = StrToFloat(AnaModule6_1->Text);
// AnaOutModSiData.fValue[1] = StrToFloat(AnaModule6_2->Text);
// nResult = Form1->SetAna_OutModule_N_Value(6,&AnaOutModSiData);
if(AnaModule6_2->Text == "")
{
Application->MessageBoxA("输出量不能为空!","Warning !",MB_OK);
return;
}
else
nResult = Form1->OptoSnapIoMemMapX1->SetAnaPtValue(6*4+1,StrToFloat(AnaModule6_2->Text)); //6*4+1指第五位
if (SIOMM_OK != nResult)
{
Form1->HandleError(nResult);
Form1->Show();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
long nResult;
nResult = Form1->OptoSnapIoMemMapX1->Close();
if (SIOMM_OK == nResult)
{
Form1->Error_Message->Text = "Disconnection ok !";
Form1->Error_Message->Color = clWhite ;
Form1->DataProcess->Enabled = false;
}
else Form1->HandleError(nResult);
Form1->Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
long nResult;
nResult = Form1->OptoSnapIoMemMapX1->Close();
if (SIOMM_OK == nResult)
{
Form1->Error_Message->Text = "Disconnection ok !";
Form1->Error_Message->Color = clWhite ;
Form1->DataProcess->Enabled = false;
}
else Form1->HandleError(nResult);
Form1->Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ScratchWrite_bitN_setClick(TObject *Sender)
{
long nResult;
nResult = Form1->OptoSnapIoMemMapX1->SetScratchPadBitAreaMask(0x00000000,0x00000020,0x00000000,0x00000000);
//将64个通道中第6位置为高,即模块1的2
if (SIOMM_OK != nResult)
{
Form1->HandleError(nResult);
Form1->Show();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ScratchWrite_bitN_clearClick(TObject *Sender)
{
long nResult;
nResult = Form1->OptoSnapIoMemMapX1->SetScratchPadBitAreaMask(0x00000000,0x00000000,0x00000000,0x00000020);
if (SIOMM_OK != nResult)
{
Form1->HandleError(nResult);
Form1->Show();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ScratchbitRead_setClick(TObject *Sender)
{
long nResult,tlength;
long Bits63to32, Bits31to0;
AnsiString InsertString;
tlength = ScratchbitWrite->Text.Length();
if(tlength<16)
{
InsertString = AnsiString::StringOfChar('0',16-tlength);
ScratchbitWrite->Text = ScratchbitWrite->Text.Insert(InsertString,1);
}
Bits63to32 = StrToInt("0x"+ScratchbitWrite->Text.SubString(1,8));
Bits31to0 = StrToInt("0x"+ScratchbitWrite->Text.SubString(9,16)); //获取64位的位变量值
nResult = Form1->OptoSnapIoMemMapX1->SetScratchPadBitArea(Bits63to32,Bits31to0);
if (SIOMM_OK != nResult)
{
Form1->HandleError(nResult);
Form1->Show();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ScratchWrite_IntN_setClick(TObject *Sender)
{
long nResult;
tagSIOMM_ScratchPadIntegerBlock ScratchIntWBlock;
// 保护措施
ScratchIntWBlock.nValue[0]=0;
ScratchIntWBlock.nValue[1]=0;
ScratchIntWBlock.nValue[2]=0;
ScratchIntWBlock.nValue[3]=0;
//
ScratchIntWBlock.nValue[4]= StrToInt(ScratchWrite_IntN->Text);
nResult = Form1->OptoSnapIoMemMapX1->SetScratchPadIntegerArea(0,5,&ScratchIntWBlock);
if (SIOMM_OK != nResult)
{
Form1->HandleError(nResult);
Form1->Show();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ScratchWrite_CNStr_setClick(TObject *Sender)
{ /*
//将得到的三个字符串顺序存入Scratch pad String area,最多可以存放64个字符串
long nResult;
tagSIOMM_ScratchPadStringBlock ScratchStrBlock;
if(Str1->Text=="")
{
Application->MessageBoxA("字符串不能为空!","Warning !",MB_OK);
return;
}
ScratchStrBlock.String[1].bstrString = WideString(Str2->Text);
ScratchStrBlock.String[0].bstrString = WideString(Str1->Text);
// ScratchStrBlock.String[2].bstrString = WideString(Str3->Text);
nResult = Form1->OptoSnapIoMemMapX1->SetScratchPadStringArea(0,2,&ScratchStrBlock);//此处为从第0个位置开始连续存放3个
if (SIOMM_OK != nResult)
{
Form1->HandleError(nResult);
Form1->Show();
} */
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -