OPC server is always NULL - server

when I use CoCreateInstanceEx I always get NULL as a result.
My code is like that:
bool Connect(Str a_sServerName, COSERVERINFO* CoServerInfo)
{
CLSID CLSID_OPCServer;
HRESULT hr;
hr = CLSIDFromString(a_sServerName, &CLSID_OPCServer);
if( hr == S_FALSE )
{
// Log string "Wrong CLSID of OPC server"
return false;
}
LONG cmq = 1; // nbr of class instance to create.
MULTI_QI queue[] = { { &IID_IOPCServer, nullptr, 0 } };
// HERE IS SOMETHING WRONG WITH THE queue VARIABLE
hr = CoCreateInstanceEx(CLSID_OPCServer, NULL, CLSCTX_ALL, CoServerInfo, cmq, queue);
if( hr == S_FALSE )
{
// Log string "Error creating OPC server instance"
return false;
}
else
{
// Log string "Successful connection to the OPC server"
}
pIOPCServer = (IOPCServer*) queue[0].pItf;
//AND HERE pIOPCServer IS NULL
}
I get no errors, everything seem to work properly. But unfortunately the pIOPCServer is NULL.
Don't you suspect what could be wrong here?
For any help great thanks in advance.
Best Regards,

You need to check not just the HRESULT from CoCreateInstanceEx, but also the HRESULT in queue[0].hr. The reason of the problem will most likely be there.

Related

How do I resolve code.org's App Lab readRecord() asynchronous timing?

I'm a fairly new student in AP CSP, and I wanted to create a username/password system in code.org's App Lab, however, it requires me to get the readRecords() command to function first.
I have the code as such :
function read (array) {
var truth;
readRecords("loginarray", {}, function(records) {
if (records.length > 0) {
for (var i = 0; i < records.length; i++){
if (array.user == records[i].user){
if (array.pass == records[i].pass) {
truth = false;
hideElement("unverifiedtext");
hideElement("retrybutton");
setScreen("verifyscreen");
}
}
}
}
}
);
return truth;
}
But nothing I do seems to get the readRecords() command working. I'm rather confused, can this asynchronous timing be meddled with at all? If not, how should I go about fixing this issue?
Thanks in advance!

Aldec Riviera-PRO break simulation on SystemVerilog $error or $warning

Is is possible to configure Aldec Riviera-PRO simulator to break simulation on either $error or $warning SystemVerilog calls? If it is then how?
I don't think there's a specific config option for promoting $error or $warning to a breakpoint in Riviera-PRO, although it worth checking with their support. You do have a couple of options:
Replace $error with $fatal
Write a VPI module to overload the system tasks with custom C code
The second option would look something like this:
#include "vpi_user.h"
// System function overload on $warning and $error to stop sim
static int system_function_overload(char *userdata)
{
vpiHandle systfref, args_iter, argh;
struct t_vpi_value argval;
const char *msg = "*** NO MESSAGE PROVIDED ***";
// Obtain a handle to the argument list
systfref = vpi_handle(vpiSysTfCall, NULL);
args_iter = vpi_iterate(vpiArgument, systfref);
// Pull out the string passed in as the first argument
if (args_iter) {
argh = vpi_scan(args_iter);
argval.format = vpiStringVal;
vpi_get_value(argh, &argval);
vpi_free_object(args_iter);
msg = argval.value.str;
}
vpi_printf("BREAK sim from %s:%d with msg %s\n",
vpi_get_str(vpiFile, systfref),
vpi_get(vpiLineNo, systfref),
msg);
vpi_control(vpiStop);
return 0;
}
static void register_system_functions(void)
{
s_vpi_systf_data tfData = { vpiSysTask, vpiSysTask };
tfData.sizetf = NULL;
tfData.compiletf = system_function_compiletf;
tfData.calltf = system_function_overload;
tfData.user_data = NULL;
tfData.tfname = "$warning";
vpi_register_systf( &tfData );
tfData.tfname = "$error";
vpi_register_systf( &tfData );
}
void (*vlog_startup_routines[])(void) = {
register_system_functions,
0
};

PostgreSQL clarification

