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!