@@ -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,24 @@ 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+ let rate = baudRate
84+ if ( customBaudRate && ! baudRateOptions . some ( option => option . value === customBaudRate ) ) {
85+ rate = customBaudRate
86+ }
87+
88+ const success = await window . electron . ipcRenderer . invoke ( IpcEvents . OPEN_SERIAL_PORT , port , rate )
8389
8490 if ( success ) {
8591 setSerialPort ( port )
@@ -99,12 +105,12 @@ export const SerialPort = ({ setMsg }: SerialPortProps): ReactElement => {
99105 async function handleBaudRateChange ( newBaudRate : number ) : Promise < void > {
100106 setBaudRate ( newBaudRate )
101107 storage . setBaudRate ( newBaudRate )
102-
108+
103109 if ( serialPort && serialPortState === 'connected' ) {
104- const currentPort = serialPort
110+ const currentPort = serialPort
105111 await closeSerialPort ( )
106112 setTimeout ( ( ) => {
107- selectSerialPort ( currentPort )
113+ selectSerialPort ( currentPort , newBaudRate )
108114 } , 200 )
109115 }
110116 }
@@ -118,7 +124,7 @@ export const SerialPort = ({ setMsg }: SerialPortProps): ReactElement => {
118124 loading = { serialPortState === 'connecting' }
119125 status = { isFailed ? 'error' : undefined }
120126 placeholder = { t ( 'modal.selectSerial' ) }
121- onChange = { selectSerialPort }
127+ onChange = { ( serialPort ) => selectSerialPort ( serialPort ) }
122128 onClick = { ( ) => getSerialPorts ( false ) }
123129 />
124130 < Select
0 commit comments