Very nice unit - but I am having a major mental blockage on getting it working utilizing the Python library provided. Has anyone got the basics going using pure Python? Forward, back etc, once I have that I will work the rest out.
Thanks
Code: Select all
board = 0
print("DCC test on board %d\n" % board)
for chan in range(0,4) :
gb.set_mode(board,chan,gb.MODE_DCC)
print("Performing number of writes\n")
message = [0x03, 0x68 ]
print("0x03,0x68: move loc 3. Press return to send")
input()
gb.send_dcc_mess(board,0xF,message)
message = [0x02, 0x67 ]
print("0x02,0x67: move loc 2. Press return to send")
input()
gb.send_dcc_mess(board,0xF,message)
message = [0x00, 0x40 ]
print("0x00,0x40: Stop All. Press return to send")
input()
gb.send_dcc_mess(board,0xF,message)
Code: Select all
import gertbot as gb
import curses
import time
BOARD = 0 # Which board we talk to
PHY_CHANNEL = 0 # channel for track
LOCO = 0x04
gb.open_uart(0)
#gb.set_mode(BOARD, PHY_CHANNEL, MODE)
print("DCC test on board %d\n" % BOARD)
for chan in range(0,4) :
gb.set_mode(BOARD,chan,gb.MODE_DCC)
print ("ERROR" , gb.error_string(gb.read_error_status(BOARD)))
print ("MOTOR CONFIG " , gb.get_motor_config(BOARD, 0))
print("Performing number of writes\n")
message = [0x04, 0x63 ]
print("0x04,0x68: move loc 4. Press return to send")
input()
gb.send_dcc_mess(BOARD,0xF,message)
Code: Select all
case MOT_MODE_DCC:
// First switch channel short circuit to off
uart_tx(CMD_STOPSHORT,id,ENDSTOP_OFF|ENB_ERR_IGNORE); // No short no endstops
// DCC mode
uart_tx(CMD_OPMODE,id,mode);
Code: Select all
ENB_ERR_IGNORE = 0x00
CMD_START_VAL = 0xA0 # Serial protocol start flag
CMD_STOP_VAL = 0x50 # Serial protocol end flag
print("DCC test on board %d\n" % BOARD)
for chan in range(0,4) :
message = []
gb.ENDSTOP_OFF | ENB_ERR_IGNORE, CMD_STOP_VAL)
message.append(CMD_START_VAL)
message.append(gb.CMD_STOPSHORT)
message.append((BOARD<<2) | chan)
message.append(gb.ENDSTOP_OFF | ENB_ERR_IGNORE)
message.append(CMD_STOP_VAL)
gb.send_raw(message)
gb.set_mode(BOARD,chan, gb.MODE_DCC)
Code: Select all
ENB_ERR_IGNORE = 0x00
CMD_START_VAL = 0xA0 # Serial protocol start flag
CMD_STOP_VAL = 0x50 # Serial protocol end flag
for chan in range(0,4) :
message = []
#gb.send_raw(gb.ENDSTOP_OFF | ENB_ERR_IGNORE, CMD_STOP_VAL)
message.append(CMD_START_VAL)
message.append(gb.CMD_STOPSHORT)
message.append((BOARD<<2) | chan)
message.append(gb.ENDSTOP_OFF | ENB_ERR_IGNORE)
message.append(CMD_STOP_VAL)
gb.send_raw(message)
gb.set_mode(BOARD,chan, gb.MODE_DCC)
print ("ERROR" , gb.error_string(gb.read_error_status(BOARD)))
print ("MOTOR CONFIG " , gb.get_motor_config(BOARD, 0))Code: Select all
Dumbed down the code to minimum and still failing. Not sure what the message means:Code: Select all
#
# Return error status of board
# (zero means no pending errors)
# (-1 means read error)
def read_error_status(board):
# To do : check the arguments
dest = board<<2
wrtbuf = [PRE, CMD_GET_ERROR, dest, POST, POST, POST, POST]
os.write(filehandle,bytes(wrtbuf))
termios.tcdrain(filehandle)
ok , data = read_uart(4)
if (not ok) :
return -1
val = (data[2]<<8) | data[3]
return val
Code: Select all
...
"DCC illegal message (length)", # ERROR_DCC_MESS 0x0020
"Illegal error status code" ) # MAX_ERROR
def error_string(error_number):
if (error_number<0 or error_number>MAX_ERROR):
error_number = MAX_ERROR
return error_text[error_number]