cancel
Showing results for 
Search instead for 
Did you mean: 
Security Alert Log4j Security Vulnerability. Click here to know more.
cancel
Showing results for 
Search instead for 
Did you mean: 

Data Acquisition in rel 13 + realtime I/O

ptc-2033171
1-Newbie

Data Acquisition in rel 13 + realtime I/O

Hi everybody,
I am using MathCAD 2001i Professional. I noticed that the "Data Acquisition" component has the capability only to echange data with two brands of devices (quote from Help: "National Instruments E-Series data acquisition boards and PC cards, and Measurement Computing (formerly ComputerBoards) devices").
I would like to know if this is still so in the last release of MathCAD 13, and if not, which list of devices is now supported.

Moreover, I would like to hear your opinions about the possibility of communicating via MathCAD to the serial port (COM) and/or, even better, to the CANBUS interface of a hardware device.

What I need is some kind of "hardware in the loop" capability, where MathCAD simulates the physical system, and the "hardware" is the control being developed. So the MathCAD application should be able to read from device, make some calculations, and write out to the device again.

Are there previous experiences in this area? I searched the forum but could find nothing.

best regards
Claudio Pedrazzi
31 REPLIES 31

Claudio,

You might want to take a look at MathConnex for the things you try to do.

Regards,
Luc

P.S. did you take a look at my program in response to your date format question on the Usage Chat forum?