I have written a function inside PostgreSQL which has the following code:
for (i = 0; i < 4; i++)
{
Datum dat_value = CStringGetDatum(inp->str[0][i]);
values[i] = datumCopy(dat_value,
stats->attrtype->typbyval,
stats->attrtype->typlen);
}
The input strings are {ALGERIA,ARGENTINA,BRAZIL,CANADA}. The code runs for ALGERIA,ARGENTINA but terminates abruptly for BRAZIL. When I investigated I found that inside datumCopy function, the statement after memcpy is not getting printed. I checked if palloc failed with (s == NULL) condition, but that seems to be not the reason. I think memcpy is failing. Any reason why? Thanks!
Datum
datumCopy(Datum value, bool typByVal, int typLen)
{
Datum res;
if (typByVal)
res = value;
else
{
Size realSize;
char *s;
if (DatumGetPointer(value) == NULL)
return PointerGetDatum(NULL);
realSize = datumGetSize(value, typByVal, typLen);
s = (char *) palloc(realSize);
printf ("Value : %s\n",DatumGetPointer(value));
memcpy(s, DatumGetPointer(value), realSize);
printf ("Not printing \n");
res = PointerGetDatum(s);
}
return res;
}
EDITED : Ok this is really wierd. When the input is one of {BRAZIL,PAKISTAN,FRANCE}, the code terminates abruptly. If I have other countries (I haven't tried extensively, but some countries), the code runs correctly.
EDITED 2 : Found the cause and rectified the issue. If we are passing C strings to datumCopy, we have to pass -2 for typLen parameter. I had been passing it incorrectly.
Thanks!
I have found the cause and rectified the issue.
If we are passing C strings to datumCopy, we have to pass -2 for typLen parameter. I had been passing it incorrectly.

Window services cant run exe on trigger time

I make one window service in c#
to run exe on particular time., but it could open that exe,
Below is code
private static string checkdatentime()
{
currentdate = DateTime.Now;
string value = "1";
for (int i = 0; i < xml_date.Count; i++)
{
value = "2";
if (currentdate.Date < xml_date[i].Date)
{
value = "3";
break;
// go out side for loop;
}
else if (currentdate.Date > xml_date[i].Date)
{
value = "4";
//Do nothing means loops continues
}
else
{
value = "5";
//if both date are same
if (currentdate.Date == xml_date[i].Date)
{
value = "99";
currentTime = currentdate.ToString("hh:mm");
TriggerTime = newItem.TriggerTime.ToString("hh:mm");
if (currentTime == TriggerTime)
{
value = "6";
//Run EXE
System.Diagnostics.Process.Start("E:\\SqlBackup_Programs\\console-backup\\Backup_Console_App 22July Latest\\Backup_Console_App\\Backup_Console_App\\bin\\Debug\\Backup_Console_App");
return value;
}
}
}
}
return value;
}
NOTE: here I return value because to verify is my code runs correct or not and write VALUE on text file, so on same time I am getting VALUE=6, means there is no problem in code,
But still service cant open this exe,
by same code i made console application and its runs perfectly, so why not services??
Is this any problem with command,
System.Diagnostics.Process.Start();
kindly help me!!
I got the answer, I had checked the option "Allow to interact with the Desktop" in the Windows service properties
And now its Working

How can I get an alert if a specific url substring is present and nothing if null

function getCode() {
if (window.location.href.indexOf("?discount=")) {
var url = (document.URL);
var id = url.substring(url.lastIndexOf('=') + 1);
window.alert(id);
return true;
} else {
return false;
}
}
Purpose: When people go to our "Service Request" page using a QR code that has a substring of ?discount=1234. I have been testing by creating an alert box with the discount code showing. Eventually I want to be able to populate that "1234" automatically into a "Discount Code:" text field on page load.
The above is a mixture of a few suggestions when I researched it.
Result: Going to example.com/serviceRequest.html?discount=1234 gives me the appropriate alert "1234", as I want... Going to example.com/serviceRequest.html gives me the alert http://example.com/serviceRequest.html, but I don't want anything to happen if "?discount=" is null.
Any suggestions?
indexOf returns -1 if the search pattern doesn't exist. In JavaScript, anything not a 0 or false or undefined is considered true.
So your line of:
if(window.location.href.indexOf("?discount=")) {
Would better search as:
if(window.location.href.indexOf("?discount=") > -1) {
Try changing your if-statement to:
if(window.location.href.indexOf("?discount=") != -1)
Look up the documentation for ".indexOf". It returns -1 for not found and >= 0 if it is found.
...indexOf("?discount=") >= 0
substring and indexOf return -1 if the text is not found, so you can test for this. E.g.
function getCode() {
if(window.location.href.indexOf("?discount=") != -1) {
var url = (document.URL);
var id = url.substring(url.lastIndexOf('=') + 1);
window.alert(id);
return true;
}
else {
return false;
}
}
You just need to test the indexOf value:
function getCode() {
if (window.location.href.indexOf("?discount=") !== -1) {
var url = (document.URL);
var id = url.substring(url.lastIndexOf('=') + 1);
window.alert(id);
return true;
}
else {
return false;
}
}
So the quick and dirty answer would be
var discount = window.location.search.split("?discount=")[1];
alert(discount);
But this doesn't take into account the occurence of other query string parameters.
You'll really want to parse all the query parameters into a hash map.
This article does a good job of showing you a native and jQuery version.
http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html