# Demodulator mainboard control and data protocol :id=top

------

> _Doc Ver:_ 1.0  
_App Ver:_ 2.6.6.53  
_Date:_ 09/13/2026

------

> Mainboard / data-link protocol used inside SA1 2.x (`sa-di`).  
> Older “with / without RTLinux” wording is historical; the frame layout is unchanged.

-----

## 1. Hardware interface  :id=port

  * RJ45 network interface
  * RS232 serial interface

## 2. Default configuration      :id=default

  > If the demodulator has no clear marking or other instructions, it uses the following parameters.

  2.1. Default network configuration of the demodulator
  * Demodulator IP address: 192.168.3.254
  * Demodulator local command receive port: 8193
  * Host computer data receive port: 8190
  * Idle `*rst!;` to 8193 after locking the source IP: [Device reset watchdog](device-rst.md)

  2.2. Default serial-port configuration
  * Baud rate: 115200
  * 8 data bits, 1 stop bit, no parity

## 3. Wavelength data frame structure    :id=data_frame
  |Frame structure|Byte length|Remarks|
  |---|:---:|---|
  |Start bits|2|Fixed value: 0xFFFF|
  |Flag bit|1|0x00: no device code<br>0x01: with device code|
  |Status bit|1|0x00: data normal<br>0x02: built-in temperature sensor abnormal<br>0x10: data output busy<br>0x20: serial port abnormal|
  |[Device code]|4|When the flag bit is 0x01, the frame includes a four-byte device code, low byte first, high byte last|
  |Device channel count|1|Number of channels on the current device (N)|
  |Wavelength count per channel|N|Each byte is the wavelength count of sequential channels (N1,N2,N3,...) |
  |Wavelength data|(N1+N2+N3+...)*2|Data amount of the currently output spectrum (N) |

  3.1. Wavelength data frame example (no device code)

  <img src="_images/waveLength(noCode).png" width="30%">

  3.2. Wavelength data frame example (with device code)

  <img src="_images/waveLength(withCode).png" width="30%">

  3.3. Wavelength data
  
  Each grating's wavelength data is two bytes, such as [0xD8, 0x6B] and [0x45, 0x53] in the figure; grating wavelength = 1510000 + (low byte + high byte × 256);<br>In the figure, the grating wavelength of the third channel is: 0x45+(0x53×256)+1510000=1531317.

  3.4. Device temperature
  
  The device has a built-in temperature sensor that monitors internal temperature;
  
  The temperature-sensor data occupies the first wavelength data of the first channel;
  
  Device temperature = (low byte + high byte × 256-10000) / 10;
  
  In the example above, the device temperature is: (0xFE+(0x07×256)-10000)/10=23.8.

## 4. Spectrum data frame structure    :id=os_frame

  |Frame structure|Byte length|Remarks|
  |---|:---:|---|
  |Start bits|2|Fixed value: 0xFFFF|
  |Status bits|2|0x00: data normal<br>0x02: built-in temperature sensor abnormal<br>0x10: data output busy <br>0x20: serial port abnormal|
  |Spectrum channel|1|Channel of the currently output spectrum|
  |Spectrum data length|2|Data amount of the currently output spectrum (N)|
  |Spectrum data|M|M=N×2; each spectrum sample occupies two bytes|

  4.1. Spectrum data frame structure

  <img src="_images/Spectral.png" width="30%">

?> In the example above, the first two bits of 0x40 mean spectrum output; the last six bits are the output channel. Channel numbers start at zero. For example, 0x40 is channel 1, 0x41 is channel 2, and so on.

  4.2. Spectrum data

  Each spectrum sample is two bytes, low byte first, high byte last.

## 5. Device control commands  :id=equ_ctrl

  * Send the specified command to the demodulator command port [8193] to switch the device to wavelength output mode or spectrum output mode:
  * Or write the specified command to the serial port to switch the device to wavelength output mode or spectrum output mode:

  |Command|Remarks|
  |:---:|---|
  |*chs!;|Switch to spectrum output mode|
  |*chw!;|Switch to wavelength output mode (default) |
  |*pau!;|Pause laser scanning|
  |*ccp!;|Switch data output between the network port and the serial port|

## 6. Configure the demodulator network address    :id=ip_set

  * Send the specified command to the demodulator command port [8193]
  
  |#|Command |Remarks|
  |:---:|:---:|---|
  |1|*cfg!;|The device enters configuration state|
  |2|*net?;|Query the device network configuration; format:<br>{"RPort":8190,"IP":[192,168,3,253],"SubMask":[255,255,255,0],"GateWay":[192,168,3,1],"RemoteIP":[192,168,3,255]};|
  |3|*net:{parameter: value,...};|Set device network parameters, example:<br>*net:{"RPort":8191,"IP":[192,168,1,251],"GateWay":[192,168,1,1],"RemoteIP":[192,168,1,11]};|
  |4|*sav!;|Save configuration; the device restarts|

  ~~~
  Network parameters:
  RPort:        Port on which the host computer receives data
  IP:           Local IP address of the device
  SubMask:      Network subnet mask
  GateWay:      Network gateway address
  RemoteIP:     Address to which data is sent; the default is the broadcast address.
  ~~~

## Change log :id=changelog

|Version|Date|Description|
|:--:|----|----------|
|1.0|10/25/2021|1. Use the new file structure.|

------

### [Top](#top)
