@@ -61,6 +61,7 @@ public class ECUConnection
6161 public API ConnectionAPI ;
6262 public Device ConnectionDevice ;
6363 public Channel ConnectionChannel ;
64+ public string DriverPath = "" ;
6465
6566 public delegate void ConnectionStateChanged ( string newStateDescription ) ;
6667 public ConnectionStateChanged ConnectionStateChangeEvent ;
@@ -115,9 +116,11 @@ public ECUConnection()
115116
116117 public ECUConnection ( string fileName , string friendlyName )
117118 {
119+ DriverPath = fileName ;
120+
118121 // apparently AVDI embeds their hardware identifier in the device's name and path, which might be regarded as sensitive when sharing
119122 // this redacts it (somewhat) to help save some time for testers
120- if ( friendlyName . Contains ( "AVDI-PT" ) )
123+ if ( DriverIsAVDI ( ) )
121124 {
122125 FriendlyName = "AVDI-PT" ;
123126 Console . WriteLine ( $ "Initializing new connection to { friendlyName } ") ;
@@ -222,26 +225,46 @@ public ConnectResponse Connect(ECUInterfaceSubtype profile, ECU ecuContext)
222225 Console . WriteLine ( $ "Target voltage : { ConnectionChannel . MeasureBatteryVoltage ( ) } mV") ;
223226 ConnectionChannel . DefaultTxFlag = TxFlag . ISO15765_FRAME_PAD ;
224227
225- // this chunk is repeated twice, seems to be required for some j2534 devices, and doesn't harm preexisting, working devices
226228 J2534SetFilters ( profile ) ;
227229 J2534SetConfig ( profile ) ;
228230 J2534FlushBuffers ( ) ;
229231
230- J2534SetFilters ( profile ) ;
231- J2534SetConfig ( profile ) ;
232- J2534FlushBuffers ( ) ;
233232
234- State = ConnectionState . ChannelConnectedPendingEcuContact ;
235233 }
236234 catch ( Exception e )
237235 {
238- Console . WriteLine ( $ "{ e . Message } ") ;
236+ Console . WriteLine ( $ "Connection failed with exception : { e . Message } ") ;
239237 return ConnectResponse . FailedWithException ;
240238 }
239+
240+ // this chunk is repeated for AVDI devices; OpenPort2 does not care, Scanmatik refuses to continue if reconfigured without clearing prior filters
241+ // wrap the second attempt in a separate try block, so that we can suppress any potential filter errors
242+ if ( DriverIsAVDI ( ) )
243+ {
244+ try
245+ {
246+ ConnectionChannel . ClearMsgFilters ( ) ;
247+ J2534SetFilters ( profile ) ;
248+ J2534SetConfig ( profile ) ;
249+ J2534FlushBuffers ( ) ;
250+ }
251+ catch ( Exception ex )
252+ {
253+ Console . WriteLine ( $ "AVDI Second config exception suppressed: { ex . Message } ") ;
254+ }
255+ }
256+
257+ State = ConnectionState . ChannelConnectedPendingEcuContact ;
258+
241259 ConnectionUpdateState ( ) ;
242260 return ConnectResponse . OK ;
243261 }
244262
263+ public bool DriverIsAVDI ( )
264+ {
265+ return DriverPath . ToUpper ( ) . EndsWith ( "ABRPT32.DLL" ) ;
266+ }
267+
245268 public void J2534SetFilters ( ECUInterfaceSubtype profile )
246269 {
247270 // setup ecu filter (mimicking vediamo's behavior)
@@ -256,7 +279,6 @@ public void J2534SetFilters(ECUInterfaceSubtype profile)
256279 MessageFilter filter = new MessageFilter ( ) ;
257280
258281 // Apparently in the EIS series, the RX identifier is !! NOT !! CanIdentifier+8 per ISO15765, so the automatic config in J2534-Sharp will fail
259- //filter.StandardISO15765(CanIdentifier);
260282
261283 // manually configure a ISO15765 filter
262284 filter . FilterType = Filter . FLOW_CONTROL_FILTER ;
@@ -368,6 +390,7 @@ public byte[] SendMessage(IEnumerable<byte> message, bool quiet = false)
368390 }
369391
370392 GetMessageResults readResult = ConnectionChannel . GetMessage ( ) ;
393+
371394 if ( readResult . Result == ResultCode . STATUS_NOERROR )
372395 {
373396 foreach ( Message row in readResult . Messages )
0 commit comments