baldanos / cctools Goto Github PK
View Code? Open in Web Editor NEWCollection of tools used to interact with a ccTalk bus
Collection of tools used to interact with a ccTalk bus
I'm trying to access my Wh EMP800 with CCT 910 using ccTools.
Environment: Linux Mint 17 AMD64 (based on Ubuntu 14.04)
CCT 910 info (lsusb -v):
Bus 001 Device 005: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0403 Future Technology Devices International, Ltd
idProduct 0x6001 FT232 USB-Serial (UART) IC
bcdDevice 6.00
iManufacturer 1 wh Berlin
iProduct 2 CCT 900
iSerial 3 whCCT018266
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 2 CCT 900
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Tried to run the basic example from your blog post, on virtualenv:
import serial
import time
from tools.ccTalk import *
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
def send_message(header, data='', source=1, destination=2):
req = ccTalkMessage(header=header, payload=data, source=source,
destination=destination)
req.setPayload(header, data)
ser.write(req)
data = ser.read(50)
messages = parseMessages(data)
for message in messages:
print message
init = ccTalkMessage()
init.setPayload(254)
ok = False
# Wait for device to be initiated
while ok != True:
ser.write(init)
data = ser.read(50)
try:
messages = parseMessages(data)
response = messages[-1]
print response
except:
continue
if response.payload.header == 0:
ok = True
else:
print response.payload.header
# Set inhibit status to allow all
send_message(231, '\xff\xff')
#Set master inhibit status to enable device
send_message(228, '\x01')
#Read buffered credit or error codes
event = 0
while True:
try:
request = ccTalkMessage()
request.setPayload(229)
ser.write(request.__str__())
data = ser.read(50)
messages = parseMessages(data)
for message in messages:
if message.payload.header == 0:
data = message.payload.data
if ord(data[0]) > event:
event = ord(data[0])
print "Counter : " + str(ord(data[0]))
print "Credit 1 : " + str(ord(data[1])),
print "Error 1 : " + str(ord(data[2]))
print "Credit 2 : " + str(ord(data[3])),
print "Error 2 : " + str(ord(data[4]))
print "Credit 3 : " + str(ord(data[5])),
print "Error 3 : " + str(ord(data[6]))
print "Credit 4 : " + str(ord(data[7])),
print "Error 4 : " + str(ord(data[8]))
print "Credit 5 : " + str(ord(data[9])),
print "Error 5 : " + str(ord(data[10]))
time.sleep(0.2)
except KeyboardInterrupt, e:
print "Quitting..."
break
ser.close()
And that's the error:
Traceback (most recent call last):
File "/home/marjinal1st/Development/PycharmProjects/CoinTests/src/test-02.py", line 26, in <module>
ser.write(init)
File "/home/marjinal1st/Development/PycharmProjects/CoinTests/local/lib/python2.7/site-packages/serial/serialposix.py", line 491, in write
d = to_bytes(data)
File "/home/marjinal1st/Development/PycharmProjects/CoinTests/local/lib/python2.7/site-packages/serial/serialutil.py", line 75, in to_bytes
for item in seq:
TypeError: iteration over non-sequence
I made some debugs using PyCharm, this is some debug information I could get when the exception is thrown:
Any ideas?
I've a coin hopper and I'm trying to dispense coins. But I'm always getting NAK response for the 167 Header.
Normally, all the ccTalk documents I've found says: Get the serial number with 242 header and add number of coins to dispense as hex. Concatenate them and send them as data with 167 header.
My test program:
import serial
from tools.ccTalk import *
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=0.2)
def sendMessage(header, data='', source=1, destination=3):
request = ccTalkMessage(header=header, payload=data, source=source, destination=destination)
print " -> " + str(request)
ser.write(request.raw())
data = ser.read(50)
messages = parseMessages(data)[1]
print " <- " + str(messages[1])
print("Data: %s\n" % messages[1].payload.data)
return messages[1]
print "[*] Pinging device..."
ok = False
# Wait for device to be initiated
while not ok:
try:
response = sendMessage(254)
except:
continue
if response.payload.header == 0:
ok = True
else:
print response.payload.header
print "[*] Request manufacturer id ..."
sendMessage(246)
print "[*] Request product code"
sendMessage(244)
print "[*] Enable hopper"
sendMessage(164)
print "[*] Getting serial number"
sr = sendMessage(242).payload.data
print "[*] Dispensing coins..."
sendMessage(167, sr + '\x01')
And my output is:
[*] Pinging device...
-> <cctalk src=1 dst=3 length=0 header=254 signature=checksum>
<- <cctalk src=3 dst=1 length=0 header=0 signature=checksum>
Data:
[*] Request manufacturer id ...
-> <cctalk src=1 dst=3 length=0 header=246 signature=checksum>
<- <cctalk src=3 dst=1 length=10 header=0 data=484f505045522053726c signature=checksum>
Data: HOPPER Srl
[*] Request product code
-> <cctalk src=1 dst=3 length=0 header=244 signature=checksum>
<- <cctalk src=3 dst=1 length=14 header=0 data=554348312d4e4f454e4352595054 signature=checksum>
Data: UCH1-NOENCRYPT
[*] Enable hopper
-> <cctalk src=1 dst=3 length=0 header=164 signature=checksum>
<- <cctalk src=3 dst=1 length=0 header=0 signature=checksum>
Data:
[*] Getting serial number
-> <cctalk src=1 dst=3 length=0 header=242 signature=checksum>
<- <cctalk src=3 dst=1 length=3 header=0 data=bdb65b signature=checksum>
Data: ��[
[*] Dispensing coins...
-> <cctalk src=1 dst=3 length=4 header=167 data=bdb65b01 signature=checksum>
<- <cctalk src=3 dst=1 length=0 header=5 signature=checksum>
Data:
Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.