Solved

A question to mrdtn: How does one close the port of the multimeter?

Posted on 2004-08-21
9
307 Views
Last Modified: 2008-03-06
mrdtn,

The code you provided which was rewritten for managed Visual C++ .NET by drichards seems to be working very well. Unfortunately, I still can only acquire data at 0.5s interval since other, larger intervals, cause delays and faulty readings for some reason. For now, having no choice, I will stay with this 0.5s interval.

I have now an additional question which we did not discuss before. How does one close the port? I would like to get out of the part of the program which acquires data, then do some other tasks and at some point go back and acquire a new set of data, unrelated to the first set. It seems that to do that one has to close the port (and then open it upon subsequent call to the device). Hope you’re around and can help me with this. Thanks in advance.

judico

0
Comment
Question by:judico
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 250 total points
ID: 11872968
You close the port with 'CloseHandle'.  In this case, add a method to the MultiMeter class:

    void Close();

Implement it like this:

void MultiMeter::Close()
{
    CloseHandle(m_hComm);
}

You'll have to figure out a good way to call it in your program - manually by a button click or automatically by handling some event in your program (closing the form, or a timer if you want it to just run for some fixed period).
0
 

Author Comment

by:judico
ID: 11874694
I placed your above code in MultiMeter.h. However, can't figure out how to close the port from the form temperature.h. In temperature.h I have #include "MultiMeter.h" but

private: System::Void temperature_Load(System::Object *  sender, System::EventArgs *  e)
             {
                  
MultiMeter::Close()

                 }

doesn't do any good.
0
 
LVL 19

Expert Comment

by:drichards
ID: 11874974
You need a pointer to the MultiMeter object.  Also, closing the multimeter on the form load seems to be inappropriate unless this is a new form coming up after you're finished reading data.  Also, tou'll have to kill the timer so you don't try to read data after the meter is closed.  Otherwise, you'll have to add a state variable indicating whether the meter is open or not.  You could set m_hComm to 0 in CLose() and check if m_hComm is 0 before reading data.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:judico
ID: 11875413
See, the idea is when the work in temperature.h is finished to go back to Form1.h by clicking on the X in the upper right corner. I don't want this going back to Form1.h to be done by pressing a special button ... That's why the form load ... I'll try to do it differently.

But, before that, I don't know how to set a pointer to MultiMeter object from temperature.h or from Form1.h (maybe the closing of the port should occur upon returning to Form1.h).
0
 
LVL 19

Expert Comment

by:drichards
ID: 11876079
>> when the work in temperature.h is finished to go back to Form1.h by clicking on the X in the upper right corner

Then you probably want to do it in the 'Closing' or 'Closed' event of the temperature form, not the 'Load' event.
0
 

Author Comment

by:judico
ID: 11876532
OK, I'll try that but I don't know how to close the port while I'm in temperature.h.
0
 
LVL 19

Expert Comment

by:drichards
ID: 11878078
What's the relationship between Form1 and temperature?  You'll probably have to give temperature a reference to multimeter when you create temperature.  How do you create temperature?
0
 

Author Comment

by:judico
ID: 11878502
You know, my main problem is that when you rewrote into managed VC++ the program given by mrdtn, I treated it as a black box and wrote the rest of the code around it without getting into the details of the code you sent me. It works beautifully now as is (with the exception that I can't have intervals other than 0,5s, as well as this business with closing the port) but now I need to understand the nitty gritty of your code because I need to simplify it so that I can use it with a PIC device. I know how to do it in VB.NET with a special rs232comms.dll I have but I want to learn how to do it your way which I like better.

In the program that I have now, temperature.h, where the main activity in calling the device and plotting the data occurs, is called from Form1.h. When I finish with the tasks in temperature.h, I go back to Form1.h. This is the moment when I want to close the device. Because I may need later to go back into temperature.h and acquire a new set of data, unrelated to the first.

At present, if I want to take a new set of data (without exiting the program), I unplug and then plug back the USB-RS232 cable while in Form1.h and then get into temperature.h -- the data is acquired fine in this way. I want, however, to avoid that step of unplugging and again plugging the cable.

More importantly, I want to simplify your code, so that, as I mentioned, I can use it with a PIC device, instead of with the multimeter which we've been discussing so far.
0
 

Author Comment

by:judico
ID: 11879160
Now, I figured that out -- the closing of port part. I placed in MultiMeter.cpp the code you gave above for closing of the port:

void MultiMeter::Close()
{
    CloseHandle(m_hComm);
}

Then, in MultiMeter.h I placed:

public:
     void Close();

and finally I had to relinquish the idea of closing the port upon leaving temperature.h and in its stead I placed

mmeter->Close();

in a button which also kills the timer.

Thanks again for your help on this problem. I will probably open a separate question to discuss the code you translated from unmanaged to managed VC++.



P.S. I increased your points to 250. Please let me know if you have problems in getting the increased number of points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cisco USB console Windows 8.1 unable to open serial port 4 138
Smoothing a rectified sine wave DDS 32 155
Cant Extend Laptop screen 6 95
base to cord ratio 3 49
In this article you will get to know about pros and cons of storage drives HDD, SSD and SSHD.
In this article we have discussed the manual scenarios to recover data from Windows 10 through some backup and recovery tools which are offered by it.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question