@@ -19,20 +19,22 @@ internal class SilinkCli
1919 {
2020 private const int SilinkTelnetPort = 49000 ;
2121 private const int SilinkAdminPort = SilinkTelnetPort + 2 ;
22- private const int TargetBaudRate = 921600 ;
22+ private const int DefaultBaudRate = 921600 ;
2323
2424 /// <summary>
2525 /// This will set the baud rate of the VCP in a Silabs Jlink board.
2626 /// Before setting the value the devices is queried and the new setting is applied only if needed.
2727 /// </summary>
2828 /// <param name="probeId">Id of the JLink probe to adjust the baud rate.</param>
29+ /// <param name="baudRate">Value of baud rate to set.</param>
2930 /// <param name="verbosity">Verbosity level for the operation. <see cref="VerbosityLevel.Quiet"/> will be used if not specified.</param>
3031 /// <returns></returns>
3132 /// <remarks>
3233 /// Currently this operation is only supported in Windows machines.
3334 /// </remarks>
3435 public static ExitCodes SetVcpBaudRate (
3536 string probeId ,
37+ int baudRate ,
3638 VerbosityLevel verbosity = VerbosityLevel . Quiet )
3739 {
3840 // check that we can run on this platform
@@ -50,6 +52,9 @@ public static ExitCodes SetVcpBaudRate(
5052 return ExitCodes . E8002 ;
5153 }
5254
55+ // store baud rate value
56+ int targetBaudRate = baudRate == 0 ? DefaultBaudRate : baudRate ;
57+
5358 Console . ForegroundColor = ConsoleColor . White ;
5459
5560 // launch silink
@@ -101,12 +106,12 @@ public static ExitCodes SetVcpBaudRate(
101106 const string regexPattern = "(?:Stored port speed : )(?'baudrate'\\ d+)" ;
102107
103108 var myRegex1 = new Regex ( regexPattern , RegexOptions . Multiline ) ;
104- var currentBaud = myRegex1 . Match ( currentConfig ) ;
109+ var currentVcomConfig = myRegex1 . Match ( currentConfig ) ;
105110
106- if ( currentBaud . Success )
111+ if ( currentVcomConfig . Success )
107112 {
108113 // verify current setting
109- if ( int . TryParse ( currentBaud . Groups [ "baudrate " ] . Value , out int baudRate ) && baudRate == TargetBaudRate )
114+ if ( int . TryParse ( currentVcomConfig . Groups [ "baud rate " ] . Value , out int currentBaudRate ) && currentBaudRate == targetBaudRate )
110115 {
111116 if ( verbosity >= VerbosityLevel . Detailed )
112117 {
@@ -131,7 +136,7 @@ public static ExitCodes SetVcpBaudRate(
131136 Thread . Sleep ( 250 ) ;
132137
133138 // compose command
134- buffer = Encoding . Default . GetBytes ( $ "serial vcom config speed { TargetBaudRate } \r ") ;
139+ buffer = Encoding . Default . GetBytes ( $ "serial vcom config speed { targetBaudRate } \r ") ;
135140 silinkSocket . Send ( buffer ) ;
136141
137142 Thread . Sleep ( 250 ) ;
@@ -146,7 +151,7 @@ public static ExitCodes SetVcpBaudRate(
146151 Console . WriteLine ( $ "{ opResult } ") ;
147152 }
148153
149- if ( opResult . Contains ( $ "Baudrate set to { TargetBaudRate } bps") )
154+ if ( opResult . Contains ( $ "Baudrate set to { targetBaudRate } bps") )
150155 {
151156 if ( verbosity == VerbosityLevel . Normal )
152157 {
0 commit comments