Checking for presence of System::IO::Ports::SerialPort
-
I'm attempting to write communication software to talk to a laser via RS232. If I setup a Managed C++ class that has a SerialPort variable how can I test the variable to see that it is present or has a valid value. So in my code I have: .h file -------- SerialPort^ sp; .cpp file --------- if(sp) //Testing to see if 'sp' has already been assigned a value. { if(sp->IsOpen) sp->Close(); } sp = gcnew SerialPort("Com1"); Any idea how to check to see if an Object handle has been assigned? Thanks,
George
-
I'm attempting to write communication software to talk to a laser via RS232. If I setup a Managed C++ class that has a SerialPort variable how can I test the variable to see that it is present or has a valid value. So in my code I have: .h file -------- SerialPort^ sp; .cpp file --------- if(sp) //Testing to see if 'sp' has already been assigned a value. { if(sp->IsOpen) sp->Close(); } sp = gcnew SerialPort("Com1"); Any idea how to check to see if an Object handle has been assigned? Thanks,
George
...sp=nullptr; if (sp==nullptr) { dosometing; } alse,you can do like this ..sp; if (sp==nullptr) { dosometing; } in the c++/cli,the default object is equal to "nullptr".