QAxBase.Object -> dynamicCall() Data type
-
Hi guys. I need your help.
I'm trying to get some data from mx component(mitsubishi) using ActiveQtI succeed in writing a data to output s/w, but getting data is too difficult.
The data reading method format is
ReadDeviceBlock(String *szDevice, int iSize, int *iplData)I wanna how call this function correctly.
Please tell me your idea.Under is my test source
void MainWindow::on_pushButton_clicked() {
ActLlt = new QAxObject; bool bStatus = false; bool bTemp = false; int nStatus = 0; int nTemp = 0; short hTemp = 0; long lTemp = 0; QString sTemp(""); QStringList qsl_Temp; QVariant qv_Temp; QVariant qv_bTemp; QVariant qv_nTemp; QVariant qv_sTemp; QVariantList qvl_Temp; bStatus = ActLlt->setControl("{235CFC02-AE9E-11D3-83AE-00A024BDBF2B}"); /* Property */ //CpuType nTemp = ActLlt->property("ActCpuType").toInt(); bTemp = ActLlt->setProperty("ActCpuType", CPU_Q26UDEHCPU); //Cpu type change //NetworkNumber nTemp = ActLlt->property("ActNetworkNumber").toInt(); //StationNumber nTemp = ActLlt->property("ActStationNumber").toInt(); //TimeOut nTemp = ActLlt->property("ActTimeOut").toInt(); QMap<QString, QVariant> qm_Temp; qm_Temp = ActLlt->propertyBag(); QStringList qsl_PropertyKeys; QVariantList qsl_PropertyValue; qsl_PropertyKeys = qm_Temp.keys(); qsl_PropertyValue = qm_Temp.values(); /*----OK----*/ nStatus = ActLlt->dynamicCall("Open()").toInt(); //Here is my problem "ReadDeviceBlock" //try 1 qv_Temp = ActLlt->dynamicCall("ReadDeviceBlock(QString,int,int&)", "D0", 1, qv_nTemp); //try 2 int nReadData[10] = {0}; void *ptrReadData = nReadData; qv_Temp.setValue(ptrReadData); qv_Temp = ActLlt->dynamicCall("ReadDeviceBlock(QString,int,int&)", "D0", 1, qv_nTemp); // I tried it with QVariantList, QVariant->fromValue() , etc. // Help me T.T /* -------------------------------------------------------- */ /* WriteDeviceBlock */ nTemp = 123; qv_nTemp.setValue(nTemp); qv_Temp = ActLlt->dynamicCall("WriteDeviceBlock(QString,int,int&)", "D0", 1, qv_nTemp); /* -------OK------- */ /* End */ nStatus = ActLlt->dynamicCall("Close()").toInt(); delete ActLlt;
}
-
Hi, it seems Mitsubushi made this more difficult by not using a SAFEARRAY for returning values, instead they are using an int array, which dynamicCall() doesn't like :-(
But I think you can get one integer at the time like this, using the same pattern as for WriteDeviceBlock:
//try 2 int nReadData = 0; qv_nTemp.setValue(nReadData); qv_temp = ActLlt->dynamicCall("ReadDeviceBlock(QString,int,int&)", "D0", 1, qv_nTemp); // check if qv_ntemp got something... qDebug() << qv_nTemp;
-
Thanks gooooooood man
I've just got a way to get one data like this
QVariantList qvl_Temp; QString sRDB = "ReadDeviceBlock(QString,int,int&)"; qvl_Temp << "D0" << 1 << 0; qv_Temp = ActLlt->dynamicCall(sRDB.toLatin1(), qvl_Temp);
// qvl_Temp has "D0", (int) 3, !!!! Data !!!!!
// It stored the one data into qvl_Temp.at(2)but I need getting more seems
qvl_Temp << "D0" << 3 << 0 << 0 << 0; qv_Temp = ActLlt->dynamicCall(sRDB.toLatin1(), qvl_Temp);
I expected it works to get 3 datas of [D0,D1,D2] but it doesn't T_T
so, I tried this
QVariantList qvl_Temp; QVariantList qvl_Data; QString sRDB = "ReadDeviceBlock(QString,int,int&)"; qvl_Data << 0 << 0 << 0; qvl_Temp << "D0" << 3 << qvl_Data; qv_Temp = ActLlt->dynamicCall(sRDB.toLatin1(), qvl_Temp);
but.......it could get just one data.
I'm still finding ^^;;;;
Thanks for your idea.
-
I think as long as you have
"ReadDeviceBlock(QString,int,int&)"
then one data value is all you are getting (because Mitsubishi didn't read the COM manual properly) but you could try cheating:QString sRDB = "ReadDeviceBlock(QString,int,QList<QVariant>&)"; qvl_Data << 0 << 0 << 0; qvl_Temp << "D0" << 3 << qvl_Data; qv_Temp = ActLlt->dynamicCall(sRDB.toLatin1(), qvl_Temp);
-
I found an easy way to use ActiveX in qt if you had *.tlb
I did dumpcpp.exe with *.tlb file.
It makes filenametlb.h and filenametlb.cpp files.
It has a namespace and there are some classes wanna use.Look follow article. He is a genius
http://www.codeproject.com/Tips/751240/Using-COM-Binary-Interface-with-CplusplusHave good a day.