Dear Mr. Luc Meekes,
thanks but... I was not able to find any reference for this software on the web, except... someone stating that it does not exist anymore :-(.
Could you point me to the right source?

Thanks
Claudio Pedrazzi

PS: Concerning my other "data read" question, you are right, actually I did not realize its presence! I answered you in that thread.
RichardJ
19-Tanzanite
(To:ptc-2033171)

MathConnex is dead.

Richard
SteenGroðe
5-Regular Member
(To:RichardJ)

On 4/19/2006 12:03:17 PM, rijackson wrote:
>MathConnex is dead.

But if he is on v2001i it's still alive. It's in the download section.

Steen Gro�e
RichardJ
19-Tanzanite
(To:SteenGroðe)

True enough. Looking to the future though, a solution implemented in MathConnex cannot be migrated to the latest version of Mathcad, and that may be a very undesirable situation.

Richard
SteenGroðe
5-Regular Member
(To:RichardJ)

On 4/20/2006 9:17:31 AM, rijackson wrote:
>True enough. Looking to the
>future though, a solution
>implemented in MathConnex
>cannot be migrated to the
>latest version of Mathcad, and
>that may be a very undesirable
>situation.

Correct, but how about the VissimLE that probably still is somewhere among the downloads? I don't if or how the data acquisitions works in Vissim but I know that Vissim is much faster than Mathconnex.

MathConnex is alive and kicking, for versions up to 11. Simply go to the download on www.mathcad.com.

Luc.

P.S. I still have installable for 2001i, and the documentation PDF's.
RichardJ
19-Tanzanite
(To:ptc-2033171)

In theory, if your device can be controlled via an ActiveX control you could write a scripted component to do the work. See this thread for an example:

http://collab.mathsoft.com/read?78411,12e#78411

Richard

Thanks everybody for the many answers. After a few internal discussions, here I am again with a "follow-up" question. The "device" will certainly not have an ActiveX control, because it will be developed inside the company, and the preferred way of communication, due to simplicity, would be the serial port (COM1 / RS232).

Now I fould a few indications on how to use RS232 from Visual Basic: I am trying something like:

Set MSComm1 = CreateObject("Scripting.MSCOMM")


MSComm1.CommPort = 1 ' Select COM1
MSComm1.Settings = "9600,n,8,1" ' MSComm1.PortOpen = True ' Open COM1

and so on...

but I get an error when creating the object. Now my question is: do I have inside the "Scripting" language of MathCAD all the features of Visual Basic? and if not, which subset of them? I had a cursory look to the developer's help, but I was not able to answer this somehow "basic" question.

More generally, has someone practical advice about exactly how to interact with the serial port from MathCAD?

Any help would be appreciated.
Thanks a lot!
Best regards
Claudio Pedrazzi
RichardJ
19-Tanzanite
(To:ptc-2033171)

On 4/26/2006 8:26:33 AM, cpedrazzi wrote:
>Thanks everybody for the many
>answers. After a few internal
>discussions, here I am again
>with a "follow-up" question.
>The "device" will certainly
>not have an ActiveX control,

Yes it will, as you will see.....

>because it will be developed
>inside the company, and the
>preferred way of
>communication, due to
>simplicity, would be the
>serial port (COM1 / RS232).

OK

>Now I fould a few indications
>on how to use RS232 from
>Visual Basic: I am trying
>something like:
>
>Set MSComm1 =
>CreateObject("Scripting.MSCOMM
>")

You are trying to invoke MSCOMM32.ocx. That's an ActiveX control 😉

There are two problems. One, your syntax is incorrect. It's not part of the Scripting library. You should have:

MSComm1 = CreateObject("ScriptingMSCOMMLib.MSCOMM")

Unfortunately, that will not fix problem number 2. MSCOMM32.OCX is distributed with Visual Basic. If you don't have VB on the system, you don't have the control. You could copy it to you system, and register it (go to the command prompt and type "regsvr32 mscomm32.ocx"), but that will still not work because it's a licensed control. That means it can be distributed with a VB6 application, and when called from that application it will work. It will not work when called from any other application though.

Ther eis good news though. That control could be wrappered in a VB6 program that is itself compiled to an ActiveX control. And, that's been done:

http://ourworld.compuserve.com/homepages/richard_grier/NETCommOCX.htm

Note that you still need to download and register MScomm32.ocx from somewhere!

With all of that done, here's an example of calling the control from VBscript:

http://www.visualbasicscript.com/m_1947/mpage_1/key_/tm.htm

Follow the thread, and it gives an example near the end. Make sure to look at page 2 of the thread as well. The example is for a script to be run using the Windows Scripting host, so you will need to make some minor changes. Basically, you need to get rid of all the WScript references. So, for example, change the line

Set objTest = WScript.CreateObject("MSCOMMLib.MSComm", "[/b]MSCommEvent_")

to

Set objTest = CreateObject("MSCOMMLib.MSComm", "[/b]MSCommEvent_")

If you check page 2 of the thread, for this line you also need to change it to be:

Set objTest = CreateObject("NETCommOCX.NETComm", "[/b]MSCommEvent_")

If you manage to create a control that works, do us a favor and post it back here. Access to the RS 232 port from within Mathcad might be handy.



>but I get an error when
>creating the object. Now my
>question is: do I have inside
>the "Scripting" language of
>MathCAD all the features of
>Visual Basic?

No. It's a subset of VB

> and if not,
>which subset of them?

I really recommend you get a copy of the book I referenced in the other thread (with the file read question)


>More generally, has someone
>practical advice about exactly
>how to interact with the
>serial port from MathCAD?

As above 🙂

Best of luck

Richard




RichardJ
19-Tanzanite
(To:RichardJ)

Sorry. Typo on my part

The line

MSComm1 = CreateObject("ScriptingMSCOMMLib.MSCOMM")

should read

MSComm1 = CreateObject("MSCOMMLib.MSCOMM")

Richard

Richard,
your suggestions are very appreciated. The one on the file read is now "up and running", to my satisfaction!

This one might need a little more time 😉 but you gave me the "start" sign!

I also believe that interaction MathCAD RS232 could be interesting anyway, and will try to post what is "postable" without entering in the details of the application.

In order to give you an idea of what I am targeting, I will post a PDF printout of a big MathCAD worksheet (about 30 pages), implementing the control of the eolic generator. It is a 1 DOF time domain model, but realistic enough, because it contains a table lookup for the aerodynamic calculations (performed off-line with WTPERF software, from NREL,USA). And it contains the control algorithms (at least a subset of them). The input is a turbulent wind file from the specialised software TurbSim also developed by NREL, or some analytical curve defined by the standards.

The solution is obtainet by means of iterated calls to "rkfixed", intermixed with "control decisions", in a way that the differential equation being solved "changes" at every new DELTAT step, having as initial condition the final stage of the last step, and the new pitch and electric torque decided by the control.

The whole idea would be to substitute the "software control" with the "hardware" one.

Thanks again and
best regards from Italy
Claudio Pedrazzi
RichardJ
19-Tanzanite
(To:ptc-2033171)

On 4/27/2006 10:50:24 AM, cpedrazzi wrote:

>This one might need a little
>more time 😉

That's why I didn't write anything myself 🙂 Without finding some hardware to stick on my RS232 port it would be hard to test, too.

Richard

Hi everybody,
here I am, developing "My First VBScript" control.

I wish to share with you the progress, so I will attach the first "working" result, even if it is miles away from my final target. It is just a read/write on a Modem, but it is a small feasibility demonstration.

I got the required MSCOMM32.OCX, I installed the NETCommOCX exactly as suggested by Richard, and now I have the following two next questions, that both arise in the need to do something more "event-driven" than the attached example.

1) I do not find a sleep function in the VBScript language of MathCAD. Is this possible? I do need to be able to "wait a given time", without looping 100% CPU!!! I found a suggestion to use something like:

Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

but I get a syntax error!

2) (and more important). Of course I need to be able to work with the "OnComm" event. But the method suggested by Richard, involving the following syntax:

