|
1 | NO CONTENT: new file 100644 |
@@ -0,0 +1,113 | |||
|
1 | ''' | |
|
2 | Created on Nov 25, 2015 | |
|
3 | ||
|
4 | @author: Miguel Urco | |
|
5 | ||
|
6 | eth_device decorator is used to implement an api to ethernet devices. | |
|
7 | When eth_device decorator is used it adds two parameters to any function (ip and port) | |
|
8 | ||
|
9 | #Definition of a function using eth_device decorator | |
|
10 | ||
|
11 | @eth_device(ID_CLASS) | |
|
12 | def enable_acq(message) | |
|
13 | cmd = "xxxxx" | |
|
14 | payload = message | |
|
15 | ||
|
16 | return cmd, payload | |
|
17 | ||
|
18 | #How to call this function: | |
|
19 | answer = enable_acq(ip, port, message) | |
|
20 | ||
|
21 | ''' | |
|
22 | import sys | |
|
23 | import struct | |
|
24 | import json | |
|
25 | ||
|
26 | from devices.jro_device import eth_device, IdClass | |
|
27 | ||
|
28 | ID_CLASS = IdClass["jars"] | |
|
29 | ||
|
30 | CMD_RESET = 0X01 | |
|
31 | CMD_CHANGEIP = 0X03 | |
|
32 | #Add other commands | |
|
33 | CMD_CONFIGURE = 0X10 | |
|
34 | CMD_STATUS = 0X11 | |
|
35 | CMD_SET_EXEPATH = 0X12 | |
|
36 | CMD_ECHO = 0XFE | |
|
37 | CMD_READ = 0X08 | |
|
38 | CMD_STOP = 0X09 | |
|
39 | ||
|
40 | @eth_device(ID_CLASS) | |
|
41 | def reset(): | |
|
42 | ||
|
43 | cmd = CMD_RESET | |
|
44 | payload = '' | |
|
45 | ||
|
46 | return cmd, payload | |
|
47 | ||
|
48 | @eth_device(ID_CLASS) | |
|
49 | def stop(): | |
|
50 | ||
|
51 | cmd = CMD_STOP | |
|
52 | payload = '' | |
|
53 | ||
|
54 | return cmd, payload | |
|
55 | ||
|
56 | @eth_device(ID_CLASS) | |
|
57 | def echo(message): | |
|
58 | ||
|
59 | cmd = CMD_ECHO | |
|
60 | payload = message | |
|
61 | ||
|
62 | return cmd, payload | |
|
63 | ||
|
64 | @eth_device(ID_CLASS) | |
|
65 | def configure(conf): | |
|
66 | ||
|
67 | cmd = CMD_CONFIGURE | |
|
68 | payload = conf | |
|
69 | ||
|
70 | return cmd, payload | |
|
71 | ||
|
72 | @eth_device(ID_CLASS) | |
|
73 | def status(): | |
|
74 | ||
|
75 | cmd = CMD_STATUS | |
|
76 | payload = '' | |
|
77 | ||
|
78 | return cmd, payload | |
|
79 | ||
|
80 | @eth_device(ID_CLASS) | |
|
81 | def read(): | |
|
82 | ||
|
83 | cmd = CMD_READ | |
|
84 | payload = '' | |
|
85 | ||
|
86 | return cmd, payload | |
|
87 | ||
|
88 | @eth_device(ID_CLASS) | |
|
89 | def set_exepath(path): | |
|
90 | ||
|
91 | cmd = CMD_SET_EXEPATH | |
|
92 | payload = path | |
|
93 | ||
|
94 | return cmd, payload | |
|
95 | ||
|
96 | #--To take .json file from computer: | |
|
97 | #with open('/home/fquino/Downloads/Experiment.json') as data_file: | |
|
98 | # data = json.load(data_file) | |
|
99 | ||
|
100 | # data['configurations']['dds']='' | |
|
101 | # data['configurations']['rc']['pulses']='' | |
|
102 | # data['configurations']['rc']['delays']='' | |
|
103 | ||
|
104 | #data = json.dumps(data) | |
|
105 | #----------------------------------- | |
|
106 | ||
|
107 | #print reset('10.10.10.100', 10000) | |
|
108 | #print echo('10.10.10.95', 10000, 'Hola JARS :)') | |
|
109 | ||
|
110 | #json_data = json.dumps({'name':'archivo1','variable':9}) | |
|
111 | #print configure('10.10.10.95', 10000, data) | |
|
112 | #print configure('10.10.10.100', 10000, '') | |
|
113 | #print status('10.10.10.100', 10000) |
|
1 | NO CONTENT: modified file |
@@ -3,8 +3,4 from django.conf.urls import url | |||
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_abs_conf'), |
|
5 | 5 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_abs_conf'), |
|
6 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_abs_conf'), | |
|
7 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_abs_conf'), | |
|
8 | url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_abs_conf'), | |
|
9 | url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_abs_conf'), | |
|
10 | 6 | ) |
|
1 | NO CONTENT: modified file |
@@ -245,6 +245,11 class JARSConfiguration(Configuration): | |||
|
245 | 245 | return self.device.status |
|
246 | 246 | |
|
247 | 247 | |
|
248 | def start_device(self): | |
|
249 | ||
|
250 | self.write_device() | |
|
251 | ||
|
252 | ||
|
248 | 253 | def echo(self): |
|
249 | 254 | |
|
250 | 255 | answer = api.echo(self.device.ip_address,self.device.port_address,'(=') |
@@ -1,5 +1,4 | |||
|
1 | 1 | import os |
|
2 | import ast | |
|
3 | 2 | import json |
|
4 | 3 | |
|
5 | 4 | from django import forms |
@@ -322,7 +321,6 class RCLineEditForm(forms.ModelForm): | |||
|
322 | 321 | help_text=help_text) |
|
323 | 322 | |
|
324 | 323 | else: |
|
325 | ||
|
326 | 324 | self.fields[label] = forms.CharField(initial=value, help_text=help_text) |
|
327 | 325 | |
|
328 | 326 | if label in ('code', ): |
@@ -339,7 +337,7 class RCLineEditForm(forms.ModelForm): | |||
|
339 | 337 | elif params[label]['widget']=='codes': |
|
340 | 338 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
341 | 339 | else: |
|
342 | self.fields[label].widget = DefaultWidget(attrs={'name':'%s|%s|%s' % (count, line.id, label)}) | |
|
340 | self.fields[label].widget = DefaultWidget(attrs={'line':line, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
|
343 | 341 | |
|
344 | 342 | |
|
345 | 343 | class Meta: |
@@ -293,7 +293,7 class IPData(object): | |||
|
293 | 293 | def __sendTCPData(self, cadena): |
|
294 | 294 | |
|
295 | 295 | sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
296 |
sck.settimeout( |
|
|
296 | sck.settimeout(3) | |
|
297 | 297 | |
|
298 | 298 | try: |
|
299 | 299 | sck.connect(self.address) |
@@ -314,7 +314,10 class IPData(object): | |||
|
314 | 314 | if time.time() - ini > 0.5: |
|
315 | 315 | break |
|
316 | 316 | |
|
317 |
t |
|
|
317 | try: | |
|
318 | tmp = sck.recv(4096) | |
|
319 | except: | |
|
320 | break | |
|
318 | 321 | |
|
319 | 322 | if len(tmp) < 1: |
|
320 | 323 | continue |
@@ -35,8 +35,6 CMD_ECHO =0XFE | |||
|
35 | 35 | RC_CMD_RESET =0X10 |
|
36 | 36 | RC_CMD_WRITE =0x50 |
|
37 | 37 | RC_CMD_READ =0x8000 |
|
38 | RC_CMD_ENABLE =0X24 | |
|
39 | RC_CMD_DISABLE =0X00 | |
|
40 | 38 | |
|
41 | 39 | @eth_device(ID_CLASS) |
|
42 | 40 | def reset(): |
@@ -71,32 +69,16 def echo(): | |||
|
71 | 69 | return cmd, payload |
|
72 | 70 | |
|
73 | 71 | @eth_device(ID_CLASS) |
|
74 | def enable(): | |
|
75 | ||
|
76 | cmd = RC_CMD_ENABLE | |
|
77 | payload = chr(0x01) | |
|
78 | ||
|
79 | return cmd, payload | |
|
80 | ||
|
81 | @eth_device(ID_CLASS) | |
|
82 | def disable(): | |
|
83 | ||
|
84 | cmd = RC_CMD_DISABLE | |
|
85 | payload = chr(0x00) | |
|
86 | ||
|
87 | return cmd, payload | |
|
88 | ||
|
89 | @eth_device(ID_CLASS) | |
|
90 | 72 | def read_all_device(): |
|
91 | 73 | |
|
92 | 74 | payload = "" |
|
93 | 75 | |
|
94 |
return |
|
|
76 | return CR_CMD_READ, payload | |
|
95 | 77 | |
|
96 | 78 | @eth_device(ID_CLASS) |
|
97 | 79 | def write_all_device(payload): |
|
98 | 80 | |
|
99 |
return |
|
|
81 | return CR_CMD_WRITE, payload | |
|
100 | 82 | |
|
101 | 83 | def read_config(ip, port): |
|
102 | 84 | """ |
@@ -117,7 +99,7 def write_config(ip, port, parms): | |||
|
117 | 99 | |
|
118 | 100 | """ |
|
119 | 101 | |
|
120 | payload = write_ram_memory(parms['pulses'], parms['delays']) | |
|
102 | payload = data.dict_to_rc_str(parms) | |
|
121 | 103 | |
|
122 | 104 | answer = write_all_device(ip, port, payload) |
|
123 | 105 | |
@@ -131,7 +113,7 def __get_high_byte(valor): | |||
|
131 | 113 | |
|
132 | 114 |
|
|
133 | 115 | |
|
134 | ||
|
116 | @eth_device(ID_CLASS) | |
|
135 | 117 | def write_ram_memory(vector_valores, vector_tiempos): |
|
136 | 118 | |
|
137 | 119 | l1 = len(vector_valores) |
@@ -143,7 +125,7 def write_ram_memory(vector_valores, vector_tiempos): | |||
|
143 | 125 |
|
|
144 | 126 | ord(84) + __get_low_byte(vector_tiempos[i]) + ord(85) + __get_high_byte(vector_tiempos[i]) |
|
145 | 127 | |
|
146 | return cad | |
|
128 | return RC_CMD_WRITE, cad | |
|
147 | 129 | |
|
148 | 130 | if __name__ == '__main__': |
|
149 | 131 | ip = "10.10.20.150" |
|
1 | NO CONTENT: modified file |
General Comments 0
You need to be logged in to leave comments.
Login now