Forgot to attach my script...

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
##!/opt/bin/python2.7
#!/usr/bin/env python2

import sys, traceback
import usb.core, usb.util
from time import sleep

def trimbuffer(buf):
    i = 0
    while i < len(buf):
        if (i > 0 and buf[i] == 0x7d and buf[i-1] == 0x40):
            break
        i += 1
    return buf[0:i+1]

def ws3000_write(command):
    print "ws3000_write: entry"
    VENDOR = 0x0483
    PRODUCT = 0x5750
    CONFIGURATION = 0

    try:

        print "Detecting device..."
        device = usb.core.find(idVendor=VENDOR, idProduct=PRODUCT)
        if device is None:
            print("Is the WS-3000 connected?")
            sys.exit(1)
        print("Device found")

        # Device busy if managed by the kernel
        if device.is_kernel_driver_active(CONFIGURATION):
            print("Detaching kernel driver")
            device.detach_kernel_driver(CONFIGURATION)

        # WS-3000 has only one configuration
        device.set_configuration()

        # control
        print "Sending control packet"
        #device.ctrl_transfer(0x21, 10, 0, 0, None)
        device.ctrl_transfer(0, 9, 1, 0, None)

        commands = [0x41, 0x06, 0x08, 0x09, 0x05, 0x03, 0x04]
        #commands = [0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03]
        for command in commands:
            request = [0x7b, command, 0x40, 0x7d]
            padding = [0x0] * 60
            request.extend(padding)
            print "Sending command: ", request
            device.write(0x01, request, 100)
            data = device.read(0x82, 64, 100)
            data = trimbuffer(data)
            print data
            print len(data)
            #for value in data:
            #    print hex(value)
            sleep(10)

    except:
        print "An error occurred:", sys.exc_info()
        traceback.print_exc(file=sys.stdout)

    usb.util.dispose_resources(device)

print("Starting tests...")
ws3000_write("")
print("Tests completed")

Reply via email to