Controlling an SCPI instrument in Simulink

조회 수: 8 (최근 30일)
chris akins
chris akins 2017년 6월 27일
댓글: 佳祺 2023년 7월 18일
Hi all,
I’m working on interfacing a dSPACE-based controller with a power supply that speaks SCPI, and I’m trying to figure out how to use their Ethernet blockset to do it, which is much like Mathworks' TCP/IP Send and TCP/IP Receive blocks. Because of how compiled Simulink models interact with their Ethernet hardware and drivers, I cannot use the Instrument Control Toolbox.
An example query would be “volt:prot?\r\n” to query the overvoltage threshold, and “volt:prot 50\r\n” to set it. The query would receive a reply something like “50\r\n”, and the command would receive no reply at all.
I can compose outbound messages easily enough with array concatenation, but I’m at a loss as to how to parse variably-sized incoming replies, or to accumulate incoming bytes until a reply has completely come across the wire. For example, a command of “<> STA?\r\n” requests a status, and gets a reply like “, 1, 2, 3, 4\r\n”. If I requested a buffer of 100 bytes, I’d have to send the command several times, and I’d get a number of replies glued together; if I requested a buffer of 1 byte, I wouldn’t know what to do with it until I got the “\r\n” pattern. I could write a stream-oriented parser for incoming messages, but that wouldn’t know, for a reply of ‘1000’, if the first ‘1’ should be multiplied against 1, 10, 100, or 1000, so that’s not a great solution.
Pure-Simulink solutions are ideal, since I need to generate code from this model, but I may be able to modify function blocks to do what's needed - the restrictions of the environment and toolchain make it dicey.
Thanks in advance!
  댓글 수: 2
Marcelo Saboia
Marcelo Saboia 2019년 4월 19일
편집: Marcelo Saboia 2019년 4월 19일
Hello Chris,
I am trying to do almost the same thing you are doing (interfacing a dSPACE-based controller with a power supply that speaks SCPI) but in my case I need to use a Serial Communication (RS-232) and I would like to know how you send the SCPI Commands via SIMULINK.
I don't know how to convert a String Type variable (like your command “volt:prot?\r\n”) to ASCII to use as INPUT in the dSPACE Serial Communication blockset. My matlab is earlier than 2018a so a don't have the feature String to ASCII, and I am not pretty sure if this feature would be usefull.
Thanks in Advance,
Marcelo Saboia
佳祺
佳祺 2023년 7월 18일
I had almost the same problem as you, don't know if you solved it

댓글을 달려면 로그인하십시오.

채택된 답변

Vinod
Vinod 2017년 7월 30일
Perhaps you can use the Simulink While Iterator to run a subsystem that reads in the data until a '/n' is received? In your subsystem you read one byte at a time and store it into a buffer that will then be used later in the processing chain.

추가 답변 (1개)

chris akins
chris akins 2017년 7월 31일
We found a workaround by parsing all returns as float64. It's not great, but it's good enough. I'll play with this, though, it might fix some other networking weaknesses we're fighting.

카테고리

Help CenterFile Exchange에서 Direct Interface Communication in Simulink에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by