Skip to content

Serial communication

Jordi edited this page Jan 21, 2022 · 7 revisions

Communication between device and computer is over UART protocol (using a ch341 IC UART to USB adapter). Baudrate is set at 115200 bauds and all the data is sent by plain text with the gb2312 chinese charset encoding. Other charset won't work. (for example: if you use the arduino serial monitor you won't send commands to device).

 ________                   __________
|        |    UART-USB     |          |
| Device |<--------------->| Computer |
|________|  115200 bauds   |__________|

Commands

List of commands that computer can send to device:

Instruction Description
Q Connect to device
W Disconnect from device
V[0-9]{4} Set output voltage to ##.## V
I[0-9]{4} Set output current to #.### A
X Enable time protection
Y Disable time protection
H[0-9]{2} Set ## hours of time protection
M[0-9]{2} Set ## minutes of time protection
S[0-9]{2} Set ## seconds of time protection
B[0-9]{4} Set voltage protection at ##.## V
D[0-9]{4} Set current protection at #.### A
E[0-9]{4} Set power protection at ###.# W
O Load M1 preset config values
P Load M2 preset config values
Z Reset status flag
N Turn output supply ON
F Turn output supply OFF
U Update firmware (not implemented)

Some aclarations:

  • Protections are maximum values admited at output, when exceeded device turns off output. When some protection is activated the status flag change. More info at status flags.
  • M1 & M2 presets are useful for DC580, I suppose this is for loading presaved values.
  • Reset status flag is for clear status when a protection is activated.

All of these instructions are followed by \r\n. Here are some examples:

serial.writeString("Q\r\n")     // connect to device
serial.writeString("V0330\r\n") // Set output voltage to 3.3v
serial.writeString("H11\r\n")   // Set time protection to 11:##:##
serial.writeString("M26\r\n")   // Set time protection to ##:26:##
serial.writeString("N\r\n")     // Turn output on

Status snapshots

Device sends information of status to de computer in a some sort of "snapshot" that contains all values concatenated and each one has an 'A' trailing character. There are four different types of status snap distinguished by number of fields: 7, 9, 15 or 17 (I saw another version with different number of fields 😓). All fields has numeric values only (no alphabet characters neither dots or commas) and software has to parse it to floating values. Number of digits is fixed, padding 0s at right or left if necessary.

Representation diagram of all types:

Fields details:

Field Value format Description
Voltage output value [0-9]{4} Output voltage value is ##.## volts
Current output value [0-9]{4} Output current value is #.### amperes
Power output value [0-9]{4} Output power value is ###.# watts
Temperature units 0 or 1 0 for celsius unit and 1 for farenheit
Current temperature [0-9]{3} Representation of ### (celsius or farenheit defined at units)
CC or CV 0 or 1 0 for CV (Constant Voltage) and 1 for CC (Constant Current)
Flag Status [0-5] 0:OK, 1:OVP, 2:OCP, 3:OPP, 4:OTP & 5:OHP (see flags for info)
Voltage output set [0-9]{4} Setted voltage output to ##.## volts
Current output set [0-9]{4} Setted current output to #.### amperes
Voltage protection set [0-9]{4} Setted voltage protection to ##.## volts
Current protection set [0-9]{4} Setted current protection to #.### amperes
Power protection set [0-9]{4} Setted power protection to ###.# watts
Enabled time protection 0 or 1 0 for disabled and 1 for enabled
Hours of time protect. [0-9]{2} Setted hours of protection to ##
Minutes of time protec. [0-9]{2} Setted minutes of protection to ##
Seconds of time protec. [0-9]{2} Setted seconds of protection to ##
ON/OFF at output 0 or 1 0: output supply is off, 1: output supply is on

Example of each type:

  1. 0000A0000A0000A0A023A0A0A
  2. 0000A0000A0000A0A023A0A0A0330A5000A
  3. 0000A0000A0000A0A023A0A0A1200A0050A10000A0A00A00A00A0A
  4. 0000A0000A0000A0A023A0A0A0499A5000A1200A0050A10000A0A00A00A00A0A

When is received each type?:

  • Type 1 (shortest): periodically (in a time lesser than one second). Serial event is necessary to handle it.
  • Type 2: voltage output or current output has changed.
  • Type 3: some of the protections has changed.
  • Type 4 (all fields): only received once when PC connects to device.

Device identification

When computer sends to device the connection command, the device identifies itself by sending a pair of characters (followed by '\r\n' too):

Code Device
KB DC-6006L
MB DC-580

Status flags

Flag code Description
OK Normal status
OVP Overvoltage protection
OCP Overcurrent protection
OPP Overpower protection
OTP Overtemperature protection
OHP Overtime protection

General sequence diagram of communication

Clone this wiki locally