Skip to content

Repository files navigation

checkBatteryState

Using Win32 API to control UART for reading battery state. It can show battery capacity, current, votage.

UI

Capture

Open com port

My_SerialPort=newSerialPort();if(My_SerialPort.IsOpen){CloseComport();}//config Serial PortMy_SerialPort.PortName=comboBox_comPortSelecter.Text;My_SerialPort.BaudRate=9600;My_SerialPort.DataBits=8;My_SerialPort.StopBits=StopBits.One;if(!My_SerialPort.IsOpen){interror=0;//open Serial Porttry{My_SerialPort.Open();}catch(Exceptionex){error=1;MessageBox.Show(ex.Message);}if(error==0){Console_receiving=true;sendData=newThread(DoSend);sendData.IsBackground=true;sendData.Start();receiveData=newThread(DoReceive);receiveData.IsBackground=true;receiveData.Start();}}else{MessageBox.Show("Serial port has been opened.","",MessageBoxButtons.OK,MessageBoxIcon.Error);}

Receive data

privatevoidDoReceive(){Byte[]buffer=newByte[32];try{while(Console_receiving){if(My_SerialPort.BytesToRead>0){Int32length=My_SerialPort.Read(buffer,0,buffer.Length);Array.Resize(refbuffer,length);
.......

Write data

publicvoidserialWrite(bytea,byteb,bytec,byted){try{Byte[]buffer=newByte[4]{a,b,c,d};//BIOS nameMy_SerialPort.Write(buffer,0,buffer.Length);}catch(Exceptionex){CloseComport();MessageBox.Show(ex.Message);}}
voidDoSend(){while(true){switch(getDataType){case100://get BIOS BOM and BIOS namelable_biosBom.Text="";getDataType=0;//parse methodserialWrite(0x04,0xA0,0x00,0x5c);//BIOS BOMThread.Sleep(750);//wait for receive data
..............

About

Using Win32 API to control UART for reading battery state. It can show battery capacity, current, votage.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages