@@ -41,7 +41,7 @@ export const SerialPort = ({ setMsg }: SerialPortProps): ReactElement => {
4141 useEffect ( ( ) => {
4242 const savedBaudRate = storage . getBaudRate ( )
4343 setBaudRate ( savedBaudRate )
44-
44+
4545 getSerialPorts ( true )
4646
4747 const rmListener = window . electron . ipcRenderer . on ( IpcEvents . OPEN_SERIAL_PORT_RSP , ( _ , err ) => {
@@ -68,18 +68,20 @@ export const SerialPort = ({ setMsg }: SerialPortProps): ReactElement => {
6868 if ( autoOpen ) {
6969 const port = storage . getSerialPort ( )
7070 if ( port && serialPorts . includes ( port ) ) {
71- await selectSerialPort ( port )
71+ const savedBaudRate = storage . getBaudRate ( )
72+ await selectSerialPort ( port , savedBaudRate )
7273 }
7374 }
7475 }
7576
76- async function selectSerialPort ( port : string ) : Promise < void > {
77+ async function selectSerialPort ( port : string , customBaudRate ?: number ) : Promise < void > {
7778 if ( serialPortState === 'connecting' ) return
7879 setSerialPortState ( 'connecting' )
7980 setIsFailed ( false )
8081 setMsg ( '' )
8182
82- const success = await window . electron . ipcRenderer . invoke ( IpcEvents . OPEN_SERIAL_PORT , port , baudRate )
83+ const rate = customBaudRate ?? baudRate
84+ const success = await window . electron . ipcRenderer . invoke ( IpcEvents . OPEN_SERIAL_PORT , port , rate )
8385
8486 if ( success ) {
8587 setSerialPort ( port )
@@ -99,12 +101,12 @@ export const SerialPort = ({ setMsg }: SerialPortProps): ReactElement => {
99101 async function handleBaudRateChange ( newBaudRate : number ) : Promise < void > {
100102 setBaudRate ( newBaudRate )
101103 storage . setBaudRate ( newBaudRate )
102-
104+
103105 if ( serialPort && serialPortState === 'connected' ) {
104- const currentPort = serialPort
106+ const currentPort = serialPort
105107 await closeSerialPort ( )
106108 setTimeout ( ( ) => {
107- selectSerialPort ( currentPort )
109+ selectSerialPort ( currentPort , newBaudRate )
108110 } , 200 )
109111 }
110112 }
@@ -118,7 +120,7 @@ export const SerialPort = ({ setMsg }: SerialPortProps): ReactElement => {
118120 loading = { serialPortState === 'connecting' }
119121 status = { isFailed ? 'error' : undefined }
120122 placeholder = { t ( 'modal.selectSerial' ) }
121- onChange = { selectSerialPort }
123+ onChange = { ( serialPort ) => selectSerialPort ( serialPort ) }
122124 onClick = { ( ) => getSerialPorts ( false ) }
123125 />
124126 < Select
0 commit comments