C#_SDK Quick Start
C#_SDK quick start
Applicable Model
Routine download
Go to the link below to download the sample
https://github.com/WITMOTION/WitStandardProtocol_JY901
Noun introduction
Wit-motion private protocol: Wit-motion protocol for short, is the protocol used by Wit-motion sensors, usually TTL or 232 level sensors use Wit-motion protocol; the agreement stipulates that the sensor returns the data packet starting with 55, and the host computer sends the data packet starting with FF AA;
Routine introduction
This routine introduces how to use C# to develop the upper computer to connect to the Wit-motion protocol sensor, receive sensor data and communicate with the sensor;
Before viewing this routine, please read the relevant sensor manual to understand the protocol used by the sensor and the basic functions of the sensor
Routine directory
The routine project directory is as follows
Dll: The dependent files of the project, please import these dlls into your project before running the project.
Form1:There is only one Form window in the routine, all logic codes are in the Form window file, and there are no other files

Turn on the device
The JY901 object represents the JY901 device in the program, and you can communicate with the device through it; when opening the device, you need to specify the serial port number and baud rate of the sensor, and call the JY901.Open() method after specifying
turn off the device
Receive sensor data
Get data
The JY901 object will automatically calculate the sensor data and save it on itself. The sensor data can be obtained through the JY901.GetDeviceData() method. JY901.GetDeviceData() needs to pass in a key to get sensor data. Please check the key that needs to be used in the routine, the key is stored in the WitSensorKey class
Record data
The data of the sensor can be obtained through the JY901 object, but usually the upper computer needs to record the data of the sensor. JY901 has an OnRecord event that will notify you when to record the data, and the OnRecord event can be realized when the device is turned on; and then through cooperation with JY901.GetDeviceData( ) method to record the data
set sensor
The sensor can be operated by the method of JY901
JY901.UnlockReg() Send unlock register command
JY901.AppliedCalibration() Send meter calibration command
JY901.StartFieldCalibration() Send start magnetic field calibration command
JY901.EndFieldCalibration() Send end magnetic field calibration command
JY901.SendProtocolData() Send other commands
Accelerometer Calibration
Apply accumulative calibration to the sensor by calling the JY901.AppliedCalibration() method
Magnetic Field Calibration
Calibrate the magnetic field of the sensor by calling the JY901.StartFieldCalibration() method and the JY901.EndFieldCalibration() method
More
For other operations, please refer to the sensor manual
read sensor register
The register of the sensor can be read through the JY901.SendReadReg() method, or the JY901.SendProtocolData() method can be used
After sending the read command, the register value will be saved in JY901, you need to get the register data through JY901.GetDeviceData()
JY901 API
Method
illustrate
Parameter introduction
Return value
void SetPortName(string portName)
Set the serial port to open
PortName: serial port number
void
void SetBaudrate(int baudRate)
Specify the baud rate to open
BaudRate: baud rate
void
void Open()
Turn on the device
None
void
bool IsOpen()
Is the device turned on
None
Return whether to open open: true close: false
void Close()
turn off the device
无
void
void SendData(byte[] data, out byte[] returnData, bool isWaitReturn, int waitTime , int repetition)
send data
data: the data to be sent
returnData: the data returned by the sensor
isWaitReturn: Whether the sensor needs to return data
waitTime: wait for the sensor to return data time, unit ms, default 100ms
repetition: the number of times to repeat sending
void
void SendProtocolData(byte[] data)
send protocol data
data: the data to be sent
void
void SendProtocolData(byte[] data, int waitTime)
Send data with protocol, and specify the waiting time
data: the data to be sent
waitTime: waiting time
void
void SendReadReg(byte reg, int waitTime)
Send the command to read the register
reg: command to be sent
waitTime: waiting time
void
void UnlockReg()
unlock register
none
void
void SaveReg()
save register
none
void
void AppliedCalibration()
Calibration
none
void
void StartFieldCalibration()
Start Magnetic Field Calibration
none
void
void EndFieldCalibration()
End magnetic field calibration
none
void
void SetReturnRate(byte rate)
set return rate
rate: the return rate to be set
void
string GetDeviceName()
get device name
none
return device name
string GetDeviceData(string key)
Get Key value data
key: data key value
return data value
English description
Last updated