In questo articolo sono presenti due progetti che mostrano come utilizzare i driver IToolS in un’applicazione MFC ed in un’applicazione console VC++:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
// IToolSVCClr.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <vcclr.h> void OnChanged(System::Object^ sender, IToolS::Data::ChangedEventArgs ^e) { System::Console::WriteLine(System::String::Format("New value {0}", e->NewValue)); } int _tmain(int argc, _TCHAR* argv[]) { gcroot<IToolS::Lite::Communication::Variable^> variable = gcnew IToolS::Lite::Communication::Variable(); gcroot<IToolS::Lite::Communication::Client^> client = gcnew IToolS::Lite::Communication::Client(); gcroot<IToolS::Lite::Communication::Group^> group = gcnew IToolS::Lite::Communication::Group(); gcroot<IToolS::Lite::IOServers::IOServer^> ioserver = gcnew IToolS::Lite::IOServers::IOServer(); variable->VariableName = "var"; variable->Address = "10"; variable->Changed += gcnew IToolS::Data::ChangedEventHandler(OnChanged); group->Add(variable); ioserver->Name = "Simulation"; client->Group = group; client->IOServer = ioserver; client->Start(); System::Console::WriteLine("Press ENTER to exit"); System::Console::ReadLine(); client->Stop(); client->StopIOServer(); return 0; } |