'=↓=↓=↓= MW3 Header Start =↓=↓=↓=↓=↓=↓=↓=↓=↓=↓=↓=↓=[MWTAG1] ' Script Type: MacroWorks 3 Device Script ' Device Name: RailDriver ' Device Description: RailDriver ' Script Name: RailDriver ' Script Description: Macros for RailDriver ' PID: 210 ' Firmware: ' MW3 Version: ' Script Language: Visual Basic ' Script Template: Beta 1.0 ' Format: Unicode 8 ' P.I. Engineering, Inc. ' "The No Slogan Company" ' Williamston, Michigan, USA ' www.xkeys.com ' Start Date: 12-15-09, 6:43: 34 AM ' Last Update: 12-15-09, 6:43: 34 AM ' Config Path: RailDriver\ReportConfig_RailDriver.xml [MWTAG18] ' Default Mode: Software ' Last Update: 23.12.2015 13:27:26 [MWTAG21] ' Start Date: 09.10.2015 12:53:49 [MWTAG20] '=↑=↑=↑= MW3 Header End =↑=↑=↑=↑=↑=↑=↑=↑=↑=↑=↑=↑=[/MWTAG1] Imports Microsoft.VisualBasic Imports System Imports System.Collections.Generic Imports System.Collections.ArrayList Imports System.Runtime.InteropServices 'for dll import Imports Microsoft.Win32 Public Class Script Implements Interfaces.IScript '[MWTAG12] 'Initialize Variables Start [MWTAG3] Dim MW3 As Interfaces.MW3 Dim MyDevice As Integer() = {210, -1, 53} 'Device Descriptor [MWTAG8] Dim AppName As String = "" 'Active application name Dim AppTitle As String = "" 'Active application title Dim GUIState As Boolean = false 'RailDriver.dll import Const dllname As String="RailDriver.dll" _ Private Shared Sub SetRailDriverConnected(ByVal isConnected As Boolean) End Sub _ Private Shared Function GetRailSimConnected() As Boolean End Function _ Private Shared Sub SetRailSimValue(ByVal controlID As Integer, ByVal value As Single) End Sub _ Private Shared Function GetRailSimValue(ByVal controlID As Integer, ByVal type As Integer) As Single End Function _ Private Shared Function GetRailSimLocoChanged() As Boolean End Function _ Private Shared Function GetLocoName() As String End Function _ Private Shared Function GetControllerList() As String End Function _ Private Shared Function GetControllerValue(ByVal controlID As Integer, ByVal type As Integer) As Single End Function _ Private Shared Sub SetControllerValue(ByVal controlID As Integer, ByVal value As Single) End Sub 'My RailDriver variables, see timer1_Tick for assignment when new loco detected 'make variables, -1 if controller doesn't exist on the current loco Dim REVERSER_ID As Integer = -1 'analog Dim THROTTLE_ID As Integer = -1 'analog - VirtualThrottle Dim COMBINED_THROTTLE_BRAKE_ID As Integer = -1 'analog - ThrottleAndBrake Dim SIMPLE_THROTTLE_ID As Integer = -1 'SimpleThrottle Dim SIMPLE_CHANGE_DIRECTION_ID As Integer = -1 'SimpleChangeDirection Dim REGULATOR_ID As Integer = -1 'Regulator Dim TRAIN_BRAKE_ID As Integer = -1 'analog Dim LOCOMOTIVE_BRAKE_ID As Integer = -1 'analog Dim DYNAMIC_BRAKE_ID As Integer = -1 'analog Dim EMERGENCY_BRAKE_ID As Integer = -1 Dim HANDBRAKE_ID As Integer = -1 Dim HORN_ID As Integer = -1 '0 off, 1 on Dim BELL_ID As Integer = -1 '0 off, 1 on Dim WIPERS_ID As Integer = -1 'toggle 1 on, 1 off Dim SANDER_ID As Integer = -1 Dim HEADLIGHTS_ID As Integer = -1 'toggle Dim PANTOGRAPH_ID As Integer = -1 'toggle Dim FIREBOX_DOOR_ID As Integer = -1 'toggle Dim EXHAUST_INJECTOR_STEAM_ID As Integer = -1 'toggle Dim EXHAUST_INJECTOR_WATER_ID As Integer = -1 'toggle Dim LIVE_INJECTOR_STEAM_ID As Integer = -1 'toggle Dim LIVE_INJECTOR_WATER_ID As Integer = -1 'toggle Dim DAMPER_ID As Integer = -1 'toggle Dim BLOWER_ID As Integer = -1 'toggle Dim STOKING_ID As Integer = -1 'toggle Dim CYLINDER_COCK_ID As Integer = -1 'toggle Dim WATERSCOOP_ID As Integer = -1 'toggle Dim SMALL_COMPRESSOR_ID As Integer = -1 Dim AWS_ID As Integer = -1 Dim AWS_RESET_ID As Integer = -1 Dim DSD_RESET_ID As Integer = -1 Dim SPEEDOMETER_ID As Integer = -1 'MPH Dim SPEEDOMETERKPH_ID As Integer = -1 'KPH Dim AMMETER_ID As Integer=-1 Dim BRAKEPIPEPRESSUREBAR_ID As Integer=-1 Dim BOILERPRESSUREPSI_ID As Integer=-1 Dim RPM_ID As Integer=-1 'add more if desired for example 'Dim TRACTIVEEFFORT_ID As Integer=-1 'Hardcoded controls, these are same for all locos Dim LATITUDE_OF_TRAIN_ID As Integer=400 Dim LONGITUDE_OF_TRAIN_ID As Integer=401 Dim FUEL_LEVEL_ID As Integer=402 Dim TUNNEL_ID As Integer=403 'is in a tunnel Dim GRADIENT_ID As Integer=404 Dim HEADING_ID As Integer=405 Dim TIME_OF_DAY_HRS_ID As Integer=406 Dim TIME_OF_DAY_MIN_ID As Integer=407 Dim TIME_OF_DAY_SEC_ID As Integer=408 'for old trains Enum eRailSimControlID REVERSER_ID = 0 'analog THROTTLE_ID = 1 'analog COMBINED_THROTTLE_BRAKE_ID = 2 'analog GEAR_LEVER_ID = 3 TRAIN_BRAKE_ID = 4 'analog LOCOMOTIVE_BRAKE_ID = 5 'analog DYNAMIC_BRAKE_ID = 6 'analog EMERGENCY_BRAKE_ID = 7 HANDBRAKE_ID = 8 WARNING_SYSTEM_RESET_ID = 9 START_SHUTDOWN_ENGINE_ID = 10 HORN_ID = 11 '0 off, 1 on WIPERS_ID = 12 'toggle 1 on, 1 off SANDER_ID = 13 HEADLIGHTS_ID = 14 'toggle PANTOGRAPH_ID = 15 'toggle FIREBOX_DOOR_ID = 16 'toggle EXHAUST_INJECTOR_STEAM_ID = 17 'toggle EXHAUST_INJECTOR_WATER_ID = 18 'toggle LIVE_INJECTOR_STEAM_ID = 19 'toggle LIVE_INJECTOR_WATER_ID = 20 'toggle DAMPER_ID = 21 'toggle BLOWER_ID = 22 'toggle STOKING_ID = 23 'toggle CYLINDER_COCK_ID = 24 'toggle WATERSCOOP_ID = 25 'toggle SMALL_COMPRESSOR_ID = 26 AWS_ID = 27 AWS_RESET_ID = 28 STARTUP_ID = 29 'toggle SPEEDOMETER_ID = 30 PROMPT_SAVE_ID = 31 TOGGLE_LABELS_ID = 32 'toggle TOGGLE_2D_MAP_ID = 33 'toggle TOGGLE_HUD_ID = 34 TOGGLE_QUIT_ID = 35 PAUSE_ID = 36 DRIVER_GUIDE_ID = 37 TOGGLE_RV_NUMBER_ID = 38 DIALOG_ASSIGNMENT_ID = 39 'toggle SWITCH_JUNCTION_AHEAD_ID = 40 'toggle SWITCH_JUNCTION_BEHIND_ID = 41 'toggle LOAD_CARGO_ID = 42 UNLOAD_CARGO_ID = 43 PASS_AT_DANGER_AHEAD_ID = 44 PASS_AT_DANGER_BEHIND_ID = 45 MANUAL_COUPLE_ID = 46 ActivateCabCamera_ID = 47 ActivateFollowCamera_ID = 48 ActivateHeadOutCamera_ID = 49 ActivateRearCamera_ID = 50 ActivateTrackSideCamera_ID = 51 ActivateCarriageCamera_ID = 52 ActivateCouplingCamera_ID = 53 ActivateYardCamera_ID = 54 SwitchToNextFrontCab_ID = 55 SwitchToNextRearCab_ID = 56 ActivateFreeCam_ID = 57 End Enum Dim railsimconnected As Boolean Dim loconame As String '5/1/15 Dim controllerlist As String() = Nothing Public Structure POSITION Public min As Integer 'contains the actual min value obtained for this position during calibration, read directly from cal file Public max As Integer 'contains the actual max value obtained for this position during calibration, read directly from cal file Public upperthreshold As Integer 'contains the upper threshold for this position Public lowerthreshold As Integer 'contains the lower threshold for this position End Structure Public Structure CAL_DATA Public LastValue As Integer 'holds the last value sent, used to compare if significant change in current analog value from last send Public Sensitivity As Integer 'change of analog must be greater than this to be considered a significant change, ie not "chatter" Public position() As POSITION 'position lever was in for calibration, each lever has at least 2 positions and up to 4 Public slope() As Single 'for each "segment" on an analog maps the RailDriver cal values to the RailSim cal values using y=mx+b where m is slope and b is intercept, not applicable to rotary switches Public intercept() As Single 'for each "segment" on an analog maps the RailDriver cal values to the RailSim cal values using y=mx+b where m is slope and b is intercept, not applicable to rotary switches Public islope() As Single 'for each "segment" on an analog maps the RailDriver cal values to the INVERSE RailSim cal values using y=mx+b where m is slope and b is intercept, not applicable to rotary switches Public iintercept() As Single 'for each "segment" on an analog maps the RailDriver cal values to the INVERSE RailSim cal values using y=mx+b where m is slope and b is intercept, not applicable to rotary switches End Structure Dim lever As CAL_DATA() = New CAL_DATA(6) {} Dim lastrp1 As Integer = -1 'last position for rotary switch 1 (0, 1 or 2) Dim lastrp2 As Integer = -1 'last position for rotary switch 2 (0, 1 or 2) Dim thisrp As Integer=-1 'RailSim "calibrations" Dim RailSimReverserMin As Single Dim RailSimReverserMax As Single Dim RailSimReverserN As Single 'computed center from min and max Dim RailSimThrottleMin As Single Dim RailSimThrottleMax As Single Dim RailSimCombinedThrottleBrakeMin As Single Dim RailSimCombinedThrottleBrakeMax As Single Dim RailSimCombinedThrottleBrakeN As Single 'computed center from min and max Dim RailSimTrainBrakeMin As Single Dim RailSimTrainBrakeMax As Single Dim RailSimLocoBrakeMin As Single Dim RailSimLocoBrakeMax As Single Dim RailSimDynamicBrakeMin As Single Dim RailSimDynamicBrakeMax As Single Dim ThrottleStyle As Integer '0=just throttle as listed, 1=throttle/train brake, 2=throttle/dynamic brake, 3=all throttle Dim onetime As Boolean=true Dim timer1 As New System.Windows.Forms.Timer() 'used to see if trains have been changed Dim timer2 As New System.Windows.Forms.Timer() 'used for checking the existence of the cal file Dim appactive As Boolean=true 'is RailWorksProc2 the active app Dim lastspeed As String="" 'the last speed written out to display Dim ToDigits() As Integer = {63, 6, 91, 79, 102, 109, 125, 7, 127, 111} 'for speed display Dim speedunit As Boolean 'false=mph, true=kph Dim result As Integer 'for msgbox returns 'Initialize Varibles End [/MWTAG3] Public Sub Initialize(MW3 As Interfaces.MW3) Implements Interfaces.IScript.Initialize Me.MW3 = MW3 ReadCalData() Dim dllpaths As String() = {"f:\Steam\SteamApps\common\RailWorks\plugins\", "f:\Steam\SteamApps\common\RailWorks\plugins\"} 'locations of the RailDriver.dll MW3.AddDLLpaths(dllpaths) SetRailDriverConnected(true) loconame="" timer1.Dispose() AddHandler timer1.Tick, AddressOf timer1_Tick timer1.Interval = 100 timer1.Enabled = True End Sub Public Sub ScriptLoad() Implements Interfaces.IScript.ScriptLoad End Sub Public Function ScriptUnload() As Boolean Implements Interfaces.IScript.ScriptUnload End Function Public Sub SysPowerChange(PowerState As Byte) Implements Interfaces.IScript.SysPowerChange End Sub Public Sub ActiveAppChange(ActiveAppTitle As String, ActiveAppName As String) Implements Interfaces.IScript.ActiveAppChange AppName= ActiveAppName AppTitle= ActiveAppTitle appactive=true Dim OutputReport() as Byte = {0,133,0,0,0,0,0,1,0} MW3.SendGenericOutput(MyDevice,OutputReport) End Sub Public Sub DeviceChange(DevInfo As Integer(), plugged As Boolean) Implements Interfaces.IScript.DeviceChange End Sub Public Sub Initializing() Implements Interfaces.IScript.Initializing End Sub 'Digital State Change Event Start [MWTAG4] Public Sub XKEvent(CID As Integer, State As Boolean, Repeat As Integer, TimeStamp as Long, MessageData As Integer) Implements Interfaces.IScript.XKEvent Select Case CID 'Button Check Start [MWTAG9] Case 1001 'Button 001 If State 'Pressed [MWTAG10] '↓7↓]> MW3.sendScanCode("42:1,8:1") '↓7↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("8:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1002 'Button 002 If State 'Pressed [MWTAG10] '↓8↓]> MW3.sendScanCode("42:1,9:1") '↓8↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("9:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1003 'Button 003 If State 'Pressed [MWTAG10] '↓8↓]> MW3.sendScanCode("29:1,9:1") '↓8↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("9:0,29:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1004 'Button 004 If State 'Pressed [MWTAG10] '↓6↓]> MW3.sendScanCode("42:1,7:1") '↓6↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("7:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1005 'Button 005 If State 'Pressed [MWTAG10] '↓f↓]> MW3.sendScanCode("42:1,33:1") '↓f↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("33:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1006 'Button 006 If State 'Pressed [MWTAG10] '↓p↓]> MW3.sendScanCode("42:1,25:1") '↓p↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("25:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1007 'Button 007 If State 'Pressed [MWTAG10] '↓b↓]> MW3.sendScanCode("42:1,48:1") '↓b↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("48:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1008 'Button 008 If State 'Pressed [MWTAG10] '↓ö↓]> MW3.sendScanCode("42:1,39:1") '↓ö↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("39:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1009 'Button 009 If State 'Pressed [MWTAG10] '↓w↓]> MW3.sendScanCode("42:1,17:1") '↓w↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("17:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1010 'Button 010 If State 'Pressed [MWTAG10] '↓9↓]> MW3.sendScanCode("42:1,10:1") '↓9↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("10:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1011 'Button 011 If State 'Pressed [MWTAG10] ' MW3.sendScanCode("11:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("11:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1012 'Button 012 If State 'Pressed [MWTAG10] '↓p↓]> MW3.sendScanCode("29:1,42:1,25:1") '↓p↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("25:0,42:0,29:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1013 'Button 013 If State 'Pressed [MWTAG10] Else 'Released [MWTAG11] End If 'Press-Release [/MWTAG10/MWTAG11] Case 1014 'Button 014 If State 'Pressed [MWTAG10] '↓t↓]> MW3.sendScanCode("42:1,20:1") '↓t↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("20:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1015 'Button 015 If State 'Pressed [MWTAG10] '↓]> MW3.sendScanCode("339:1") '↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("339:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1016 'Button 016 If State 'Pressed [MWTAG10] '↓]> MW3.sendScanCode("335:1") '↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("335:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1017 'Button 017 If State 'Pressed [MWTAG10] '↓]> MW3.sendScanCode("337:1") '↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("337:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1018 'Button 018 If State 'Pressed [MWTAG10] '↓a↓]> MW3.sendScanCode("42:1,30:1") '↓a↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("30:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1019 'Button 019 If State 'Pressed [MWTAG10] '↓f↓]> MW3.sendScanCode("29:1,33:1") '↓f↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("33:0,29:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1020 'Button 020 If State 'Pressed [MWTAG10] '↓p↓]> MW3.sendScanCode("29:1,25:1") '↓p↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("25:0,29:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1021 'Button 021 If State 'Pressed [MWTAG10] ' MW3.sendScanCode("43:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("43:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1022 'Button 022 If State 'Pressed [MWTAG10] '↓l↓]> MW3.sendScanCode("42:1,38:1") '↓l↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("38:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1023 'Button 023 If State 'Pressed [MWTAG10] ' MW3.sendScanCode("38:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("38:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1024 'Button 024 If State 'Pressed [MWTAG10] ' MW3.sendScanCode("46:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("46:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1025 'Button 025 If State 'Pressed [MWTAG10] '↓0↓]> MW3.sendScanCode("42:1,11:1") '↓0↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("11:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1026 'Button 026 If State 'Pressed [MWTAG10] '↓b↓]> MW3.sendScanCode("29:1,42:1,48:1") '↓b↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("48:0,42:0,29:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1027 'Button 027 If State 'Pressed [MWTAG10] Else 'Released [MWTAG11] End If 'Press-Release [/MWTAG10/MWTAG11] Case 1028 'Button 028 If State 'Pressed [MWTAG10] ' MW3.sendScanCode("20:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("20:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1029 'Rocker Up If State 'Pressed [MWTAG10] ' MW3.sendScanCode("2:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("2:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1030 'Rocker Down If State 'Pressed [MWTAG10] ' MW3.sendScanCode("2:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("2:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1031 'Pad Up If State 'Pressed [MWTAG10] '↓2↓]> MW3.sendScanCode("42:1,3:1") '↓2↓]> Else 'Released [MWTAG11] '↑2↑]> MW3.sendScanCode("42:0,3:0") '↑2↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1032 'Pad Right If State 'Pressed [MWTAG10] '↓]> MW3.sendScanCode("333:1") '↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("333:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1033 'Pad Down If State 'Pressed [MWTAG10] ' MW3.sendScanCode("2:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("2:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1034 'Pad Left If State 'Pressed [MWTAG10] '↓]> MW3.sendScanCode("331:1") '↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("331:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1035 'Range Up If State 'Pressed [MWTAG10] ' MW3.sendScanCode("44:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("44:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1036 'Range Down If State 'Pressed [MWTAG10] '↓y↓]> MW3.sendScanCode("42:1,44:1") '↓y↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("44:0,42:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1037 'E-Stop Up If State 'Pressed [MWTAG10] ' MW3.sendScanCode("23:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("23:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1038 'E-Stop Down If State 'Pressed [MWTAG10] ' MW3.sendScanCode("21:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("21:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1039 'Alerter If State 'Pressed [MWTAG10] '↓]> MW3.sendScanCode("57:1") '↓]> Else 'Released [MWTAG11] '↑]> MW3.sendScanCode("57:0") '↑]> End If 'Press-Release [/MWTAG10/MWTAG11] Case 1040 'Sand If State 'Pressed [MWTAG10] ' MW3.sendScanCode("45:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("45:0") ' End If 'Press-Release [/MWTAG10/MWTAG11]ü Case 1041 'P If State 'Pressed [MWTAG10] ' MW3.sendScanCode("25:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("25:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1042 'Bell If State 'Pressed [MWTAG10] ' MW3.sendScanCode("49:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("49:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1043 'Whistle Up If State 'Pressed [MWTAG10] ' MW3.sendScanCode("48:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("48:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] Case 1044 'Whistle Down If State 'Pressed [MWTAG10] ' MW3.sendScanCode("48:1") ' Else 'Released [MWTAG11] ' MW3.sendScanCode("48:0") ' End If 'Press-Release [/MWTAG10/MWTAG11] End Select 'Button Check End [/MWTAG9] End Sub 'Digital State Change Event End [/MWTAG4] 'String Data Received Event Start [MWTAG6] Public Sub XKStringEvent(CID As Integer, StringData As String, Repeat As Integer, TimeStamp as Long, MessageData As Integer) Implements Interfaces.IScript.XKStringEvent Select Case CID 'String Data Check Start [MWTAG14] End Select 'String Data Check End [/MWTAG14] End Sub 'String Data Received Event End [/MWTAG6] 'Analog Data Received Event Start [MWTAG7] Public Sub XKAnalogEvent(CID As Integer, AnalogValue As Integer(), Repeat As Integer, TimeStamp as Long, MessageData As Integer) Implements Interfaces.IScript.XKAnalogEvent If (appactive=false) Then Return Select Case CID 'Analog Check Start [MWTAG13] Case 2001 'Reverser Dim tmax As Integer=lever(0).position(0).max+lever(0).position(0).upperthreshold Dim tmin As Integer=lever(0).position(2).min-lever(0).position(2).lowerthreshold 'ignore out of range vals If (AnalogValue(0)tmin) 'now check for significant change If (AnalogValue(0)>(lever(0).LastValue+lever(0).Sensitivity) Or AnalogValue(0)<(lever(0).LastValue-lever(0).Sensitivity)) Dim maxreverser As Integer=lever(0).position(0).min-lever(0).position(0).lowerthreshold Dim minreverser As Integer=lever(0).position(2).max+lever(0).position(2).upperthreshold Dim maxneutral As Integer=lever(0).position(1).max+lever(0).position(1).upperthreshold Dim minneutral As Integer=lever(0).position(1).min-lever(0).position(1).lowerthreshold Dim invert As Boolean=false 'change to true to invert the lever Dim railsimmin As Single=RailSimReverserMin Dim railsimmax As Single=RailSimReverserMax Dim m As Single =lever(0).slope(0) Dim b As Single =lever(0).intercept(0) Dim m1 As Single =lever(0).slope(1) Dim b1 As Single =lever(0).intercept(1) If (invert=true) Then railsimmin=RailSimReverserMax railsimmax=RailSimReverserMin m=lever(0).islope(0) b=lever(0).iintercept(0) m1=lever(0).islope(1) b1=lever(0).iintercept(1) End If 'now find segment If (AnalogValue(0)>=maxreverser) Then 'full reversed TS_SetControllerValue(REVERSER_ID, railsimmin) Else If (AnalogValue(0)<=minreverser) Then 'full forward TS_SetControllerValue(REVERSER_ID, railsimmax) Else If (AnalogValue(0)maxneutral) Then 'between full reversed and neutral Dim sendval As Single=(m*AnalogValue(0))+b TS_SetControllerValue(REVERSER_ID, sendval) Else If (AnalogValue(0)>minreverser And AnalogValue(0)tmin) 'now check for significant change If (AnalogValue(0)>(lever(1).LastValue+lever(1).Sensitivity) Or AnalogValue(0)<(lever(1).LastValue-lever(1).Sensitivity)) Dim maxthrottle As Integer=lever(1).position(0).min-lever(1).position(0).lowerthreshold Dim minthrottle As Integer=lever(1).position(1).max+lever(1).position(1).upperthreshold Dim maxbrake As Integer=lever(1).position(2).max+lever(1).position(2).upperthreshold Dim minbrake As Integer=lever(1).position(3).min-lever(1).position(3).lowerthreshold Dim invert As Boolean=true 'change to true to invert the lever, change below within individual cases Dim railsimmin As Single Dim railsimmax As Single Dim m As Single Dim b As Single Dim m1 As Single Dim b1 As Single Select Case ThrottleStyle Case 0 'throttle as labeled on RD (throttle on bottom half) railsimmin =RailSimThrottleMin railsimmax =RailSimThrottleMax m =lever(1).slope(0) b =lever(1).intercept(0) invert=true 'change to true to invert If (invert=true) Then railsimmin=RailSimThrottleMax railsimmax=RailSimThrottleMin m=lever(1).islope(1) b=lever(1).iintercept(1) End If 'now find segment If (AnalogValue(0)>=maxthrottle) Then 'full throttle TS_SetControllerValue(THROTTLE_ID, railsimmax) Else If (AnalogValue(0)minthrottle) Then 'between full throttle and idle Dim sendval As Single=m*AnalogValue(0)+b TS_SetControllerValue(THROTTLE_ID, sendval) Else 'idle TS_SetControllerValue(THROTTLE_ID, railsimmin) End If lever(1).LastValue=AnalogValue(0) Case 1 'throttle/train brake railsimmin =RailSimCombinedThrottleBrakeMin '0=max brake railsimmax =RailSimCombinedThrottleBrakeMax '1=max throttle m =lever(1).slope(0) b =lever(1).intercept(0) m1 =lever(1).slope(1) b1 =lever(1).intercept(1) invert=true 'change to true to invert If (invert=true) Then railsimmin=RailSimCombinedThrottleBrakeMax railsimmax=RailSimCombinedThrottleBrakeMin m=lever(1).islope(0) b=lever(1).iintercept(0) m1=lever(1).islope(1) b1=lever(1).iintercept(1) End If 'now find segment If (AnalogValue(0)>=maxthrottle) Then 'full throttle TS_SetControllerValue(COMBINED_THROTTLE_BRAKE_ID, railsimmax) Else If (AnalogValue(0)minthrottle) Then 'between full throttle and idle Dim sendval As Single=m*AnalogValue(0)+b TS_SetControllerValue(COMBINED_THROTTLE_BRAKE_ID, sendval) Else If (AnalogValue(0)<=maxbrake) 'full brake TS_SetControllerValue(COMBINED_THROTTLE_BRAKE_ID, railsimmin) Else If (AnalogValue(0)>maxbrake And AnalogValue(0)=maxthrottle) Then 'full throttle TS_SetControllerValue(THROTTLE_ID, RailSimThrottleMax) Else If (AnalogValue(0)minthrottle) Then 'between full throttle and idle Dim sendval As Single=lever(1).slope(0)*AnalogValue(0)+lever(1).intercept(0) TS_SetControllerValue(THROTTLE_ID, sendval) Else If (AnalogValue(0)<=maxbrake) 'full brake TS_SetControllerValue(DYNAMIC_BRAKE_ID, RailSimDynamicBrakeMax) Else If (AnalogValue(0)>maxbrake And AnalogValue(0)=maxthrottle) Then 'full brake now TS_SetControllerValue(DYNAMIC_BRAKE_ID, RailSimDynamicBrakeMax) Else If (AnalogValue(0)minthrottle) Then 'between full throttle and idle Dim sendval As Single=lever(1).islope(0)*AnalogValue(0)+lever(1).iintercept(0) TS_SetControllerValue(DYNAMIC_BRAKE_ID, sendval) Else If (AnalogValue(0)<=maxbrake) 'full throttle now TS_SetControllerValue(THROTTLE_ID, RailSimThrottleMax) Else If (AnalogValue(0)>maxbrake And AnalogValue(0)= 0) And (sendval <= 1) Then TS_SetControllerValue(THROTTLE_ID, 0) Else If (sendval > 1) And (sendval <= 2) Then TS_SetControllerValue(THROTTLE_ID, 1) Else If (sendval > 2) And (sendval <= 3) Then TS_SetControllerValue(THROTTLE_ID, 2) Else If (sendval > 3) And (sendval <= 4) Then TS_SetControllerValue(THROTTLE_ID, 3) Else If (sendval > 4) And (sendval <= 5) Then TS_SetControllerValue(THROTTLE_ID, 4) Else If (sendval > 5) And (sendval <= 6) Then TS_SetControllerValue(THROTTLE_ID, 5) Else If (sendval > 6) And (sendval <= 7) Then TS_SetControllerValue(THROTTLE_ID, 6) Else If (sendval > 7) And (sendval <= 8) Then TS_SetControllerValue(THROTTLE_ID, 7) Else If (sendval > 8) And (sendval <= 9) Then TS_SetControllerValue(THROTTLE_ID, 8) Else If (sendval > 9) And (sendval <= 10) Then TS_SetControllerValue(THROTTLE_ID, 9) Else If (sendval > 10) And (sendval <= 11) Then TS_SetControllerValue(THROTTLE_ID, 10) Else If (sendval > 11) And (sendval <= 12) Then TS_SetControllerValue(THROTTLE_ID, 11) Else If (sendval > 12) And (sendval <= 13) Then TS_SetControllerValue(THROTTLE_ID, 12) Else If (sendval > 13) And (sendval <= 14) Then TS_SetControllerValue(THROTTLE_ID, 13) Else If (sendval > 14) And (sendval <= 15) Then TS_SetControllerValue(THROTTLE_ID, 14) Else If (sendval > 15) And (sendval <= 16) Then TS_SetControllerValue(THROTTLE_ID, 15) Else If (sendval > 16) And (sendval <= 17) Then TS_SetControllerValue(THROTTLE_ID, 16) Else If (sendval > 17) And (sendval <= 18) Then TS_SetControllerValue(THROTTLE_ID, 17) Else If (sendval > 18) And (sendval <= 19) Then TS_SetControllerValue(THROTTLE_ID, 18) Else If (sendval > 19) And (sendval <= 20) Then TS_SetControllerValue(THROTTLE_ID, 19) Else If (sendval > 20) And (sendval <= 21) Then TS_SetControllerValue(THROTTLE_ID, 20) Else If (sendval > 21) And (sendval <= 22) Then TS_SetControllerValue(THROTTLE_ID, 21) Else If (sendval > 22) And (sendval <= 23) Then TS_SetControllerValue(THROTTLE_ID, 22) Else If (sendval > 23) And (sendval <= 24) Then TS_SetControllerValue(THROTTLE_ID, 23) Else If (sendval > 24) And (sendval <= 25) Then TS_SetControllerValue(THROTTLE_ID, 24) Else If (sendval > 25) And (sendval <= 26) Then TS_SetControllerValue(THROTTLE_ID, 25) Else If (sendval > 26) And (sendval <= 27) Then TS_SetControllerValue(THROTTLE_ID, 26) Else If (sendval > 27) And (sendval <= 28) Then TS_SetControllerValue(THROTTLE_ID, 27) Else If (sendval > 28) And (sendval <= 29) Then TS_SetControllerValue(THROTTLE_ID, 28) End If lever(1).LastValue=AnalogValue(0) End Select End If End If Exit Select Case 2003 'Train or Auto Brake Dim maxt As Integer=lever(2).position(0).max+lever(2).position(0).upperthreshold Dim mint As Integer=lever(2).position(2).min-lever(2).position(2).lowerthreshold 'ignore out of range vals If (AnalogValue(0)mint) Then 'now check for significant change If (AnalogValue(0)>(lever(2).LastValue+lever(2).Sensitivity) Or AnalogValue(0)<(lever(2).LastValue-lever(2).Sensitivity)) Dim minbrake As Integer=lever(2).position(0).min-lever(2).position(0).lowerthreshold Dim maxbrake As Integer=lever(2).position(2).max+lever(2).position(2).upperthreshold Dim invert As Boolean=false 'change to true to invert the lever Dim railsimmin As Single=RailSimTrainBrakeMin Dim railsimmax As Single=RailSimTrainBrakeMax Dim m As Single=lever(2).slope(0) Dim b As Single=lever(2).intercept(0) If (invert=true) Then railsimmin=RailSimTrainBrakeMax railsimmax=RailSimTrainBrakeMin m=lever(2).islope(0) b=lever(2).iintercept(0) End If If (AnalogValue(0)>=minbrake) Then 'no brake TS_SetControllerValue(TRAIN_BRAKE_ID, 0) Else If (AnalogValue(0)<=maxbrake) Then 'full brake (Emergency) TS_SetControllerValue(TRAIN_BRAKE_ID, railsimmax) Else 'in between Dim sendval As Single=(m*AnalogValue(0))+b If (sendval < 0) TS_SetControllerValue(TRAIN_BRAKE_ID, 0) Else TS_SetControllerValue(TRAIN_BRAKE_ID, sendval) End If End If lever(2).LastValue=AnalogValue(0) End If End If Exit Select Case 2004 'Engine Brake (Independent Brake / Locomotive Brake) If (lever(3).slope(0)<>0) Then Dim maxt As Integer=lever(3).position(0).max+lever(3).position(0).upperthreshold Dim mint As Integer=lever(3).position(1).min-lever(3).position(1).lowerthreshold 'ignore out of range vals If (AnalogValue(0)mint) Then 'now check for significant change If (AnalogValue(0)>(lever(3).LastValue+lever(3).Sensitivity) Or AnalogValue(0)<(lever(3).LastValue-lever(3).Sensitivity)) Dim minbrake As Integer=lever(3).position(0).min-lever(3).position(0).lowerthreshold Dim maxbrake As Integer=lever(3).position(1).max+lever(3).position(1).upperthreshold Dim invert As Boolean=false 'change to true to invert the lever Dim railsimmin As Single=RailSimLocoBrakeMin Dim railsimmax As Single=RailSimLocoBrakeMax Dim m As Single=lever(3).slope(0) Dim b As Single=lever(3).intercept(0) If (invert=true) Then railsimmin=RailSimLocoBrakeMax railsimmax=RailSimLocoBrakeMin m=lever(3).islope(0) b=lever(3).iintercept(0) End If If (AnalogValue(0)>=minbrake) Then 'no brake TS_SetControllerValue(LOCOMOTIVE_BRAKE_ID, railsimmin) Else If (AnalogValue(0)<=maxbrake) Then 'full brake TS_SetControllerValue(LOCOMOTIVE_BRAKE_ID, railsimmax) Else 'in between Dim sendval As Single=(m*AnalogValue(0))+b TS_SetControllerValue(LOCOMOTIVE_BRAKE_ID, sendval) End If lever(3).LastValue=AnalogValue(0) End If End If End If Exit Select Case 2005 'Bail Off If (AnalogValue(0)>lever(4).position(0).min-lever(4).position(0).lowerthreshold) Then 'bailing off MW3.sendScanCode("26:1") Else 'not bailing off MW3.sendScanCode("26:0") End If Exit Select Case 2006 '3 Position Rotary Switch 1 If (AnalogValue(0)<>lever(5).LastValue) Then 'Method 1 - SetControllerValue, currently not working on all locomotives 5/11/15 REM If (AnalogValue(0)<(lever(5).position(0).max+lever(5).position(0).upperthreshold)) Then REM If (lastrp1<>0) Then REM TS_SetControllerValue(WIPERS_ID, 0) 'turn off wipers REM lastrp1=0 REM End If REM Else If ((AnalogValue(0)>(lever(5).position(1).min-lever(5).position(1).lowerthreshold)) And (AnalogValue(0)<(lever(5).position(1).max+lever(5).position(1).upperthreshold))) Then REM If (lastrp1<>1) Then REM TS_SetControllerValue(WIPERS_ID, 1) 'turn on wipers at 1, eventually the middle val REM lastrp1=1 REM End If REM Else If ((AnalogValue(0)>(lever(5).position(2).min-lever(5).position(2).lowerthreshold)) And (AnalogValue(0)<(lever(5).position(2).max+lever(5).position(2).upperthreshold))) Then REM If (lastrp1<>2) Then REM TS_SetControllerValue(WIPERS_ID, 2) 'turn on wipers at 2, eventually at max REM lastrp1=2 REM End If REM End If 'Method 2 - using v keystroke If (AnalogValue(0)<(lever(5).position(0).max+lever(5).position(0).upperthreshold)) Then If (lastrp1<>0) Then If (lastrp1=1) Then 'if moving from pos2 to pos1 '↑]> MW3.sendScanCode("47:1,47:0") '↑]> End If lastrp1=0 End If Else If ((AnalogValue(0)>(lever(5).position(1).min-lever(5).position(1).lowerthreshold)) And (AnalogValue(0)<(lever(5).position(1).max+lever(5).position(1).upperthreshold))) Then If (lastrp1<>1) Then If (lastrp1=0) Then 'if moving from pos1 to pos2 '↑]> MW3.sendScanCode("47:1,47:0") '↑]> End If lastrp1=1 End If Else If ((AnalogValue(0)>(lever(5).position(2).min-lever(5).position(2).lowerthreshold)) And (AnalogValue(0)<(lever(5).position(2).max+lever(5).position(2).upperthreshold))) Then If (lastrp1<>2) Then 'does nothing here, only 2 positions lastrp1=2 End If End If End If lever(5).LastValue=AnalogValue(0) Exit Select Case 2007 '3 Position Rotary Switch 2 If (AnalogValue(0)<>lever(6).LastValue) Then 'Switch movement detected 'Method 1 - SetControllerValue, waiting for min/max fix but for now using 0, 1, 2 If (AnalogValue(0)<(lever(6).position(0).max+lever(6).position(0).upperthreshold)) Then If (lastrp2<>0) Then TS_SetControllerValue(HEADLIGHTS_ID, 0) 'turn off headlights lastrp2=0 End If Else If ((AnalogValue(0)>(lever(6).position(1).min-lever(6).position(1).lowerthreshold)) And (AnalogValue(0)<(lever(6).position(1).max+lever(6).position(1).upperthreshold))) Then If (lastrp2<>1) Then TS_SetControllerValue(HEADLIGHTS_ID, 1) 'turn on headlights at 1, eventually the middle val lastrp2=1 End If Else If ((AnalogValue(0)>(lever(6).position(2).min-lever(6).position(2).lowerthreshold)) And (AnalogValue(0)<(lever(6).position(2).max+lever(6).position(2).upperthreshold))) Then If (lastrp2<>2) Then TS_SetControllerValue(HEADLIGHTS_ID, 2) 'turn on headlights at 2, eventually at max lastrp2=2 End If End If 'Method 2 - using h keystroke for pos2 and pos3 REM If ((AnalogValue(0)>(lever(6).position(0).min-lever(6).position(0).lowerthreshold)) And (AnalogValue(0)<(lever(6).position(0).max+lever(6).position(0).upperthreshold))) Then REM TS_SetControllerValue(HEADLIGHTS_ID, 0) 'turn off headlights REM thisrp=0 REM Else If ((AnalogValue(0)>(lever(6).position(1).min-lever(6).position(1).lowerthreshold)) And (AnalogValue(0)<(lever(6).position(1).max+lever(6).position(1).upperthreshold))) Then REM thisrp=1 REM If (thisrp<>lastrp2) Then REM If (lastrp2=0 OR lastrp2=2) Then REM '↑]> REM MW3.sendScanCode("35:1,35:0") REM '↑]> REM End If REM End If REM Else If ((AnalogValue(0)>(lever(6).position(2).min-lever(6).position(2).lowerthreshold)) And (AnalogValue(0)<(lever(6).position(2).max+lever(6).position(2).upperthreshold))) Then REM thisrp=2 REM If (thisrp<>lastrp2) Then REM If (lastrp2=1) Then REM '↑]> REM MW3.sendScanCode("35:1,35:0") REM '↑]> REM End If REM End If REM End If lastrp2=thisrp End If lever(6).LastValue=AnalogValue(0) Exit Select End Select 'Analog Check End [/MWTAG13] End Sub 'Analog Data Received Event End [/MWTAG7] Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) SetRailDriverConnected(true) 'do this everytime Dim thisloco As String thisloco=GetLocoName() If (thisloco<>"") Then If (thisloco<>loconame) Then 'new loco detected loconame=thisloco 'MsgBox("New loco detected"&loconame, 0, "RailDriver") 'read in controller list, this changes with every loco Dim controlstring As String controlstring=GetControllerList() 'parse it out Dim delimit As String = "::" Dim cnt As Integer = 0 'first find the total number of controllers Dim temp As String temp=controlstring While temp.Length > 0 Dim pos As Integer = temp.IndexOf(delimit) If pos <> -1 Then temp = temp.Remove(0, pos + 2) cnt += 1 Else Exit While End If End While controllerlist = New String(cnt+1) {} 'now put them into the array cnt=0 While controlstring.Length > 0 Dim pos As Integer = controlstring.IndexOf(delimit) If pos <> -1 Then 'listBox2.Items.Add(cnt.ToString() & "=" & controllerlist.Substring(0, pos)) controllerlist(cnt)=controlstring.Substring(0, pos) controlstring = controlstring.Remove(0, pos + 2) cnt += 1 Else Exit While End If End While 'now assign to _ID variables, see Control List Dialog for available controls, to see the Control List Dialog enter -ShowControlStateDialog in Set Launch Options and run windowed ResetAllIDs() cnt=cnt+1 Dim vbrake As Integer=-1 Dim vreverser As Integer=-1 Dim uvreverser As Integer=-1 Dim vdynbrake As Integer=-1 Dim vwipers As Integer=-1 Dim vheadlights As Integer=-1 Dim venginebrake As Integer=-1 'for now just these For i As Integer = 0 To (cnt) If (controllerlist(i)="Reverser") Then REVERSER_ID=i 'MsgBox("Reverser found "&i, 0, "RailDriver") Else If (controllerlist(i)="VirtualReverser") Then vreverser=i Else If (controllerlist(i)="UserVirtualReverser") Then uvreverser=i Else If (controllerlist(i)="VirtualThrottle") Then THROTTLE_ID=i Else If (controllerlist(i)="Regulator") Then REGULATOR_ID=i Else If (controllerlist(i)="ThrottleAndBrake") Then COMBINED_THROTTLE_BRAKE_ID =i 'if have this don't use dynamic brake Else If (controllerlist(i)="SimpleThrottle") Then SIMPLE_THROTTLE_ID =i Else If (controllerlist(i)="SimpleChangeDirection") Then SIMPLE_CHANGE_DIRECTION_ID=i Else If (controllerlist(i)="DynamicBrake") Then DYNAMIC_BRAKE_ID=i Else If (controllerlist(i)="VirtualDynamicBrake") Then vdynbrake=i Else If (controllerlist(i)="TrainBrakeControl") Then TRAIN_BRAKE_ID=i Else If (controllerlist(i)="VirtualBrake") Then vbrake=i Else If (controllerlist(i)="EmergencyBrake") Then EMERGENCY_BRAKE_ID=i Else If (controllerlist(i)="EngineBrakeControl") Then LOCOMOTIVE_BRAKE_ID=i Else If (controllerlist(i)="VirtualEngineBrakeControl") Then venginebrake=i Else If (controllerlist(i)="Wipers") Then '0,1,2 for now WIPERS_ID=i Else If (controllerlist(i)="VirtualWipers") Then '0,1,2 for now vwipers=i Else If (controllerlist(i)="Headlights") Then '0,1,2 for now HEADLIGHTS_ID=i Else If (controllerlist(i)="VirtualHeadlights") Then '0,1,2 for now vheadlights=i Else If (controllerlist(i)="Horn") Then HORN_ID=i Else If (controllerlist(i)="Sander") Then SANDER_ID=i Else If (controllerlist(i)="Bell") Then BELL_ID=i Else If (controllerlist(i)="PantographControl") Then PANTOGRAPH_ID=i Else If (controllerlist(i)="AWS") Then AWS_ID=i Else If (controllerlist(i)="AWSReset") Then AWS_RESET_ID=i Else If (controllerlist(i)="DSDReset") Then DSD_RESET_ID=i Else If (controllerlist(i)="SpeedometerMPH") Then 'only get either this or KPH, not both SPEEDOMETER_ID=i speedunit=false Else If (controllerlist(i)="SpeedometerKPH") Then SPEEDOMETERKPH_ID=i speedunit=true Else If (controllerlist(i)="ExhaustInjectorSteamOnOff") Then EXHAUST_INJECTOR_STEAM_ID=i Else If (controllerlist(i)="ExhaustInjectorWater") Then EXHAUST_INJECTOR_WATER_ID=i Else If (controllerlist(i)="FireboxDoor") Then FIREBOX_DOOR_ID=i Else If (controllerlist(i)="HandBrake") Then HANDBRAKE_ID=i Else If (controllerlist(i)="LiveInjectorSteamOnOff") Then LIVE_INJECTOR_STEAM_ID=i Else If (controllerlist(i)="LiveInjectorWater") Then LIVE_INJECTOR_WATER_ID=i Else If (controllerlist(i)="SmallCompressorOnOff") Then SMALL_COMPRESSOR_ID=i Else If (controllerlist(i)="Stoking") Then STOKING_ID=i Else If (controllerlist(i)="WaterScoopRaiseLower") Then WATERSCOOP_ID=i Else If (controllerlist(i)="Blower") Then BLOWER_ID=i Else If (controllerlist(i)="CylinderCock") Then CYLINDER_COCK_ID=i Else If (controllerlist(i)="Damper") Then DAMPER_ID=i Else If (controllerlist(i)="Ammeter") Then AMMETER_ID=i Else If (controllerlist(i)="BrakePipePressureBAR") Then BRAKEPIPEPRESSUREBAR_ID=i Else If (controllerlist(i)="BoilerPressurePSI") Then BOILERPRESSUREPSI_ID=i Else If (controllerlist(i)="RPM") Then RPM_ID=i 'add more if desired for example 'Else If (controllerlist(i)="TractiveEffort") Then ' TRACTIVEEFFORT_ID=i End If Next 'sort out this virtual stuff REM If (uvreverser<>-1) Then REM REVERSER_ID=uvreverser REM Else If (vreverser<>-1) Then REM REVERSER_ID=vreverser REM End If If (vbrake<>-1) Then TRAIN_BRAKE_ID=vbrake End If If (vdynbrake<>-1) Then DYNAMIC_BRAKE_ID=vdynbrake End If If (vwipers<>-1) Then WIPERS_ID=vwipers End If If (vheadlights<>-1) Then HEADLIGHTS_ID=vheadlights End If If (venginebrake<>-1) Then LOCOMOTIVE_BRAKE_ID=venginebrake End If CalculateTranslations() End If 'end if Loco has changed Else 'double check 5/12/15 End If 'Do this every timer tick for display SetLEDDisplay() End Sub Public Sub SetLEDDisplay() Dim speed As Single If (SPEEDOMETER_ID<>-1) Then speed = GetControllerValue(SPEEDOMETER_ID, 0) 'speedometer mph If (speedunit=true) Then speed=(speed*1.609344) 'if want kph convert Else If (SPEEDOMETERKPH_ID<>-1) Then speed = GetControllerValue(SPEEDOMETERKPH_ID, 0) 'speedometer kph If (speedunit=false) Then speed=(speed*0.621371) 'if want mph convert End If Dim speeds As String=speed.ToString("000") 'assumes that the train will never be faster than 999, this rounds also If (speeds<>lastspeed) Then 'write new speed 'write to LEDs Dim OutputReport() as Byte = {0,134,ToDigits(speeds.Substring(2, 1)),ToDigits(speeds.Substring(1, 1)),ToDigits(speeds.Substring(0, 1)),0,0,0,0} MW3.SendGenericOutput(MyDevice,OutputReport) lastspeed=speeds End If End Sub Public Sub TS_SetControllerValue(ByVal controlID As Integer, ByVal value As Single) If (controlID<>-1) Then SetControllerValue(controlID, value) End If End Sub Public Sub ResetAllIDs() 'do each time new loco is detected! REVERSER_ID = -1 'analog THROTTLE_ID = -1 'analog - VirtualThrottle REGULATOR_ID = -1 'regulator COMBINED_THROTTLE_BRAKE_ID = -1 'analog - ThrottleAndBrake SIMPLE_THROTTLE_ID = -1 'SimpleThrottle SIMPLE_CHANGE_DIRECTION_ID = -1 'SimpleChangeDirection TRAIN_BRAKE_ID = -1 'analog LOCOMOTIVE_BRAKE_ID = -1 'analog DYNAMIC_BRAKE_ID = -1 'analog EMERGENCY_BRAKE_ID = -1 HANDBRAKE_ID = -1 HORN_ID = -1 '0 off, 1 on BELL_ID = -1 '0 off, 1 on WIPERS_ID = -1 'toggle 1 on, 1 off SANDER_ID = -1 HEADLIGHTS_ID = -1 'toggle PANTOGRAPH_ID = -1 'toggle FIREBOX_DOOR_ID = -1 'toggle EXHAUST_INJECTOR_STEAM_ID = -1 'toggle EXHAUST_INJECTOR_WATER_ID = -1 'toggle LIVE_INJECTOR_STEAM_ID = -1 'toggle LIVE_INJECTOR_WATER_ID = -1 'toggle DAMPER_ID = -1 'toggle BLOWER_ID = -1 'toggle STOKING_ID = -1 'toggle CYLINDER_COCK_ID = -1 'toggle WATERSCOOP_ID = -1 'toggle SMALL_COMPRESSOR_ID = -1 AWS_ID = -1 AWS_RESET_ID = -1 DSD_RESET_ID = -1 SPEEDOMETER_ID = -1 'MPH SPEEDOMETERKPH_ID = -1 'KPH AMMETER_ID=-1 BRAKEPIPEPRESSUREBAR_ID=-1 BOILERPRESSUREPSI_ID=-1 RPM_ID=-1 'add other desired controls 'TRACTIVEEFFORT_ID=-1 End Sub Public Sub ReadCalData() 'this structure contains calibrations and sensitivities for the analog values 'ReDim lever(6) '0=reverser, 1=Dynamic Brake/Throttle, 2=Auto Brake/Emergency Brake, 3=Independent Brake , 4=Bail Off, 5=Rotary 1, 6=Rotary 2 For i As Integer = 0 To 6 ReDim lever(i).position(3) ReDim lever(i).slope(3) ReDim lever(i).intercept(3) ReDim lever(i).islope(3) ReDim lever(i).iintercept(3) lever(i).LastValue=0 For j As Integer = 0 To 3 lever(i).position(j).max = -1 lever(i).position(j).min = -1 lever(i).position(j).upperthreshold = 0 lever(i).position(j).lowerthreshold = 0 lever(i).slope(j) = 0 lever(i).intercept(j) = 0 lever(i).islope(j)=0 lever(i).iintercept(j)=0 Next Next 'read in calibrations Dim sPath As String 'sPath = "C:\Program Files\PI Engineering\MacroWorks 3\Devices\RailDriver\ModernCalibration.rdm" 'sPath=MW3.GetDeviceFolderPath(MyDevice)+"\ModernCalibration.rdm" sPath=MW3.GetLocalDataPath()+"\MyScripts\RailDriver\ModernCalibration.rdm" Const forReading As Integer = 1 Dim objFSO, objFile, sData As Object objFSO = CreateObject("Scripting.FileSystemObject") Try objFile = objFSO.openTextFile(sPath, forReading) Catch ex As System.IO.FileNotFoundException 'MsgBox(sPath+" not found, make sure RailDriver is calibrated.", 0,"File Not Found") result=MsgBox(sPath+" required calibration file not found, would you like to run the calibration utility now?", 4, "Calibration RailDriver") If (result=vbYes) Then 'start up RDcalibration.exe MW3.RunApp(MW3.GetDeviceFolderPath(MyDevice) + "\RD Calibration\RDcalibration.exe","") 'turn on timer which checks for file timer2.Dispose() '??do I need this AddHandler timer2.Tick, AddressOf timer2_Tick timer2.Interval = 500 timer2.Enabled = True Return Else 'if don't calibrate, script will run but analogs will not work or put defaults in?? Return End If 'Return Catch ex As Exception MsgBox(ex.Message, 0, "File Open Error") Return End Try sData = "" Do Until objFile.atEndOfStream sData = sData & objFile.readLine & vbCrLf Loop objFile.close() objFile = Nothing objFSO = Nothing 'now parse out Dim LeverName As String = "" Dim cnt As Int16 = 0 Dim fulldata As String = sData.ToString() Dim pos As Integer Dim minvals(21) As Integer Dim maxvals(21) As Integer While (fulldata.Trim() <> "") pos = fulldata.IndexOf("Min") If (pos <> -1) Then fulldata = fulldata.Remove(0, pos + 3) 'get rid of the Min pos = fulldata.IndexOf(vbCrLf) minvals(cnt) = System.Convert.ToUInt32(fulldata.Substring(0, pos)) fulldata = fulldata.Remove(0, pos).Trim() pos = fulldata.IndexOf("Max") 'assuming there must be a max if there is a min fulldata = fulldata.Remove(0, pos + 3).Trim() pos = fulldata.IndexOf(vbCrLf) maxvals(cnt) = System.Convert.ToUInt32(fulldata.Substring(0, pos)) fulldata = fulldata.Remove(0, pos).Trim() cnt = cnt + 1 Else fulldata = "" End If End While 'fill in the lever structure using the values read in from the calibration file above, thresholds and sensitivity chosen and may be changed lever(0).position(0).min = minvals(0) 'reverser full reversed lever(0).position(0).max = maxvals(0) 'reverser full reversed lever(0).position(0).upperthreshold=4 lever(0).position(0).lowerthreshold=4 lever(0).position(1).min = minvals(1) 'reverser neutral lever(0).position(1).max = maxvals(1) 'reverser neutral lever(0).position(1).upperthreshold=8 'big neutral range lever(0).position(1).lowerthreshold=8 'big neutral range lever(0).position(2).min = minvals(2) 'reverser full forward lever(0).position(2).max = maxvals(2) 'reverser full forward lever(0).position(2).upperthreshold=4 lever(0).position(2).lowerthreshold=4 lever(1).position(0).min = minvals(3) 'dynamic brake/throttle full throttle lever(1).position(0).max = maxvals(3) 'dynamic brake/throttle full throttle lever(1).position(0).upperthreshold=4 lever(1).position(0).lowerthreshold=5 lever(1).position(1).min = minvals(4) 'dynamic brake/throttle throttle idle lever(1).position(1).max = maxvals(4) 'dynamic brake/throttle throttle idle lever(1).position(1).upperthreshold=4 lever(1).position(1).lowerthreshold=4 lever(1).position(2).min = minvals(5) 'dynamic brake/throttle dynamic brake lever(1).position(2).max = maxvals(5) 'dynamic brake/throttle dynamic Brake lever(1).position(2).upperthreshold=4 lever(1).position(2).lowerthreshold=4 lever(1).position(3).min = minvals(6) 'dynamic brake/throttle dynamic brake Setup lever(1).position(3).max = maxvals(6) 'dynamic brake/throttle dynamic brake Setup lever(1).position(3).upperthreshold=4 lever(1).position(3).lowerthreshold=4 lever(2).position(0).min = minvals(7) 'autobrake/emergency brake auto brake released lever(2).position(0).max = maxvals(7) 'autobrake/emergency brake auto brake released lever(2).position(0).upperthreshold=4 lever(2).position(0).lowerthreshold=5 lever(2).position(1).min = minvals(8) 'autobrake/emergency brake full auto brake (cs) lever(2).position(1).max = maxvals(8) 'autobrake/emergency brake full auto brake (cs) lever(2).position(1).upperthreshold=4 lever(2).position(1).lowerthreshold=4 lever(2).position(2).min = minvals(9) 'autobrake/emergency brake emergency brake EMG lever(2).position(2).max = maxvals(9) 'autobrake/emergency brake emergency brake EMG lever(2).position(2).upperthreshold=4 lever(2).position(2).lowerthreshold=4 lever(3).position(0).min = minvals(10) 'independent brake released lever(3).position(0).max = maxvals(10) 'independent brake released lever(3).position(0).upperthreshold=4 lever(3).position(0).lowerthreshold=4 lever(3).position(1).min = minvals(12) 'independent brake full lever(3).position(1).max = maxvals(12) 'independent brake full lever(3).position(1).upperthreshold=4 lever(3).position(1).lowerthreshold=4 lever(4).position(0).min = minvals(11) 'bail off engaged in release lever(4).position(0).max = maxvals(11) 'bail off engaged in release lever(4).position(0).upperthreshold=4 'bail off engaged in release lever(4).position(0).lowerthreshold=10 'bail off engaged in release lever(4).position(1).min = minvals(13) 'bail off engaged in full lever(4).position(1).max = maxvals(13) 'bail off engaged in full lever(4).position(2).min = minvals(14) 'bail off disengaged in release lever(4).position(2).max = maxvals(14) 'bail off disengaged in release lever(4).position(3).min = minvals(15) 'bail off disengaged in full lever(4).position(3).max = maxvals(15) 'bail off disengaged in full lever(5).position(0).min = minvals(16) 'rotary 1 position 1 (off) lever(5).position(0).max = maxvals(16) 'rotary 1 position 1 (off) lever(5).position(0).upperthreshold=6 'must not be 0 w/o changing the logic below lever(5).position(0).lowerthreshold=6 'must not be 0 w/o changing the logic below lever(5).position(1).min = minvals(17) 'rotary 1 position 2 (slow) lever(5).position(1).max = maxvals(17) 'rotary 1 position 2 (slow) lever(5).position(1).upperthreshold=10 'must not be 0 w/o changing the logic below lever(5).position(1).lowerthreshold=10 'must not be 0 w/o changing the logic below lever(5).position(2).min = minvals(18) 'rotary 1 position 1 (full) lever(5).position(2).max = maxvals(18) 'rotary 1 position 1 (full) lever(5).position(2).upperthreshold=6 'must not be 0 w/o changing the logic below lever(5).position(2).lowerthreshold=6 'must not be 0 w/o changing the logic below lever(6).position(0).min = minvals(19) 'rotary 2 position 1 (off) lever(6).position(0).max = maxvals(19) 'rotary 2 position 1 (off) lever(6).position(0).upperthreshold=15 'must not be 0 w/o changing the logic below lever(6).position(0).lowerthreshold=15 'must not be 0 w/o changing the logic below lever(6).position(1).min = minvals(20) 'rotary 2 position 2 (slow) lever(6).position(1).max = maxvals(20) 'rotary 2 position 2 (slow) lever(6).position(1).upperthreshold=10 'must not be 0 w/o changing the logic below lever(6).position(1).lowerthreshold=10 'must not be 0 w/o changing the logic below lever(6).position(2).min = minvals(21) 'rotary 2 position 1 (full) lever(6).position(2).max = maxvals(21) 'rotary 2 position 1 (full) lever(6).position(2).upperthreshold=15 'must not be 0 w/o changing the logic below lever(6).position(2).lowerthreshold=15 'must not be 0 w/o changing the logic below 'sensitivities lever(0).Sensitivity=1 lever(1).Sensitivity=1 lever(2).Sensitivity=1 lever(3).Sensitivity=1 lever(4).Sensitivity=1 lever(5).Sensitivity=1 'not used lever(6).Sensitivity=1 'not used End Sub Public Sub CalculateTranslations() For i As Integer = 0 To 6 lever(i).LastValue=0 For j As Integer = 0 To 3 lever(i).slope(j) = 0 lever(i).intercept(j) = 0 lever(i).islope(j)=0 lever(i).iintercept(j)=0 Next Next If (REVERSER_ID<>-1) Then RailSimReverserMin = GetControllerValue(REVERSER_ID, 1) RailSimReverserMax = GetControllerValue(REVERSER_ID, 2) 'If (RailSimReverserMin=RailSimReverserMax) Then ' RailSimReverserMin=-1 ' RailSimReverserMax=1 'End If End If RailSimReverserN = ((RailSimReverserMax - RailSimReverserMin) / 2.0) + RailSimReverserMin 'calculate the line segments, railsim val=m*AnalogValue+b for each segment calibrated Dim y1 As Single Dim y2 As Single Dim x1 As Single Dim x2 As Single 'segment full reversed to neutral y1=RailSimReverserMin y2=RailSimReverserN x1= ((lever(0).position(0).max - lever(0).position(0).min) / 2.0) + lever(0).position(0).min 'use the average of the max and min cal vals x2 = ((lever(0).position(1).max - lever(0).position(1).min) / 2.0) + lever(0).position(1).min lever(0).slope(0) = (y2 - y1) / (x2 - x1) lever(0).intercept(0) = y1 - (lever(0).slope(0) * x1) y1=RailSimReverserMax lever(0).islope(0) = (y2 - y1) / (x2 - x1) lever(0).iintercept(0) = y1 - (lever(0).islope(0) * x1) 'segment neutral to full forward y1=RailSimReverserN y2=RailSimReverserMax x1 = ((lever(0).position(1).max - lever(0).position(1).min) / 2.0) + lever(0).position(1).min x2 = ((lever(0).position(2).max - lever(0).position(2).min) / 2.0) + lever(0).position(2).min lever(0).slope(1) = (y2 - y1) / (x2 - x1) lever(0).intercept(1) = y1 - (lever(0).slope(1) * x1) y2=RailSimReverserMin lever(0).islope(1) = (y2 - y1) / (x2 - x1) lever(0).iintercept(1) = y1 - (lever(0).islope(1) * x1) 'set ThrottleStyle based on controller list If (THROTTLE_ID<>-1) Then 'VirtualThrottle ThrottleStyle=3 If (DYNAMIC_BRAKE_ID<>-1) Then ThrottleStyle=3 'throttle on bottom, dyn brake on top End If Else If (COMBINED_THROTTLE_BRAKE_ID<>-1) ThrottleStyle=3 'ThrottleAndBrake - brake comes along automatically Else If (REGULATOR_ID<>-1) 'regulator ThrottleStyle=0 THROTTLE_ID=REGULATOR_ID If (DYNAMIC_BRAKE_ID<>-1) Then ThrottleStyle=3 'throttle on bottom, dyn brake on top End If Else If (SIMPLE_THROTTLE_ID<>-1) Then 'last chance, old trains ThrottleStyle=3 THROTTLE_ID=SIMPLE_THROTTLE_ID If (DYNAMIC_BRAKE_ID<>-1) Then 'dynamic brake exists ThrottleStyle=3 End If End If REM ThrottleStyle=3 'forces the dynamic brake/throttle lever to be all throttle for entire lever range RailSimThrottleMin = GetControllerValue(THROTTLE_ID, 1) RailSimThrottleMax = GetControllerValue(THROTTLE_ID, 2) RailSimCombinedThrottleBrakeMin = GetControllerValue(COMBINED_THROTTLE_BRAKE_ID, 1) RailSimCombinedThrottleBrakeMax = GetControllerValue(COMBINED_THROTTLE_BRAKE_ID, 2) RailSimTrainBrakeMin = GetControllerValue(TRAIN_BRAKE_ID, 1) RailSimTrainBrakeMax = GetControllerValue(TRAIN_BRAKE_ID, 2) RailSimLocoBrakeMin = GetControllerValue(LOCOMOTIVE_BRAKE_ID, 1) RailSimLocoBrakeMax = GetControllerValue(LOCOMOTIVE_BRAKE_ID, 2) RailSimDynamicBrakeMin = GetControllerValue(DYNAMIC_BRAKE_ID, 1) RailSimDynamicBrakeMax = GetControllerValue(DYNAMIC_BRAKE_ID, 2) 'RailSimReverserN = ((RailSimReverserMax - RailSimReverserMin) / 2.0) + RailSimReverserMin RailSimCombinedThrottleBrakeN = ((RailSimCombinedThrottleBrakeMax - RailSimCombinedThrottleBrakeMin) / 2.0) + RailSimCombinedThrottleBrakeMin 'fix for Class801, the above GetControllerValue call does NOT return the proper min and max values for this ThrottleAndBrake on this loco Dim temploco As String 'temploco=GetLocoName() 'If (InStr(1,temploco,"Class801")>0) Then ' RailSimCombinedThrottleBrakeMin = -1.5 'obtained from the Control List Dialog ' RailSimCombinedThrottleBrakeMax = 1.0 'obtained from the Control List Dialog ' RailSimCombinedThrottleBrakeN = ((RailSimCombinedThrottleBrakeMax - RailSimCombinedThrottleBrakeMin) / 2.0) + RailSimCombinedThrottleBrakeMin 'End If 'fix for Class 150/2-make throttle lever all throttle temploco=GetLocoName() If (InStr(1,temploco,"Class150/2")>0) Then 'RailSimThrottleMin = 0 'obtained from the Control List Dialog 'RailSimThrottleMax = 7.0 'obtained from the Control List Dialog 'RailSimTrainBrakeMin = 0 'obtained from the Control List Dialog 'RailSimTrainBrakeMax = 4 'obtained from the Control List Dialog ThrottleStyle=3 'force to use entire range just for throttle End If 'fix for BR420, in this case the VirtualThrottle is behaving like a ThrottleAndBrake and also RailDriver.dll does not receive the correct min and max temploco=GetLocoName() If (InStr(1,temploco,"BR420")>0) Then RailSimCombinedThrottleBrakeMin = -9 'obtained from the Control List Dialog RailSimCombinedThrottleBrakeMax = 10 'obtained from the Control List Dialog RailSimCombinedThrottleBrakeN = 0 COMBINED_THROTTLE_BRAKE_ID=THROTTLE_ID 'still need to change the VirtualThrottle so reassign it here ThrottleStyle=1 End If If (ThrottleStyle=0) Then 'segment full throttle to throttle idle 'uses RailSimThrottleMin, RailSimThrottleMax, THROTTLE_ID in Case 2002 y1=RailSimThrottleMax y2=RailSimThrottleMin x1 = ((lever(1).position(0).max - lever(1).position(0).min) / 2.0) + lever(1).position(0).min x2 = ((lever(1).position(1).max - lever(1).position(1).min) / 2.0) + lever(1).position(1).min lever(1).slope(0) = (y2 - y1) / (x2 - x1) lever(1).intercept(0) = y1 - (lever(1).slope(0) * x1) lever(1).islope(0) = (y1 - y2) / (x2 - x1) lever(1).iintercept(0) = y2 - (lever(1).islope(0) * x1) Else If (ThrottleStyle=1) Then 'throttle on bottom segment as labeled on RailDriver 'uses RailSimCombinedThrottleBrakeMin, RailSimCombinedThrottleBrakeMax, COMBINED_THROTTLE_BRAKE_ID in Case 2002 y1=RailSimCombinedThrottleBrakeMax 'this is the RailSim max throttle, usually 1 y2=RailSimCombinedThrottleBrakeN 'RailSim N, usually 0.5 x1 = ((lever(1).position(0).max - lever(1).position(0).min) / 2.0) + lever(1).position(0).min x2 = ((lever(1).position(1).max - lever(1).position(1).min) / 2.0) + lever(1).position(1).min lever(1).slope(0) = (y2 - y1) / (x2 - x1) lever(1).intercept(0) = y1 - (lever(1).slope(0) * x1) 'inverted put throttle on top, full throttle all the way forward y1=RailSimCombinedThrottleBrakeMin lever(1).islope(0) = (y2 - y1) / (x2 - x1) lever(1).iintercept(0) = y1 - (lever(1).islope(0) * x1) 'train brake on upper segment as labeled on RailDriver y1=RailSimCombinedThrottleBrakeMin 'this is the RailSim max train brake, usually 0 y2=RailSimCombinedThrottleBrakeN 'RailSim N, usually 0.5 x1 = ((lever(1).position(2).max - lever(1).position(2).min) / 2.0) + lever(1).position(2).min x2 = ((lever(1).position(3).max - lever(1).position(3).min) / 2.0) + lever(1).position(3).min lever(1).slope(1) = (y2 - y1) / (x2 - x1) lever(1).intercept(1) = y1 - (lever(1).slope(1) * x1) 'inverted put train brake on bottom, full on all the way back y1=RailSimCombinedThrottleBrakeMax lever(1).islope(1) = (y2 - y1) / (x2 - x1) lever(1).iintercept(1) = y1 - (lever(1).islope(1) * x1) Else If (ThrottleStyle=2) Then 'throttle on bottom segment as labeled on RailDriver 'uses RailSimThrottleMin, RailSimThrottleMax, RailSimDynamicBrakeMin, RailSimDynamicBrakeMax, THROTTLE_ID, DYNAMIC_BRAKE_ID in Case 2002 y1=RailSimThrottleMax y2=RailSimThrottleMin x1 = ((lever(1).position(0).max - lever(1).position(0).min) / 2.0) + lever(1).position(0).min x2 = ((lever(1).position(1).max - lever(1).position(1).min) / 2.0) + lever(1).position(1).min lever(1).slope(0) = (y2 - y1) / (x2 - x1) lever(1).intercept(0) = y1 - (lever(1).slope(0) * x1) 'inverted put brakes on bottom y1=RailSimDynamicBrakeMax y2=RailSimDynamicBrakeMin lever(1).islope(0) = (y2 - y1) / (x2 - x1) lever(1).iintercept(0) = y1 - (lever(1).islope(0) * x1) 'dynamic brake on upper segment as labeled on RailDriver y1=RailSimDynamicBrakeMax y2=RailSimDynamicBrakeMin x1 = ((lever(1).position(2).max - lever(1).position(2).min) / 2.0) + lever(1).position(2).min x2 = ((lever(1).position(3).max - lever(1).position(3).min) / 2.0) + lever(1).position(3).min lever(1).slope(1) = (y2 - y1) / (x2 - x1) lever(1).intercept(1) = y1 - (lever(1).slope(1) * x1) 'inverted put throttle on top y1=RailSimThrottleMax y2=RailSimThrottleMin lever(1).islope(1) = (y2 - y1) / (x2 - x1) lever(1).iintercept(1) = y1 - (lever(1).islope(1) * x1) Else 'ThrottleStyle=3 'whole range is throttle where idle is all the way down and full is all the way up (not as labeled on RailDriver) 'uses RailSimThrottleMin, RailSimThrottleMax, THROTTLE_ID in Case 2002 y1=RailSimThrottleMin y2=RailSimThrottleMax x1 = ((lever(1).position(0).max - lever(1).position(0).min) / 2.0) + lever(1).position(0).min x2 = ((lever(1).position(2).max - lever(1).position(2).min) / 2.0) + lever(1).position(2).min lever(1).slope(0) = (y2 - y1) / (x2 - x1) lever(1).intercept(0) = y1 - (lever(1).slope(0) * x1) lever(1).islope(0) = (y1 - y2) / (x2 - x1) lever(1).iintercept(0) = y2 - (lever(1).islope(0) * x1) End If 'segment auto brake released to emergency y1=RailSimTrainBrakeMin y2=RailSimTrainBrakeMax x1 = ((lever(2).position(0).max - lever(2).position(0).min) / 2.0) + lever(2).position(0).min x2 = ((lever(2).position(2).max - lever(2).position(2).min) / 2.0) + lever(2).position(2).min 'use this or CS ?? lever(2).slope(0) = (y2 - y1) / (x2 - x1) lever(2).intercept(0) = y1 - (lever(2).slope(0) * x1) lever(2).islope(0) = (y1 - y2) / (x2 - x1) lever(2).iintercept(0) = y2 - (lever(2).islope(0) * x1) 'segment independent brake released to full y1=RailSimLocoBrakeMin y2=RailSimLocoBrakeMax x1 = ((lever(3).position(0).max - lever(3).position(0).min) / 2.0) + lever(3).position(0).min x2 = ((lever(3).position(1).max - lever(3).position(1).min) / 2.0) + lever(3).position(1).min lever(3).slope(0) = (y2 - y1) / (x2 - x1) lever(3).intercept(0) = y1 - (lever(3).slope(0) * x1) lever(3).islope(0) = (y1 - y2) / (x2 - x1) lever(3).iintercept(0) = y2 - (lever(3).islope(0) * x1) End Sub Private Sub timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Dim sPath As String 'sPath = "C:\Program Files\PI Engineering\MacroWorks 3\Devices\RailDriver\ModernCalibration.rdm" 'sPath=MW3.GetDeviceFolderPath(MyDevice)+"\ModernCalibration.rdm" sPath=MW3.GetLocalDataPath()+"\MyScripts\RailDriver\ModernCalibration.rdm" Const forReading As Integer = 1 Dim objFSO, objFile As Object objFSO = CreateObject("Scripting.FileSystemObject") Try objFile = objFSO.openTextFile(sPath, forReading) Catch ex As System.IO.FileNotFoundException 'cal file not found Return End Try timer2.Enabled = False ReadCalData() objFile.close() objFile = Nothing objFSO = Nothing timer2.Dispose() End Sub End Class '[MWTAG12]