11using System ;
2+ using System . Linq ;
23using Newtonsoft . Json ;
34using _1RM . Model . Protocol . Base ;
45using _1RM . Utils . KiTTY ;
@@ -66,6 +67,59 @@ public string BitRate
6667 set => SetAndNotifyIfChanged ( ref _bitRate , value ) ;
6768 }
6869
70+
71+ public string [ ] DataBitsCollection => new [ ] { "5" , "6" , "7" , "8" } ;
72+ private string _dataBits = "8" ;
73+ public string DataBits
74+ {
75+ get => _dataBits ;
76+ set => SetAndNotifyIfChanged ( ref _dataBits , value ) ;
77+ }
78+
79+
80+ public string [ ] StopBitsCollection => new [ ] { "1" , "2" } ;
81+ private string _stopBits = "1" ;
82+ public string StopBits
83+ {
84+ get => _stopBits ;
85+ set => SetAndNotifyIfChanged ( ref _stopBits , value ) ;
86+ }
87+
88+ public string [ ] ParityCollection => new [ ] { "NONE" , "ODD" , "EVEN" , "MARK" , "SPACE" } ;
89+ private string _parity = "NONE" ;
90+ public string Parity
91+ {
92+ get => _parity ;
93+ set => SetAndNotifyIfChanged ( ref _parity , value ) ;
94+ }
95+
96+ public string GetParityFlag ( )
97+ {
98+ if ( string . IsNullOrWhiteSpace ( _parity ) )
99+ return "N" ;
100+ // ‘n’ for none, ‘o’ for odd, ‘e’ for even, ‘m’ for mark and ‘s’ for space.
101+ //string[] ParityFlagCollection = new[] { "n", "o", "e", "m", "s" };
102+ return _parity [ 0 ] . ToString ( ) . ToUpper ( ) ;
103+ }
104+
105+
106+ public string [ ] FlowControlCollection => new [ ] { "NONE" , "XON/XOFF" , "RTS/CTS" , "DSR/DTR" } ;
107+ private string _flowControl = "XON/XOFF" ;
108+ public string FlowControl
109+ {
110+ get => _flowControl ;
111+ set => SetAndNotifyIfChanged ( ref _flowControl , value ) ;
112+ }
113+
114+ public string GetFlowControlFlag ( )
115+ {
116+ // ‘N’ for none, ‘X’ for XON/XOFF, ‘R’ for RTS/CTS and ‘D’ for DSR/DTR.
117+ if ( string . IsNullOrWhiteSpace ( _flowControl ) )
118+ return "N" ;
119+ return _flowControl [ 0 ] . ToString ( ) . ToUpper ( ) ;
120+ }
121+ // TODO 数据位、校验位、停止位
122+
69123 private string _startupAutoCommand = "" ;
70124 public string StartupAutoCommand
71125 {
@@ -86,9 +140,16 @@ public string ExternalKittySessionConfigPath
86140 public string GetExeArguments ( string sessionName )
87141 {
88142 // https://stackoverflow.com/questions/35411927/putty-command-line-automate-serial-commands-from-file
143+ // https://documentation.help/PuTTY/using-cmdline-sercfg.html
144+ // Any single digit from 5 to 9 sets the number of data bits.
145+ // ‘1’, ‘1.5’ or ‘2’ sets the number of stop bits.
146+ // Any other numeric string is interpreted as a baud rate.
147+ // A single lower-case letter specifies the parity: ‘n’ for none, ‘o’ for odd, ‘e’ for even, ‘m’ for mark and ‘s’ for space.
148+ // A single upper-case letter specifies the flow control: ‘N’ for none, ‘X’ for XON/XOFF, ‘R’ for RTS/CTS and ‘D’ for DSR/DTR.
149+ // For example, ‘-sercfg 19200,8,n,1,N’ denotes a baud rate of 19200, 8 data bits, no parity, 1 stop bit and no flow control.
89150 var serial = ( this . Clone ( ) as Serial ) ! ;
90151 serial . ConnectPreprocess ( ) ;
91- return $@ " -load ""{ sessionName } "" -serial { serial . SerialPort } -sercfg { serial . BitRate } ";
152+ return $@ " -load ""{ sessionName } "" -serial { serial . SerialPort } -sercfg { serial . BitRate } , { DataBits } , { GetParityFlag ( ) } , { StopBits } , { GetFlowControlFlag ( ) } ";
92153 }
93154 }
94155}
0 commit comments