Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-21
9
Medium Priority
?
309 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 1000 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
Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

 

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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Monitor input from a computer is usually nothing special.  In this instance it prevented anyone from using the computer.  This was a preconfiguration that didn't work.
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

688 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