フィルターのクリア

Using fprintf and instrument control toolbox with serial connection

1 回表示 (過去 30 日間)
Senaasa
Senaasa 2013 年 9 月 30 日
回答済み: Walter Roberson 2013 年 9 月 30 日
Hi,
I'm trying to send commands to a monochromator (CM110/112) connected to a cpu (RS232). I've successfully connected to the instrument using serial() and also by using the instrument toolbox but I'm having trouble understanding how to send commands to it. The manual gives the following example:
<pre class="language-matlab">GOTO
This command moves the monochromator to a selected position.
To CM110/112: &lt;16> D &lt;High Byte> &lt;Low Byte> [*The D denotes decimal value of the byte is being used)
From CM110/112: &lt;Status Byte>
CM110/112 Action: If valid, move to position ( 256 * &lt;High Byte> ) + &lt;Low Byte> [units].
From CM110/112: &lt;24> D
For example, the command to instruct the monochromator to GOTO the wavelength 250 nm could be sent as the three bytes &lt;16> D &lt;0> D &lt;250> D (if the current units are in nm). Here, &lt;16> D specifies the

採用された回答

Walter Roberson
Walter Roberson 2013 年 9 月 30 日
I would advise you not to attempt to use fprintf() for communicating with that device. fprintf() has the undocumented limitation that if it encounters a null byte (value 0) in the string, it will consider the string to have finished and will not send anything beyond that point. There are ways to get around that but they are a pain, and the alternative is not difficult.
The sample command shown could be coded as
fwrite( fid, uint8([16 0 250]) );

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInstrument Control Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by