CreateObject("....", "[/b]MSCommEvent_")

does not work. I get "remote server not available" message when I run the script. Obviously the second argument is interpreted as the remote server on which to create the object! What is the meaning of this [/b]? I could not understand it.

Then I thought, it must be a name convention problem, and using what suggested in the the Developer's Guide (under Event Function Implementation), I simply created a function named: Object_Event, that is:

MSComm1_OnComm()

In this case, no runtime errors, but I have positive evidence that the function that I provided is NOT called (although the Property MSComm1.CommEvent is getting the appropriate value, namely "2", when I type something in the connected PC via HyperTerminal+RS232). The application loops never being able to exit, and I have to kill MathCAD.

Please have a look and tell me if you can understand what I am doing wrong. In exchange, I promise to post the final control that I will develop...

Thanks a lot
Claudio Pedrazzi


This is great work that you are doing. I regret that I cannot help because all my experience is with lower level languages and real-time platforms, but I look forward to your progress. I hope that others can contribute here...

Rich
http://www.DownEastEngineering.com/
RichardJ
19-Tanzanite
(To:ptc-2033171)

I forgot to get back to you on this, despite promises. Based on you email, as well as these posts, you can't do what you want from within a scripted component. The mathcad worksheet executes from top left to bottom right. When it encounters a control, it executes the associated script, and then exits the control. An event handler in a control is therefore inactive unless the control is actually executing. I don't see any way to make a Mathcad worksheet "aware" of external events, and respond to them; Mathcad is just not designed to do that. Might be a handy feature though :-).

You will need to put the event handler in an external program (e.g VB), and have the prograam call the Mathcad worksheet.

Richard

Perhaps you can embed the sheet within Excel. Everytime an input to the Mathcad component is changed, the Mathcad component is recalculated.

TTFN,
Eden
RichardJ
19-Tanzanite
(To:IRstuff)

Can an Excel spreadsheet be programmed to respond to external events? If it could, then it should work. I don't know much about Labview, but I tink that would work too.

Richard

I don't know about "programmed," but there's often some ActiveX or whatever that can be tied into Excel to data collect.

TTFN,
Eden
RichardJ
19-Tanzanite
(To:IRstuff)

OK, it's not really clear from these posts, but I have some extra info via email. Claudio wants a worksheet that will sit and watch a COM port. When data comes in (the event) it should automatically respond, and calculate new results. I see no way to do that in Mathcad. It could be done in a VB program, that would respond automatically to the OnComm event, then call the Mathcad worksheet to calulate new results. I don't know if it could be done in Excel, because I don't know if you can make an Excel worksheet sit aand watch for a specific event.

Richard

I have done something similar in the past. I used a DDE link between applications. The other application would set a flag in the spreadsheet by changing a cell value from 0 to 1. That would caused the spreadsheet to be recalculated. Recalculation would cause the associated VB code to execute. At the end of the VB code block, the flag was reset to 0.

It seems reasonable to imagine that the VB code can be made to loop looking for Comm activity, but that would eat up a lot of CPU time. It seems to me from my work in other areas that the OnComm event does just that - triggers code when there is com port activity.

Rich
http://www.DownEastEngineering.com/
RichardJ
19-Tanzanite
(To:Ninetrees)

That sounds like the same problem I am describing though. I could, in principle, make a scripted component loop endlessly looking for com activity. When it sees activity, it gets the data and passes it to the output. The rest of the Mathcad sheet then executes. If there is any more com activity nothing happens though, because the script is no longer running. I think, but don't know, that a VB program running in Excel will have the same limitation. The VB program is not running all the time - only when the contents of a cell are changed. Once it has done whatever the VB code is written for, it exits, and will therefore not see any more com activity.

What is needed is code at a lower level than the Mathcad or Excel sheet that recognizes an event, and then causes the Mathcad worksheet, or Excel sheet, to execute.

