-
Notifications
You must be signed in to change notification settings - Fork 2
/
transport.py
53 lines (38 loc) · 1.08 KB
/
transport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import serial
import os
class PySID:
def __init__(self, nothing):
import pysid
self.pysid = pysid
def send(self, regs):
for x in range(25):
self.pysid.write_reg(x, regs[x])
def __del__(self):
self.send([0] * 25)
class FifoTransport:
def __init__(self, fifo_file):
try:
os.mkfifo(fifo_file)
except OSError:
pass
self.fifo = open(fifo_file,'wb')
def send(self, regs):
data = [chr(13),'S','D','M','P'] + [chr(x) for x in regs]
self.fifo.write(''.join(data))
def __del__(self):
self.send([0] * 25)
class Transport:
def __init__(self, port):
self.serial = serial.Serial(port, 115200)
def send(self, regs):
data = [chr(13),'S','D','M','P'] + [chr(x) for x in regs]
self.serial.write(''.join(data))
self.serial.flush()
def __del__(self):
self.send([0] * 25)
self.serial.close()
class DummyTransport:
def __init__(self, port):
pass
def send(self, data):
print(data)