tcpip in S function
조회 수: 3 (최근 30일)
이전 댓글 표시
hello, i'm pretty new to matlab really, so what i know is pretty superficial (i.e. following templates). i've been programming for a while though in a few other languages so if out of luck i'd still be able to get things done with low level coding. anyhow, a little bit on what i'm trying to accomplish.
i'm trying to write a level 1 s function, (level 1 due to its simplicity and my lack of knowledge). that s function will in itself act as a UAV (unmanned aerial vehicle). The S function will poll data off of the sensors on the UAV via a tcpip connection, and these sensory information will be output to i.e. another program with an algorithm to process these information. the outputs of that algorithm will serve as the inputs for my S function, and these inputs will then be transmitted to the UAV again via tcpip inside the S function.
the problem i'm having is keeping the tcpip port openned during the simulation. if you try to open a file, a fileID is returned and that can be passed one as one of the state variables. however, opening a tcpip port generates an object, and i have no idea how the port can be opened inside mdlInitializeSizes and still be used else where. (global variables didn't seem to work for me, although i might be doing that wrong as well...). the only possible work around is to open and close the port during each step, i'm guessing this will be costly timewise, and might not work for this application.
any ideas? functions i should look into etc?
Thanks!
댓글 수: 0
답변 (1개)
Kaustubha Govind
2011년 5월 13일
If you are using Level 1 MATLAB S-functions, I would highly recommend considering Level-2 S-functions instead. I think the primary difference is actually the fact that Level 1 S-functions have long been deprecated and only exist for the sake of backwards compatibility. Level 2 S-functions have greater features and capabilities to offer, and at least Level 2 MATLAB S-functions are not that much harder to implement than their Level 1 counterparts.
Coming to your question - PWork vectors are the ideal solution here, but unfortunately, they are only supported with C/C++ MEX S-functions (Level 1 MATLAB S-functions do not support any work vectors, and Level 2 MATLAB S-functions support only DWork vectors which cannot store non-numeric values).
Although I hesitate to propose this - if you do not plan to have multiple instances of this S-function running simultaneously - using global variables (as you seem to have already tried) may be the most appropriate solution. Could you provide a brief description of how you tried using a global variable to store the tcpip object and how it failed?
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!