You are here

pyUSB on Raspberry Pi

Random My Youtube Video

sudo python setup.py install

http://stackoverflow.com/questions/29345325/raspberry-pyusb-gets-resourc...

https://pixiescorner.wordpress.com/2009/09/05/utilityconvert-x10-to-inst...

This isn't too bad, but there are a couple quirks to be aware of. One limitation is that sending X10 codes breaks if you go too fast. I added a Wait subroutine (see the end of this page). The PLM seems to need a 500 millisecond pause between X10 commands. Lower delays didn't seem to work.

Also, the indexes are odd. I set up two arrays with the necessary values (see below).

The following also assumes that

house = the X10 house code as an integer, 0 = A, etc
device = the X10 device code as an integer

Put this in the declarations area of your form/module:

Public PLM_X10_House(16) as Byte
Public PLM_X10_Device(16) as Byte

Set the values for those areas somewhere convenient (like Form1.Load):

PLM_X10_House(1) = 96 ' House code A
PLM_X10_House(2) = 224 ' House code B
PLM_X10_House(3) = 32 ' House code C
PLM_X10_House(4) = 160 ' House code D
PLM_X10_House(5) = 16 ' House code E
PLM_X10_House(6) = 144 ' House code F
PLM_X10_House(7) = 80 ' House code G
PLM_X10_House(8) = 208 ' House code H
PLM_X10_House(9) = 112 ' House code I
PLM_X10_House(10) = 240 ' House code J
PLM_X10_House(11) = 48 ' House code K
PLM_X10_House(12) = 176 ' House code L
PLM_X10_House(13) = 0 ' House code M
PLM_X10_House(14) = 128 ' House code N
PLM_X10_House(15) = 64 ' House code O
PLM_X10_House(16) = 192 ' House code P

PLM_X10_Device(1) = 6
PLM_X10_Device(2) = 14
PLM_X10_Device(3) = 2
PLM_X10_Device(4) = 10
PLM_X10_Device(5) = 1
PLM_X10_Device(6) = 9
PLM_X10_Device(7) = 5
PLM_X10_Device(8) = 13
PLM_X10_Device(9) = 7
PLM_X10_Device(10) = 15
PLM_X10_Device(11) = 3
PLM_X10_Device(12) = 11
PLM_X10_Device(13) = 0
PLM_X10_Device(14) = 8
PLM_X10_Device(15) = 4
PLM_X10_Device(16) = 12
To send an X10 On command:

Dim data(3) as Byte

data(0) = 2 ' start first message: send X10 address only
data(1) = 99 ' 0x063 = Send X10
data(2) = PLM_X10_House(house + 1) + PLM_X10_Device(device) ' X10 address (house + device)
data(3) = 0 ' flag = this is the address
SerialPLM.Write(data, 0, 4)
Wait(500)
data(0) = 2 ' start second message: send X10 house + command
data(1) = 99 ' 0x063 = Send X10
data(2) = PLM_X10_House(house + 1) + 2 ' X10 address (house + command)
data(3) = 128 ' flag = this is house + address
SerialPLM.Write(data, 0, 4)
To send an X10 Off command:

Dim data(3) as Byte

data(0) = 2 ' start first message: send X10 address only
data(1) = 99 ' 0x063 = Send X10
data(2) = PLM_X10_House(house + 1) + PLM_X10_Device(device) ' X10 address (house + device)
data(3) = 0 ' flag = this is the address
SerialPLM.Write(data, 0, 4)
Wait(500)
data(0) = 2 ' start second message: send X10 house + command
data(1) = 99 ' 0x063 = Send X10
data(2) = PLM_X10_House(house + 1) + 3 ' X10 address (house + command)
data(3) = 128 ' flag = this is house + address
SerialPLM.Write(data, 0, 4)

import usb.core
import usb.util

# find our device
dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001)

# was it found?
if dev is None:
raise ValueError('Device not found')

# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]

ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)

assert ep is not None

# write the data
ep.write('test')

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.