Function SetMfxRegValue6021(thisPort As Integer, thisRegister As Integer, thisNewValue As Integer) : Boolean
begin
// (c) DiegoGarcia and Family, Germany // 19.04.2007 // RealBasic 2007-02 subroutine (Mac, Lin & Win) // Purpose: write "thisNewValue" into "thisRegister"-RegV of any FX-/MFX-decoder // through the serial port indicated by "thisPort", where a mae6021/mae6051 is connected // Assuming: "Serial1 As Serial" defined in calling window or global "App"
const ckue = "ü" // for German message text const ckea = "é" // for French message text const ckag = "à"
const Vturn = 15 //mae6021 / P50 syntax = change direction; apply only on non-moving locos! const Vstop = 0 // mae6021 / P50 syntax = speed 0, no loco moving const DefaultMFXLocoAdr = 80 // address 80 is used to access any FX/MFX decoder, no matter what address it has dim oldCTS As Boolean // to store existing status dim myGoOn As Boolean
myGoOn = TRUE
if (thisPort >= 0) and (thisPort < System.SerialPortCount) then // check bounds
Serial1.SerialPort = System.SerialPort(thisPort)
Serial1.Baud = GetActualBaud // this MUST be done before Serial1.Open !!!!!!! Serial1.Parity = GetActualParity Serial1.Bits = GetActualDataBits Serial1.Stop = GetActualStoppBits Serial1.CTS = GetActualCTSflowcontrol
// try to open the serial port if not Serial1.Open then // we failed to open the port, quit this subroutine MsgBox "Could not open " + System.SerialPort( thisPort ).Name // perhaps another application is using this port or access rights are missing myGoOn = FALSE else
// 0) instruction to the user: reset the mae6021 manually, sorry, no command for this task ShowProgrammingMode(TRUE) DisplayInfoText(0) select case App.gLanguage case 1 myGoOn = App.MessageWithCancel("Pressez simultan" + ckea + "ment les touches GO et STOP jusqu'" + ckag + " ce que le num" + ckea + "ro '99' clignote sur l'" + ckea + "cran.") case 2 myGoOn = App.MessageWithCancel("Bitte die Mrkl6021 zur" + ckue + "cksetzen durch gleichzeitiges Dr" + ckue + "cken der GO und STOP Tasten, bis '99' in der Anzeige aufblinkt.") else myGoOn = App.MessageWithCancel("Please reset the mrkl6021 by pressing GO and STOP simultaneously for several seconds until '99' blinks in the display.") end select
if myGoOn then
// 1) sending STOP command DisplayInfoText(1) WriteByte(97) // Nothalt / STOP Wait150miliseconds // sending twice, to compensate a wrong byte order of preceeding commands WriteByte(97) WaitSeconds(1)
// 2) disable CTS, because the 6050/6051 interface should tell CTS=FALSE after STOP command oldCTS = Serial1.CTS Serial1.CTS = FALSE // to enable data sending in any case
// 3) send message to turn any FX/MFX decoder into programming mode DisplayInfoText(2) WriteByte( Vstop ) // send speed = 0 to stop motor Wait150miliseconds WriteByte( DefaultMFXLocoAdr ) // addr = 80 Wait150miliseconds
WriteByte( Vturn ) // send speed = 15 to turn direction Wait150miliseconds WriteByte( DefaultMFXLocoAdr ) // addr = 80 Wait150miliseconds
DisplayInfoText(3) WriteByte(96) // Freigabe / GO WaitSeconds(1) // now the mae6021 will fire always "turning" command to loco addr 80 // and the head-lights of the MFX-/FX-loco should blink continously on both sides
// 4) re-eanable CTS Serial1.CTS = oldCTS
// 5) write RegV-entry address // sequence doesn't matter, you can turn off DefaultMFXLocoAdr's turning command before adressing thisRegister DisplayInfoText(4) WriteByte( Vstop ) // send speed = 0 to stop mae6021 firing "turning" command Wait150miliseconds WriteByte( DefaultMFXLocoAdr ) // addr = 80 Wait150miliseconds
WriteByte( Vstop ) // send speed = 0 to stop motor, preparing RegV to receive data Wait150miliseconds WriteByte( thisRegister ) // addr = RegV address range 1..79 Wait150miliseconds
WriteByte( Vturn ) // send speed = 15 to indicate RegV to receive data Wait150miliseconds WriteByte( thisRegister ) // addr = RegV address range 1..79 WaitSeconds(2) // wait a little bit longer
// now the head-lights of the loco should blink in a faster scheme
// 6) write new value to this RegV DisplayInfoText(5) WriteByte( Vstop ) // send speed = 0 to stop mae6021 firing "turning" command Wait150miliseconds WriteByte( thisRegister ) // addr = RegV address range 1..79 Wait150miliseconds
WriteByte( Vturn ) // send speed = 15 to indicate the data Wait150miliseconds WriteByte( thisNewValue ) // addr = value range 1..80, depending on RegV's definition of the decoder Wait150miliseconds
// now the head-lights of the loco should blink in the slower scheme
WriteByte( Vstop ) // send speed = 0 to stop mae6021 firing "turning" command Wait150miliseconds WriteByte( thisNewValue ) // addr = RegV address range 1..79 WaitSeconds(2) // wait a little bit longer
WaitSeconds(1) Serial1.CTS = FALSE // to enable data sending in any case WriteByte(96) // Freigabe / GO Wait150miliseconds Serial1.CTS = oldCTS
// done, now the mae6021 should be again in normal operation mode // and the loco's decoder should have the new value "thisNewValue" entered in its RegV "thisRegister" // sorry to say that there is now way to read RegVs using a mae6021/mae6051 combination.
Dass ist sehr interessant, ich werde das dann ausprobieren. Ich werde es dann auch erst mit dem Interface versuchen. Wenn das dann geht, versuche ich ob es mit DDW auch klappt.
Gruß, Blacky
Ich bin zu allem fähig, aber zu nichts zu gebrauchen.