bonjour
je remets un fichier Word en PJ avec l'essentiel
et ci contre son contenu au cas où ( adapter les lignes avec "AT" et "A")
la solution est d'utiliser des noms uniques pour quelques variables dans les scripts Python
une bonne fin de journée
luc
help about SMA29 JMRI Turnout Channels – Direct JMRI to Arduino Communications
Sat, 2019-11-02 16:05 — lucd
• Track and electrical/DCC
• Tools, tips and tricks
Hello Geoff
J read your article « SMA29 JMRI Turnout Channels – Direct JMRI to Arduino Communications - Simple Support for Lots of Data Out From JMRI »
I need help with this communication between JMRI and Arduino
I am living in France and I built a DCC station with DCC++ and JMRI
I built a module to manage turnout without difficulty from your article and the website « locoduino » (arduino Uno / USB port com 9)
I built a second module with relays to manage switches under 16v alternative (arduino Uno / USB port com 4)
this second module also works perfectly from JMRI when it is alone
But, his presence completely blocks the first one who no longer receives anything
I made the requested changes in the script "Python" (cf the two scripts attached)
I reactivated the messages that can be seen in the console (cf the Word)
thank you for your help
a good weekend at all
best regards
luc
• 127 reads
Luc, the discussion
Sat, 2019-11-02 20:59 — samusi01
Luc,
the discussion at
https://groups.io/g/jmriusers/topic/32577852 may provide some assistance. in short, there may be duplicated variables that mean the second script is referring to a variable already created by the first script.
Sam
----------------------------------------------------------------------------------------------------------------------
La correction proposée sur un exemple de script
Les lignes en « bleue » doivent contenir des noms de variables spécifiques à chaque canal de capteur
J’ai pris AT et T pour l’exemple
# Transfer "TurnOut" Data from to an Arduino via Serial Transmission
# Author: Geoff Bunza 2018 based in part on a script by
# Bob Jacobsen as part of the JMRI distribution
# Version 1.1
# Connects JMRI Turnout "Watcher" to an Arduino Output Channel
# Note that JMRI must be set up to have a valid
# turnout table; if you're not using some other DCC connection,
# configure JMRI to use LocoNet Simulator
import jarray
import jmri
import java
import purejavacomm
# find the port info and open the port
global extportinA
portname = "COM5"
portID = purejavacomm.CommPortIdentifier.getPortIdentifier(portname)
try:
port = portID.open("JMRI", 50)
except purejavacomm.PortInUseException:
port = extportinA
extportinA = port
# set options on port
baudrate = 19200
port.setSerialPortParams(baudrate,
purejavacomm.SerialPort.DATABITS_8,
purejavacomm.SerialPort.STOPBITS_1,
purejavacomm.SerialPort.PARITY_NONE)
# get I/O connections for later
inputStreamAT = port.getInputStream()
outputStreamAT = port.getOutputStream()
# define a turnout listener that will
class Datatransfer(java.beans.PropertyChangeListener):
# initialization
# registers to receive events
def __init__(self, id, value) :
self.name = "AT"+str(id)
self.closed = value # write this value to close
self.thrown = value # write this value to throw
turnout = turnouts.provideTurnout(self.name)
turnout.addPropertyChangeListener(self)
turnout.setCommandedState(CLOSED)
return
# on a property change event, first see if
# right type, and then write appropriate
# value to port based on new state
def propertyChange(self, event):
#print "change",event.propertyName
#print "from", event.oldValue, "to", event.newValue
#print "source systemName", event.source.systemName
if (event.propertyName == "CommandedState") :
if (event.newValue == CLOSED and event.oldValue != CLOSED) :
print "set CLOSED for", event.source.userName
outputStreamAT.write(event.source.userName)
outputStreamAT.write(",0")
if (event.newValue == THROWN and event.oldValue != THROWN) :
print "set THROWN for", event.source.userName
outputStreamAT.write(event.source.userName)
outputStreamAT.write(",1")
return
# The following will set up 5 listeners for Turnouts PT1 though PT6 (by username)
for x in range(1,6) :
Datatransfer(x,x+100)