Richard

Umm, technically, I don't think so, even though I don't like what I am about to say. If the VB code executes a "while" loop with an exit condition set by, say, the user setting a value in the spreadsheet or selecting a button what changes a variable in the VB code space, then possibly the code could sit there and loop. I'm not familiar with the OnComm event in VB, but in other languages it would trigger an OnComm event and execute a code block.

Nonetheless, I don't like the idea of looping unconditionally because it eats up all the CPU time doing nothing. In the real time OSes that I use, there are ways to suspend a process until somebody tells it to wake up, but that is admittedly a different ball game altogether.

I agree that a good option is the one you suggest of a separate app that interacts with Excel. I'll take a look over the weekend at creating an app that can look for a Com event and notify Excel.

Rich
http://www.DownEastEngineering.com/
RichardJ
19-Tanzanite
(To:Ninetrees)

On 6/2/2006 9:27:54 AM, woodwise wrote:

>I agree that a good option is
>the one you suggest of a
>separate app that interacts
>with Excel. I'll take a look
>over the weekend at creating
>an app that can look for a Com
>event and notify Excel.

Claudio has already been looking for an app that will look for a com event and then call Mathcad (not Excel). Unless we hear back that the hunt was unsuccessful, you might want to save yourself some effort.

Richard



Hi all!
Sorry Sorry! I had watched the thread for a few days, waiting for new messages, than, since I have the E-Mail notification, I just forgot about it, believing nobody could help me :-).

Obviously the E-Mail notification did not work! today I discovered your answers. I will read them carefully and then will be back.

Anyway, we had to choose another way to achieve what we want, at the moment we are doing the simulation "without feedback", that is, I produce with MathCAD a normal ASCII file, than this is read from a simple PC program and "shot" as fast as possible on the serial port (and, believe it or not, on the sound card, because we wanted to spare AND have one more channel!). A small interface card reads both "channels" and produces the signals for the hardware control system.

It sounds a little "home-made", and actually it is ;-), but it works!

Thanks again,
Claudio

Hi again (after reading everything you wrote).
The main answer I needed has already been given: MathCAD is not done to do what I am asking for. It is what I feared already.

Yes, the whole idea was to AVOID the need to write another application and re-code the logic and the math that already goes into my MathCAD worksheet, in another environment. If that could work, I could be "sure" that there was no programming mistake at the low level (say, in the Runge-Kutta differential equation solver or the like). The MathCAD sheet contains:
0) preprocessing of turbulent wind files and/or superimposed standard analytical wind gusts
1) the aerodynamic response of the turbine (interpolated via a 2D table)
2) the "stepped" solution of the differential equation for the single rotational DOF
3) the logic of the control system, that "interrupts" the solution every DELTAT milliseconds and "decides" what to do with the torque request to the inverter AND with the pitch motion of the blades

Using MathCAD as a "base" to build on, I avoided much low level programming, and now I have neither time nor wish 🙂 to recode everything into another tool. The system runs faster than real time (meaning it takes less then 10 minutes to simulate 10 minutes of turbulent wind). If that was possible, I could test the control system "substituting" the MathCAD functions that implement the control with the "real time I/O" component connected to the RS232.

This mean MathCAD had to recalculate the sheet every time the serial port was "saying" something, without need for any human interaction to "refresh" the worksheet, exactly as you wrote above.

Superimposed to this "base" problem, I had, and I have, a problem with the OnComm event. I described it in a separate post, for clarity. It doesn't matter anymore, though, if the "base" problem cannot be solved.

thanks to everybody in this wonderful community,
a pity that the E-Mail notification is not working everytime.

Ciao a tutti dall'Italia!
Claudio
RichardJ
19-Tanzanite
(To:ptc-2033171)

You can still avoid the low level programming of the math. Have your external program, e.g. a VB program, watch the COM port for an event. When it sees an event it can pass the data from the COM port to Mathcad via the automation interface, and get the answer back. See the developers reference for more details. There are also some example bits of VB code in some threads in this forum.

Richard

Hi

now we have V15 out allow me to ask whether we have some good news from ptc about real time I/O

thanks

RichardJ
19-Tanzanite
(To:Efried)

Mathcad is just not the right environment for real time I/O. If that's what you want to do choose somethng else (e.g. LabView). Either save the data and import it into Mathcad later, or call Mathcad via the automation interface (which will not be that fast, so that may not work as part of a feedback control system).

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."