From: Jim on
Subject line is the error.

Here's the breakdown:

- I am using MATLAB to connect to CQG to retrieve trading data for stock and futures prices. CQG is a charting tool, and they provide a sample program that I can use from within MATLAB to connect and retrieve data. I've tested my simple GUI application and it works.

- Then, I tried to build the application from MATLAB and export it as a separate exe and it doesn't work. The error is the subject line.

Here's the code in question which produces the error:
T = timer('TimerFcn',@InstrumentSubscriptionCheckConnection, 'ExecutionMode', 'fixedSpacing', 'Period', 2.0);

InstrumentSubscriptionCheckConnection is a function which does seem to get called and invoked and produces:
Error writing to output stream.

This is then followed by the "Error while evaluating TimerFCN" exception.

I tried to add a disp(exception.message) and disp(exception.stack) to the code to give me something more to go upon, but to no avail.

Any thoughts or ideas? I saw mention of a (somewhat) similar question with a reply from someone else telling them to enclose the name of the callback function in curly braces to create a cell array. This didn't seem to work for me at all; I could no longer get anything like that to work even within MATLAB (i.e. which is less than I have now). That other person was using quotations to name their function, so I imagine that was of some import to that solution/workaround.


What's strange to me is that this works inside of MATLAB, but not as a standalone exe. So, it MUST be related to that somehow, but at the moment the reason alludes me.


Thanks a lot!
Jim
From: Walter Roberson on
Jim wrote:
> Subject line is the error.
>
> Here's the breakdown:
>
> - I am using MATLAB to connect to CQG to retrieve trading data for stock
> and futures prices. CQG is a charting tool, and they provide a sample
> program that I can use from within MATLAB to connect and retrieve data.
> I've tested my simple GUI application and it works.
>
> - Then, I tried to build the application from MATLAB and export it as a
> separate exe and it doesn't work. The error is the subject line.
>
> Here's the code in question which produces the error:
> T = timer('TimerFcn',@InstrumentSubscriptionCheckConnection,
> 'ExecutionMode', 'fixedSpacing', 'Period', 2.0);
>
> InstrumentSubscriptionCheckConnection is a function which does seem to
> get called and invoked and produces:
> Error writing to output stream.
>
> This is then followed by the "Error while evaluating TimerFCN" exception.

The "Error writing to output stream" is the real error you have to solve. That
is happening within InstrumentSubscriptionCheckConnection and _that_ is the
error that occurred while evaluating the TimerFCN for timer-1 .

Wrap the functionality of your InstrumentSubscriptionCheckConnection within
try/catch and examine lasterror in the catch.
From: Jim on
Walter Roberson <roberson(a)hushmail.com> wrote in message
> Wrap the functionality of your InstrumentSubscriptionCheckConnection within
> try/catch and examine lasterror in the catch.
I have a try/catch block around this and have the following, none of which seem to produce any meaningful error messages to assist in the debug process...

disp (exception.message)
disp (exception.stack)
disp (lasterror.message)
disp (lasterror.stack)

(I come from the Java world, so I'm using "catch exception" since an anonymous or unnamed catch weirds me out a little; but I can change that if needed.)

I am using the diary function to place all of the output in a file, which allows me to keep it in between runs and clear it out as needed.


Thanks again!
Jim
From: Walter Roberson on
Jim wrote:
> Walter Roberson <roberson(a)hushmail.com> wrote in message
>> Wrap the functionality of your InstrumentSubscriptionCheckConnection
>> within try/catch and examine lasterror in the catch.
> I have a try/catch block around this and have the following, none of
> which seem to produce any meaningful error messages to assist in the
> debug process...
>
> disp (exception.message)
> disp (exception.stack)
> disp (lasterror.message)
> disp (lasterror.stack)
>
> (I come from the Java world, so I'm using "catch exception" since an
> anonymous or unnamed catch weirds me out a little; but I can change that
> if needed.)

What you write hints that the catch is being invoked -- otherwise you would
have said that no error messages were being output, not that it didn't produce
any "meaningful" error messages ?

What error messages _are_ being caught? Perhaps they will happen to be
recognized by someone else.
From: Jim on
Walter Roberson <roberson(a)hushmail.com> wrote in message
>
> What you write hints that the catch is being invoked -- otherwise you would
> have said that no error messages were being output, not that it didn't produce
> any "meaningful" error messages ?
>
> What error messages _are_ being caught? Perhaps they will happen to be
> recognized by someone else.
I agree that there should be more, but as I stare at it, it just isn't there. You'll see below when you look at the code that I have even tried to use both a catch exception AND lasterror format to try and give myself something more to go upon, but to no avail.

Very puzzling.

----------------------------------------------
Here's the total output:

Starting the timer
InstrumentSunscriptionCheckConnection
CQGAPI Started
Data Connection Status Changed to Up
InstrumentSubscriptionCheckConnection
Stopping the timerError writing to output stream.

***** InstrumentSubscriptionCheckConnection ERROR *****
Error writing to output stream.

???? Error while evaluating TimerFcn for timer 'timer-1'

Error writing to output stream.


Data Connection Status changed to Down


----------------------------------------------
Here is the code:
function InstrumentSubscription()

global T;

try
CQGAPI_StartUp();
T = timer('TimerFcn',@InstrumentSubscriptionCheckConnection, 'ExecutionMode', 'fixedSpacing', 'Period', 2.0);
disp 'Starting the timer'
start(T);
catch exception
disp '******** InstrumentSubscription ERROR *********'
disp (exception.message);
disp '***********************************************'
end
end

function InstrumentSubscriptionCheckConnection(obj, event, string_arg)

global m_CQGAPI;
global T;

disp 'InstrumentSubscriptionCheckConnection';

try
if m_CQGAPI.IsStarted
if (m_CQGAPI.Environment.DataConnectionStatus == 'csConnectionUp')
disp 'Stopping the timer'
stop(T);
DoInstrumentSubscription();
else
disp 'Waiting for Data Connection.'
end
end
catch exception
stop(T);
disp '***** InstrumentSubscriptionCheckConnection ERROR *****'
disp (exception.message)
disp (exception.stack)
disp (lasterror.message)
disp (lasterror.stack)
disp '***********************************************'
end

end

function DoInstrumentSubscription()

global m_CQGAPI;

try
LineTime = m_CQGAPI.Environment.LineTime;
disp(['Running DoInstrumentSubscription - LineTime : ' LineTime]);
disp('------------------------------------------------------------');

% The following subscribes to the most active contract
% for each commodity.
% You make subscribe to an explicit contract by specifying
% appending the month and year to the symbol.
% Stock symbols should be preceded by 'S.' and in the case of stock
% symbols that may be ambiguous, by 'S.cc.' where cc is the country
% code.

disp('F.JY6');
m_CQGAPI.NewInstrument('F.JY6')
disp('F.EDAA');
m_CQGAPI.NewInstrument('F.EDAA')
disp('F.EP');
m_CQGAPI.NewInstrument('F.EP')
% disp('S.JP.J3843');
% m_CQGAPI.NewInstrument('S.J3843')
disp('S.SPY');
m_CQGAPI.NewInstrument('S.SPY')
% disp('wrong');
% m_CQGAPI.NewInstrument('wrong')
% disp('IAUDJPY');
% m_CQGAPI.NewInstrument('X.IAUDJPY')

catch
disp '****** InstrumentSubscription ERROR ***********'
end

end
----------------------------------------------

Again a big thanks to anyone for any help, advice or references that you can provide. This stumps me, particularly since it works inside MATLAB, so there's no way to debug the problem.

Thanks!
Jim