Xcom_API.py 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. ##########################################################################################################################################
  4. # Python-File Information #
  5. ##########################################################################################################################################
  6. #
  7. # File: Xcom_API.py
  8. # Author: Tobias Müller
  9. # Date: 2017.08.09
  10. #
  11. ##########################################################################################################################################
  12. # Requirements #
  13. ##########################################################################################################################################
  14. import struct
  15. ##########################################################################################################################################
  16. # Class Definition & Description #
  17. ##########################################################################################################################################
  18. # This class is used to generate byte-frames, which are needed to communicate with Xtender-Moduls over the RS232-BUS with the Xcom-232i.
  19. # After generating the byte-frame, you can use "pyserial" to communicate with the Serial-BUS and to put the byte-frame into the write-
  20. # method of "pyserial". You can decode also read-frames of the Serial-BUS with this class.
  21. #
  22. # This class contains methods to generate read- or write-frames, and methods to decode frames. There are pre-defined types, properties
  23. # and formats for the most important parameter- and information-numbers. This reduces the effort for generating byte-frames, but there
  24. # are extended methods to generate byte-frames with other parameter- and information-numbers.
  25. class Xcom_API():
  26. """
  27. This class is used to generate byte-frames, which are needed to communicate with Xtender-Moduls over the RS232-BUS with the Xcom-232i.
  28. After generating the byte-frame, you can use "pyserial" to communicate with the Serial-BUS and to put the byte-frame into the write-
  29. method of "pyserial". You can decode also read-frames of the Serial-BUS with this class.
  30. This class contains methods to generate read- or write-frames, and methods to decode frames. There are pre-defined types, properties
  31. and formats for the most important parameter- and information-numbers. This reduces the effort for generating byte-frames, but there
  32. are extended methods to generate byte-frames with other parameter- and information-numbers.
  33. """
  34. ##################################################################################################################################
  35. # Program Information #
  36. ##################################################################################################################################
  37. __PROG_NAME = 'Xcom_API'
  38. __PROG_Version = 'v1.0'
  39. ##################################################################################################################################
  40. # Private-Object-Instance-Counter #
  41. ##################################################################################################################################
  42. __object_counter = 0
  43. ##################################################################################################################################
  44. # Private-Attributes-Service_ID #
  45. ##################################################################################################################################
  46. __service_read = 1
  47. __service_write = 2
  48. ##################################################################################################################################
  49. # Protected-Attributes-Object_Type #
  50. ##################################################################################################################################
  51. _object_type_info = 1
  52. _object_type_parameter = 2
  53. _object_type_message = 3
  54. _object_type_datalog_field = 5
  55. _object_type_datalog_transfer = 257
  56. ##################################################################################################################################
  57. # Protected-Attributes-Info-Object_ID #
  58. ##################################################################################################################################
  59. _info_battery_voltage = 3000
  60. _info_battery_temperature = 3001
  61. _info_battery_charge_current = 3005
  62. _info_battery_voltage_ripple = 3006
  63. _info_state_of_charge = 3007
  64. _info_number_of_battery_elements = 3050
  65. _info_input_voltage = 3011
  66. _info_input_current = 3012
  67. _info_input_frequency = 3084
  68. _info_input_power = 3138
  69. _info_output_voltage = 3021
  70. _info_output_current = 3022
  71. _info_output_frequency = 3085
  72. _info_output_power = 3139
  73. _info_operating_state = 3028
  74. _info_boost_active = 3019
  75. _info_state_of_inverter = 3049
  76. _info_state_of_transfer_relay = 3020
  77. _info_state_of_output_relay = 3030
  78. _info_state_of_aux_relay_1 = 3031
  79. _info_state_of_aux_relay_2 = 3032
  80. _info_state_of_ground_relay = 3074
  81. _info_state_of_neutral_transfer_relay = 3075
  82. _info_state_of_remote_entry = 3086
  83. ##################################################################################################################################
  84. # Protected-Attributes-Parameter-Object_ID #
  85. ##################################################################################################################################
  86. _para_maximum_current_of_ac_source = 1107
  87. _para_battery_charge_current = 1138
  88. _para_smart_boost_allowed = 1126
  89. _para_inverter_allowed = 1124
  90. _para_type_of_detection_of_grid_loss = 1552
  91. _para_charger_allowed = 1125
  92. _para_charger_uses_only_power_from_ac = 1646
  93. _para_ac_output_voltage = 1286
  94. _para_inverter_frequency = 1112
  95. _para_transfer_relay_allowed = 1128
  96. _para_limitation_of_the_power_boost = 1607
  97. _para_remote_entry_active = 1545
  98. ##################################################################################################################################
  99. # Protected-Attributes-Property_ID #
  100. ##################################################################################################################################
  101. _property_id_value = 1
  102. _property_id_string = 1
  103. _property_id_value_qsp = 5
  104. _property_id_min_qsp = 6
  105. _property_id_max_qsp = 7
  106. _property_id_level_qsp = 8
  107. _property_id_unsaved_value_qsp = 13
  108. _property_id_invalid_Action = 0
  109. _property_id_sd_start = 21
  110. _property_id_sd_datablock = 22
  111. _property_id_sd_ack_continue = 23
  112. _property_id_sd_nack_retry = 24
  113. _property_id_sd_abort = 25
  114. _property_id_sd_finish = 26
  115. ##################################################################################################################################
  116. # Protected-Attributes-Format #
  117. ##################################################################################################################################
  118. _format_bool = [1,1]
  119. _format_format = [2,2]
  120. _format_short_int = [3,2]
  121. _format_enum = [4,2]
  122. _format_short_enum = [5,2]
  123. _format_long_enum = [6,4]
  124. _format_error = [7,2]
  125. _format_int32 = [8,4]
  126. _format_float = [9,4]
  127. _format_byte = [10,1]
  128. ##################################################################################################################################
  129. # Private-Level-QSP #
  130. ##################################################################################################################################
  131. __level_qsp_view_only = 0x0000
  132. __level_qsp_basic = 0x0010
  133. __level_qsp_expert = 0x0020
  134. __level_qsp_installer = 0x0030
  135. __level_qsp_qsp = 0x0040
  136. ##################################################################################################################################
  137. # Private-Attributes #
  138. ##################################################################################################################################
  139. __start_byte = 0xAA
  140. __frame_flags = 0x00
  141. __data_flags = 0x00
  142. __data_frame = 0x0A
  143. # Dictionary of Error-Codes-Descriptions
  144. __error_code_dict = {0x0001 : 'INVALID_FRAME',
  145. 0x0002 : 'DEVICE_NOT_FOUND',
  146. 0x0003 : 'RESPONSE_TIMEOUT',
  147. 0x0011 : 'SERVICE_NOT_SUPPORTED',
  148. 0x0012 : 'INVALID_SERVICE_ARGUMENT',
  149. 0x0013 : 'SCOM_ERROR_GATEWAY_BUSY',
  150. 0x0021 : 'TYPE_NOT_SUPPORTED',
  151. 0x0022 : 'OBJECT_ID_NOT_FOUND',
  152. 0x0023 : 'PROPERTY_NOT_SUPPORTED',
  153. 0x0024 : 'INVALID_DATA_LENGTH',
  154. 0x0025 : 'PROPERTY_IS_READ_ONLY',
  155. 0x0026 : 'INVALID_DATA',
  156. 0x0027 : 'DATA_TOO_SMALL',
  157. 0x0028 : 'DATA_TO_BIG',
  158. 0x0029 : 'WRITE_PROPERTY_FAILED',
  159. 0x002A : 'READ_PROPERTY_FAILED',
  160. 0X002B : 'ACCESS_DENIED',
  161. 0x002C : 'SCOM_ERROR_OBJECT_NOT_SUPPORTED',
  162. 0x002D : 'SCOM_ERROR_MULTICAST_READ_NOT_SUPPORTED',
  163. 0x002E : 'OBJECT_PROPERTY_INVALID',
  164. 0x002F : 'FILE_OR_DIR_NOT_PRESENT',
  165. 0x0030 : 'FILE_CORRUPTED',
  166. 0x0081 : 'INVALID_SHELL_ARG'}
  167. # Dictionary of Parameter-Info-Numbers with type, property and format
  168. __para_info_dict = {3000 : [_object_type_info,_property_id_value,_format_float],
  169. 3001 : [_object_type_info,_property_id_value,_format_float],
  170. 3005 : [_object_type_info,_property_id_value,_format_float],
  171. 3006 : [_object_type_info,_property_id_value,_format_float],
  172. 3007 : [_object_type_info,_property_id_value,_format_float],
  173. 3050 : [_object_type_info,_property_id_value,_format_float],
  174. 3011 : [_object_type_info,_property_id_value,_format_float],
  175. 3012 : [_object_type_info,_property_id_value,_format_float],
  176. 3084 : [_object_type_info,_property_id_value,_format_float],
  177. 3138 : [_object_type_info,_property_id_value,_format_float],
  178. 3020 : [_object_type_info,_property_id_value,_format_short_enum],
  179. 3021 : [_object_type_info,_property_id_value,_format_float],
  180. 3022 : [_object_type_info,_property_id_value,_format_float],
  181. 3085 : [_object_type_info,_property_id_value,_format_float],
  182. 3139 : [_object_type_info,_property_id_value,_format_float],
  183. 3028 : [_object_type_info,_property_id_value,_format_short_enum],
  184. 3019 : [_object_type_info,_property_id_value,_format_short_enum],
  185. 3049 : [_object_type_info,_property_id_value,_format_short_enum],
  186. 3030 : [_object_type_info,_property_id_value,_format_short_enum],
  187. 3031 : [_object_type_info,_property_id_value,_format_short_enum],
  188. 3032 : [_object_type_info,_property_id_value,_format_short_enum],
  189. 3074 : [_object_type_info,_property_id_value,_format_short_enum],
  190. 3075 : [_object_type_info,_property_id_value,_format_short_enum],
  191. 3086 : [_object_type_info,_property_id_value,_format_short_enum],
  192. 1107 : [_object_type_parameter,_property_id_value_qsp,_format_float],
  193. 1138 : [_object_type_parameter,_property_id_value_qsp,_format_float],
  194. 1126 : [_object_type_parameter,_property_id_value_qsp,_format_bool],
  195. 1124 : [_object_type_parameter,_property_id_value_qsp,_format_bool],
  196. 1552 : [_object_type_parameter,_property_id_value_qsp,_format_long_enum],
  197. 1125 : [_object_type_parameter,_property_id_value_qsp,_format_bool],
  198. 1646 : [_object_type_parameter,_property_id_value_qsp,_format_bool],
  199. 1286 : [_object_type_parameter,_property_id_value_qsp,_format_float],
  200. 1112 : [_object_type_parameter,_property_id_value_qsp,_format_float],
  201. 1128 : [_object_type_parameter,_property_id_value_qsp,_format_bool],
  202. 1607 : [_object_type_parameter,_property_id_value_qsp,_format_float],
  203. 1545 : [_object_type_parameter,_property_id_value_qsp,_format_long_enum]}
  204. ##################################################################################################################################
  205. # Constructor-Method #
  206. ##################################################################################################################################
  207. # This Method is used with generating an object of the Xcom_API-Class. There are pre-defined arguments (CRC-Check, source-address,
  208. # destination-address) for this object, when you generate an objects without relevant arguments.
  209. def __init__(self, crc = True, source = 1, destination = 101):
  210. """
  211. ### Description:
  212. This Method is used with generating an object of the Xcom_API-Class. There are predefined arguments (CRC-Check, source-address,
  213. destination-address) for this object, when you generate an objects without relevant arguments.
  214. ### Arguments:
  215. There are predefined arguments, which you can change:
  216. +-+-+
  217. | | |
  218. +=+=+
  219. | **crc** | = True |
  220. +-+-+
  221. | **source** | = 1 |
  222. +-+-+
  223. | **destination** | = 101 |
  224. +-+-+
  225. ### Return-Value:
  226. This Method return an object of the Xcom_API-Class.
  227. ### Example-Code:
  228. ```>>> Object = Xcom_API()
  229. **Or if you want to change predefined arguments:**
  230. ```>>> Object = Xcom_API(crc = False)
  231. """
  232. # Check the type of the argument "crc". It raises a "ValueError" with a false type.
  233. if not isinstance(crc, bool):
  234. raise ValueError('CRC is not type \"bool\"!')
  235. # Check the type of the argument "source". It raises a "ValueError" with a false type.
  236. elif not isinstance(source, int) or isinstance(source, bool):
  237. raise ValueError('Source-Address is not type \"int\"!')
  238. # Check the range of the argument "source" It raises a "ValueError", if the argument is out of range.
  239. elif not 0<source<100:
  240. raise ValueError('Source-Address is out of range!')
  241. # Check the type of the argument "destination" It raises a "ValueError" with a false type.
  242. elif not isinstance(destination, int) or isinstance(destination, bool):
  243. raise ValueError('Destination-Address is not type \"int\"!')
  244. # Check the range of the argument "destination" It raises a "ValueError", if the argument is out of range.
  245. elif not (destination==0 or destination==401 or destination==501 or destination==601 or 100<=destination<=109 or
  246. 191<=destination<=193 or 300<=destination<=315 or 700<=destination<=715):
  247. raise ValueError('Destination-Address is out of range!')
  248. # If there is no error, the arguments will be stored in variables of the object. The object-counter will be increased.
  249. else:
  250. self.__dest = destination
  251. self.__source = source
  252. self.__crc = crc
  253. self.__frame_check_done = False
  254. Xcom_API.__object_counter += 1
  255. ##################################################################################################################################
  256. # Deconstructor-Method #
  257. ##################################################################################################################################
  258. # This Method delete an object of this class with the stored variables and decrease the object-counter.
  259. def __del__(self):
  260. """
  261. ### Description:
  262. This Method delete an object of this class with the stored variables and decrease the object-counter.
  263. ### Example-Code:
  264. ```>>> Object = Xcom_API()
  265. >>> del Object
  266. """
  267. if hasattr(self,'__crc'):
  268. del self.__crc
  269. if hasattr(self,'__source'):
  270. del self.__source
  271. if hasattr(self,'__dest'):
  272. del self.__dest
  273. if hasattr(self,'__frame_check_done'):
  274. del self.__frame_check_done
  275. Xcom_API.__object_counter -= 1
  276. ##################################################################################################################################
  277. # Information-Methods #
  278. ##################################################################################################################################
  279. # This method returns an integer-value of the source-address of an object.
  280. def get_source_address(self):
  281. """
  282. ### Description:
  283. This method returns an integer-value of the source-address of an object.
  284. ### Return-Value:
  285. This Method return an **int**.
  286. ### Example-Code:
  287. ```>>> Object = Xcom_API()
  288. >>> Src_Addr = Object.get_source_address()
  289. >>> Src_Addr
  290. 1
  291. """
  292. return self.__source
  293. # This method returns an integer-value of the destination-address of an object.
  294. def get_destination_address(self):
  295. """
  296. ### Description:
  297. This method returns an integer-value of the destination-address of an object.
  298. ### Return-Value:
  299. This Method return an **int**.
  300. ### Example-Code:
  301. ```>>> Object = Xcom_API()
  302. >>> Dest_Addr = Object.get_destination_address()
  303. >>> Dest_Addr
  304. 101
  305. """
  306. return self.__dest
  307. # This method returns a boolean-value of the active-state of the CRC-Check of an object.
  308. def is_crc_check_active(self):
  309. """
  310. ### Description:
  311. This method returns a boolean-value of the active-state of the CRC-Check of an object.
  312. ### Return-Value:
  313. This Method return a **boolean**.
  314. ### Example-Code:
  315. ```>>> Object = Xcom_API()
  316. >>> CRC_Active = Object.is_crc_check_active()
  317. >>> CRC_Active
  318. True
  319. """
  320. return self.__crc
  321. # This method returns a integer-value of the counter of active-objects of this class.
  322. @staticmethod
  323. def get_object_counter():
  324. """
  325. ### Description:
  326. This method returns a integer-value of the counter of active-objects of this class.
  327. ### Return-Value:
  328. This Method return an **int**.
  329. ### Example-Code:
  330. ```>>> Obj_Count = Xcom_API.get_object_counter()
  331. >>> Obj_Count
  332. 0
  333. **Or if you have generate an Object:**
  334. ```>>> Object = Xcom_API()
  335. >>> Obj_Count = Object.get_object_counter()
  336. >>> Obj_Count
  337. 1
  338. """
  339. return Xcom_API.__object_counter
  340. # This method returns a string of the of the program-name of this class.
  341. @staticmethod
  342. def get_prog_name():
  343. """
  344. ### Description:
  345. This method returns a string of the of the program-name of this class.
  346. ### Return-Value:
  347. This Method return a **string**.
  348. ### Example-Code:
  349. ```>>> Prog_Name = Xcom_API.get_prog_name()
  350. >>> Prog_Name
  351. 'Xcom_API'
  352. **Or if you have generate an Object:**
  353. ```>>> Object = Xcom_API()
  354. >>> Prog_Name = Object.get_prog_name()
  355. >>> Prog_Name
  356. 'Xcom_API'
  357. """
  358. return Xcom_API.__PROG_NAME
  359. # This method returns a string of the of the program-version of this class.
  360. @staticmethod
  361. def get_prog_version():
  362. """
  363. ### Description:
  364. This method returns a string of the of the program-version of this class.
  365. ### Return-Value:
  366. This Method return a **string**.
  367. ### Example-Code:
  368. ```>>> Prog_Version = Xcom_API.get_prog_version
  369. >>> Prog_Version
  370. 'v1.0'
  371. **Or if you have generate an Object:**
  372. ```>>> Object = Xcom_API()
  373. >>> Prog_Version = Object.get_prog_version
  374. >>> Prog_Version
  375. 'v1.0'
  376. """
  377. return Xcom_API.__PROG_Version
  378. ##################################################################################################################################
  379. # Private-Methods #
  380. ##################################################################################################################################
  381. # This Method calculate the CRC-Values of a Frame. It returns the CRC-Values in a list or bytearray.
  382. def __calculate_checksum(byte_frame):
  383. """
  384. ### Description:
  385. This Method calculate the CRC-Values of a Frame. It returns the CRC-Values in a **list**.
  386. ### Arguments:
  387. The **<byte_frame>** argument must be a type of **list** or **bytearray**.
  388. ### Return-Value:
  389. This Method return a **list** of length two with the CRC-Values.
  390. ### Example-Code:
  391. ```>>> Byte_Frame = [0x0, 0x1, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0xA, 0x0]
  392. >>> CRC_Value = Xcom_API.__calculate_checksum(Byte_Frame)
  393. >>> CRC_Value
  394. [0x6F, 0x71]
  395. **Or if you are not using this function inside the API:**
  396. ```>>> Byte_Frame = [0x0, 0x1, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0xA, 0x0]
  397. >>> CRC_Value = Xcom_API._Xcom_API__calculate_checksum(Byte_Frame)
  398. >>> CRC_Value
  399. [0x6F, 0x71]
  400. """
  401. # Define two Buffers for the CRC-Values.
  402. Buffer1 = 0xFF
  403. Buffer2 = 0
  404. # Calculate the CRC-Values of a Frame.
  405. for i in range(0,len(byte_frame)):
  406. Buffer1 = (Buffer1 + byte_frame[i]) % 256
  407. Buffer2 = (Buffer1 + Buffer2) % 256
  408. # Return the CRC-Values in a list.
  409. return [Buffer1, Buffer2]
  410. # This Method generate a Byte-Frame of a Value depending of the format. It returns a list of Bytes, which are ordered in LSB to
  411. # MSB.
  412. def __value_to_byte_frame(property_data, data_format):
  413. """
  414. ### Description:
  415. This Method generate a Byte-Frame of a Value depending of the format. It returns a list of Bytes, which are ordered in LSB to MSB.
  416. ### Arguments:
  417. The **<property_data>** argument must be a type of **int** or **float** depending of the type of **<data_format>**.
  418. For the **<data_format>** argument use one of the following formats:
  419. +-+-+
  420. | | |
  421. +=+=+
  422. | _format_bool | = [1, 1] |
  423. +-+-+
  424. | _format_format | = [2, 2] |
  425. +-+-+
  426. | _format_short_int | = [3, 2] |
  427. +-+-+
  428. | _format_enum | = [4, 2] |
  429. +-+-+
  430. | _format_short_enum | = [5, 2] |
  431. +-+-+
  432. | _format_long_enum | = [6, 4] |
  433. +-+-+
  434. | _format_error | = [7, 2] |
  435. +-+-+
  436. | _format_int32 | = [8, 4] |
  437. +-+-+
  438. | _format_float | = [9, 4] |
  439. +-+-+
  440. | _format_byte | = [10, 1] |
  441. +-+-+
  442. ### Return-Value:
  443. This Method return a **list** with values, which represents the **Byte_Frame**. The length of the **list** depends of the **<data_format>** argument.
  444. ### Example-Code:
  445. ```>>> Value = 12.0
  446. >>> Byte_Frame = Xcom_API.__value_to_byte_frame(Value, Xcom_API._format_float)
  447. >>> Byte_Frame
  448. [0x0, 0x0, 0x40, 0x41]
  449. **Or if you are not using this function inside the API:**
  450. ```>>> Value = 12.0
  451. >>> Byte_Frame = Xcom_API._Xcom_API__value_to_byte_frame(Value, Xcom_API._format_float)
  452. >>> Byte_Frame
  453. [0x0, 0x0, 0x40, 0x41]
  454. """
  455. # It checks the argument "data_format" for type "Bool" and check the range/type of "property_data", depending of the
  456. # data_format. It raises an ValueError if the checks failed, otherwise it returns the list of the Byte-Frame.
  457. if data_format==Xcom_API._format_bool:
  458. if not 0<=property_data<=1 or not (isinstance(property_data, int) or isinstance(property_data, bool)):
  459. raise ValueError('Invalid \"property_data\" for the data_format of type \"bool\"!')
  460. else:
  461. # Return a list of the Byte-Frame.
  462. if property_data == 0 or property_data == False:
  463. return [0]
  464. else:
  465. return [1]
  466. # It checks the argument "data_format" for type "Byte" and check the range/type of "property_data", depending of the
  467. # data_format. It raises an ValueError if the checks failed, otherwise it returns the list of the Byte-Frame.
  468. elif data_format==Xcom_API._format_byte:
  469. if not 0<=property_data<256 or not isinstance(property_data, int):
  470. raise ValueError('Invalid \"property_data\" for the data_format of type \"Byte\"!')
  471. else:
  472. # Return a list of the Byte-Frame.
  473. return [property_data]
  474. # It checks the argument "data_format" for type "Error" and check the range/type of "property_data", depending of the
  475. # data_format. It raises an ValueError if the checks failed, otherwise it calculate and returns the list of the Byte-Frame.
  476. elif data_format==Xcom_API._format_error:
  477. if not 0<=property_data<=0x65535 or not isinstance(property_data, int):
  478. raise ValueError('Invalid \"property_data\" for the data_format of type \"Error\"!')
  479. else:
  480. # Define a Buffer for calculating.
  481. Buffer = hex(property_data)
  482. # Calculate the Byte-Frame.
  483. for i in range(0,data_format[1]*2-(len(Buffer)-2)):
  484. Buffer = Buffer[0:2]+str(0)+Buffer[2:]
  485. # Return a list of the Byte-Frame.
  486. return [int(Buffer[4:6],16),int(Buffer[2:4],16)]
  487. # It checks the argument "data_format" for type "Format" or "Short Integer" and check the range/type of "property_data",
  488. # depending of the data_format. It raises an ValueError if the checks failed, otherwise it calculate and returns the list of
  489. # the Byte-Frame.
  490. elif data_format==Xcom_API._format_format or data_format==Xcom_API._format_short_int:
  491. if not -32768<=property_data<=32767 or not isinstance(property_data, int):
  492. raise ValueError('Invalid \"property_data\" for the data_format of type \"Format\" or \"Short Integer\"!')
  493. else:
  494. # Calculate the Byte-Frame.
  495. if property_data<0:
  496. # Define a Buffer for calculating.
  497. Buffer = hex(2**16 + property_data)
  498. else:
  499. # Define a Buffer for calculating.
  500. Buffer = hex(property_data)
  501. for i in range(0,data_format[1]*2-(len(Buffer)-2)):
  502. Buffer = Buffer[0:2]+str(0)+Buffer[2:]
  503. # Return a list of the Byte-Frame.
  504. return [int(Buffer[4:6],16),int(Buffer[2:4],16)]
  505. # It checks the argument "data_format" for type "Enum" or "Short Enum" and check the range/type of "property_data", depending
  506. # of the data_format. It raises an ValueError if the checks failed, otherwise it calculate and returns the list of the Byte-Frame.
  507. # Only one Bit can be set in data_format of type "Enum".
  508. elif data_format==Xcom_API._format_enum or data_format==Xcom_API._format_short_enum:
  509. if not 0<=property_data<=32767 or not isinstance(property_data, int):
  510. raise ValueError('Invalid \"property_data\" for the data_format of type \"Enum\" or \"Short Enum\"!')
  511. else:
  512. check = False
  513. for i in range(0,16):
  514. if (2**i==2**i&property_data) and check:
  515. raise ValueError('Invalid \"property_data\" for the data_format of type \"Enum\" or \"Short Enum\"!')
  516. elif 2**i==2**i&property_data:
  517. check = True
  518. # Define a Buffer for calculating.
  519. Buffer = hex(property_data)
  520. # Calculate the Byte-Frame.
  521. for i in range(0,data_format[1]*2-(len(Buffer)-2)):
  522. Buffer = Buffer[0:2]+str(0)+Buffer[2:]
  523. # Return a list of the Byte-Frame.
  524. return [int(Buffer[4:6],16),int(Buffer[2:4],16)]
  525. # It checks the argument "data_format" for type "Long Enum" and check the range/type of "property_data", depending of the
  526. # data_format. It raises an ValueError if the checks failed, otherwise it calculate and returns the list of the Byte-Frame.
  527. # Only one Bit can be set in data_format of type "Enum".
  528. elif data_format==Xcom_API._format_long_enum:
  529. if not 0<=property_data<=2147483647 or not isinstance(property_data, int):
  530. raise ValueError('Invalid \"property_data\" for the data_format of type \"Long Enum\"!')
  531. else:
  532. check = False
  533. for i in range(0,32):
  534. if (2**i==2**i&property_data) and check:
  535. raise ValueError('Invalid \"property_data\" for the data_format of type \"Long Enum\"!')
  536. elif 2**i==2**i&property_data:
  537. check = True
  538. # Define a Buffer for calculating.
  539. Buffer = hex(property_data)
  540. # Calculate the Byte-Frame.
  541. for i in range(0,data_format[1]*2-(len(Buffer)-2)):
  542. Buffer = Buffer[0:2]+str(0)+Buffer[2:]
  543. # Return a list of the Byte-Frame.
  544. return [int(Buffer[8:10],16),int(Buffer[6:8],16),int(Buffer[4:6],16),int(Buffer[2:4],16)]
  545. # It checks the argument "data_format" for type "INT32" and check the range/type of "property_data", depending of the
  546. # data_format. It raises an ValueError if the checks failed, otherwise it calculate and returns the list of the Byte-Frame.
  547. elif data_format==Xcom_API._format_int32:
  548. if not -2147483648<=property_data<=2147483647 or not isinstance(property_data, int):
  549. raise ValueError('Invalid \"property_data\" for the data_format of type \"INT32\"!')
  550. else:
  551. # Calculate the Byte-Frame.
  552. if property_data<0:
  553. # Define a Buffer for calculating.
  554. Buffer = hex(2**32 + property_data)
  555. else:
  556. # Define a Buffer for calculating.
  557. Buffer = hex(property_data)
  558. for i in range(0,data_format[1]*2-(len(Buffer)-2)):
  559. Buffer = Buffer[0:2]+str(0)+Buffer[2:]
  560. # Return a list of the Byte-Frame.
  561. return [int(Buffer[8:10],16),int(Buffer[6:8],16),int(Buffer[4:6],16),int(Buffer[2:4],16)]
  562. # It checks the argument "data_format" for type "Float" and check the range/type of "property_data", depending of the
  563. # data_format. It raises an ValueError if the checks failed, otherwise it calculate and returns the list of the Byte-Frame.
  564. elif data_format==Xcom_API._format_float:
  565. if not -2147483648<=property_data<=2147483647 or not isinstance(property_data, float):
  566. raise ValueError('Invalid \"property_data\" for the data_format of type \"Float\"!')
  567. else:
  568. # Calculate the Byte-Frame.
  569. Buffer = struct.pack("!f",property_data)
  570. # Return a list of the Byte-Frame.
  571. return [Buffer[3],Buffer[2],Buffer[1],Buffer[0]]
  572. # It raises an Error, if the argument "data_format" doesn't fit.
  573. else:
  574. raise ValueError('data_format is unknown!')
  575. # This Method generate a Value of a Byte-Frame depending of the format. It returns the value as a integer/float.
  576. def __byte_frame_to_value(byte_frame, data_format):
  577. """
  578. ### Description:
  579. This Method generate a Value of a Byte-Frame depending of the format. It returns the value as a integer/float.
  580. ### Arguments:
  581. The **<byte_frame>** argument must be a type of **list** or **bytearray**. The lenght depends of the type of **<data_format>**.
  582. For the **<data_format>** argument use one of the following formats:
  583. +-+-+
  584. | | |
  585. +=+=+
  586. | _format_bool | = [1, 1] |
  587. +-+-+
  588. | _format_format | = [2, 2] |
  589. +-+-+
  590. | _format_short_int | = [3, 2] |
  591. +-+-+
  592. | _format_enum | = [4, 2] |
  593. +-+-+
  594. | _format_short_enum | = [5, 2] |
  595. +-+-+
  596. | _format_long_enum | = [6, 4] |
  597. +-+-+
  598. | _format_error | = [7, 2] |
  599. +-+-+
  600. | _format_int32 | = [8, 4] |
  601. +-+-+
  602. | _format_float | = [9, 4] |
  603. +-+-+
  604. | _format_byte | = [10, 1] |
  605. +-+-+
  606. ### Return-Value:
  607. This Method return a value of type **int** or **float** depending of the **<data_format>** argument.
  608. ### Example-Code:
  609. ```>>> Byte_Frame = [0x0, 0x0, 0x40, 0x41]
  610. >>> Value = Xcom_API.__byte_frame_to_value(Byte_Frame, Xcom_API._format_float)
  611. >>> Value
  612. 12.0
  613. **Or if you are not using this function inside the API:**
  614. ```>>> Byte_Frame = [0x0, 0x0, 0x40, 0x41]
  615. >>> Value = Xcom_API._Xcom_API__byte_frame_to_value(Byte_Frame, Xcom_API._format_float)
  616. >>> Value
  617. 12.0
  618. """
  619. # It checks the argument "data_format" for type "Bool" and check the length/type of "byte_frame", depending of the
  620. # data_format. It raises an ValueError if the checks failed, otherwise it returns the value of the Byte-Frame.
  621. if data_format==Xcom_API._format_bool:
  622. if not len(byte_frame)==data_format[1] or not isinstance(byte_frame[0], int) or not 0<=byte_frame[0]<=1:
  623. raise ValueError('Invalid \"byte_frame\" for the data_format of type \"bool\"!')
  624. else:
  625. # Return the value of the Byte-Frame.
  626. return byte_frame[0]
  627. # It checks the argument "data_format" for type "Byte" and check the length/type of "byte_frame", depending of the
  628. # data_format. It raises an ValueError if the checks failed, otherwise it returns the value of the Byte-Frame.
  629. elif data_format==Xcom_API._format_byte:
  630. if not len(byte_frame)==data_format[1] or not isinstance(byte_frame[0], int):
  631. raise ValueError('Invalid \"byte_frame\" for the data_format of type \"Byte\"!')
  632. else:
  633. # Return the value of the Byte-Frame.
  634. return byte_frame[0]
  635. # It checks the argument "data_format" for type "Error" and check the length/type of "byte_frame", depending of the
  636. # data_format. It raises an ValueError if the checks failed, otherwise it calculate and returns the value of the Byte-Frame.
  637. elif data_format==Xcom_API._format_error:
  638. if not len(byte_frame)==data_format[1] or not isinstance(byte_frame[0], int) or not isinstance(byte_frame[1], int):
  639. raise ValueError('Invalid \"byte_frame\" for the data_format of type \"Error\"!')
  640. else:
  641. # Define a Buffer.
  642. Buffer = '0x'
  643. # Calculate the value.
  644. for i in range(0,data_format[1]):
  645. if len(hex(byte_frame[data_format[1]-1-i]))==4:
  646. Buffer = Buffer + hex(byte_frame[data_format[1]-1-i])[2:]
  647. else:
  648. Buffer = Buffer + '0' + hex(byte_frame[data_format[1]-1-i])[2:]
  649. # Return the value of the Byte-Frame.
  650. return int(Buffer,16)
  651. # It checks the argument "data_format" for type "Format" or "Short Integer" and check the length/type of "byte_frame", depending
  652. # of the data_format. It raises an ValueError if the checks failed, otherwise it calculate and returns the value of the Byte-Frame.
  653. elif data_format==Xcom_API._format_format or data_format==Xcom_API._format_short_int:
  654. if not len(byte_frame)==data_format[1] or not isinstance(byte_frame[0], int) or not isinstance(byte_frame[1], int):
  655. raise ValueError('Invalid \"byte_frame\" for the data_format of type \"Format\" or \"Short Integer\"!')
  656. else:
  657. # Define a Buffer.
  658. Buffer = '0x'
  659. # Calculate the value.
  660. for i in range(0,data_format[1]):
  661. if len(hex(byte_frame[data_format[1]-1-i]))==4:
  662. Buffer = Buffer + hex(byte_frame[data_format[1]-1-i])[2:]
  663. else:
  664. Buffer = Buffer + '0' + hex(byte_frame[data_format[1]-1-i])[2:]
  665. # Return the value of the Byte-Frame.
  666. if int(Buffer,16)<32768:
  667. return int(Buffer,16)
  668. else:
  669. return (-65536 + int(Buffer,16))
  670. # It checks the argument "data_format" for type "Enum" or "Short Enum" and check the length/type of "byte_frame", depending of the
  671. # data_format. It raises an ValueError if the checks failed, otherwise it calculate and returns the value of the Byte-Frame.
  672. elif data_format==Xcom_API._format_enum or data_format==Xcom_API._format_short_enum:
  673. if not len(byte_frame)==data_format[1] or not isinstance(byte_frame[0], int) or not isinstance(byte_frame[1], int):
  674. raise ValueError('Invalid \"byte_frame\" for the data_format of type \"Enum\" or \"Short Enum\"!')
  675. else:
  676. # Define a Buffer.
  677. Buffer = '0x'
  678. # Calculate the value.
  679. for i in range(0,data_format[1]):
  680. if len(hex(byte_frame[data_format[1]-1-i]))==4:
  681. Buffer = Buffer + hex(byte_frame[data_format[1]-1-i])[2:]
  682. else:
  683. Buffer = Buffer + '0' + hex(byte_frame[data_format[1]-1-i])[2:]
  684. # Return the value of the Byte-Frame.
  685. if int(Buffer,16)<32768:
  686. return int(Buffer,16)
  687. else:
  688. raise ValueError('Invalid \"byte_frame\" for the data_format of type \"Enum\" or \"Short Enum\"!')
  689. # It checks the argument "data_format" for type "Long Enum" and check the length/type of "byte_frame", depending of the data_format.
  690. # It raises an ValueError if the checks failed, otherwise it calculate and returns the value of the Byte-Frame.
  691. elif data_format==Xcom_API._format_long_enum:
  692. if (not len(byte_frame)==data_format[1] or not isinstance(byte_frame[0], int) or not isinstance(byte_frame[1], int)
  693. or not isinstance(byte_frame[2], int) or not isinstance(byte_frame[3], int)):
  694. raise ValueError('Invalid \"byte_frame" for the data_format of type \"Long Enum\"!')
  695. else:
  696. # Define a Buffer.
  697. Buffer = '0x'
  698. # Calculate the value.
  699. for i in range(0,data_format[1]):
  700. if len(hex(byte_frame[data_format[1]-1-i]))==4:
  701. Buffer = Buffer + hex(byte_frame[data_format[1]-1-i])[2:]
  702. else:
  703. Buffer = Buffer + '0' + hex(byte_frame[data_format[1]-1-i])[2:]
  704. # Return the value of the Byte-Frame.
  705. if int(Buffer,16)<2147483648:
  706. return int(Buffer,16)
  707. else:
  708. raise ValueError('Invalid \"byte_frame" for the data_format of type \"Long Enum\"!')
  709. # It checks the argument "data_format" for type "INT32" and check the length/type of "byte_frame", depending of the data_format.
  710. # It raises an ValueError if the checks failed, otherwise it calculate and returns the value of the Byte-Frame.
  711. elif data_format==Xcom_API._format_int32:
  712. if (not len(byte_frame)==data_format[1] or not isinstance(byte_frame[0], int) or not isinstance(byte_frame[1], int)
  713. or not isinstance(byte_frame[2], int) or not isinstance(byte_frame[3], int)):
  714. raise ValueError('Invalid \"byte_frame\" for the data_format of type \"INT32\"!')
  715. else:
  716. # Define a Buffer.
  717. Buffer = '0x'
  718. # Calculate the value.
  719. for i in range(0,data_format[1]):
  720. if len(hex(byte_frame[data_format[1]-1-i]))==4:
  721. Buffer = Buffer + hex(byte_frame[data_format[1]-1-i])[2:]
  722. else:
  723. Buffer = Buffer + '0' + hex(byte_frame[data_format[1]-1-i])[2:]
  724. # Return the value of the Byte-Frame.
  725. if int(Buffer,16)<2147483648:
  726. return int(Buffer,16)
  727. else:
  728. return (-4294967296 + int(Buffer,16))
  729. # It checks the argument "data_format" for type "Float" and check the length/type of "byte_frame", depending of the data_format.
  730. # It raises an ValueError if the checks failed, otherwise it calculate and returns the value of the Byte-Frame.
  731. elif data_format==Xcom_API._format_float:
  732. if (not len(byte_frame)==data_format[1] or not isinstance(byte_frame[0], int) or not isinstance(byte_frame[1], int)
  733. or not isinstance(byte_frame[2], int) or not isinstance(byte_frame[3], int)):
  734. raise ValueError('Invalid \"byte_frame\" for the data_format of type \"Float\"!')
  735. else:
  736. # Define a Buffer.
  737. Buffer = bytearray([byte_frame[3],byte_frame[2],byte_frame[1],byte_frame[0]])
  738. # Calculate and return the value of the Byte-Frame.
  739. return struct.unpack("!f",Buffer)[0]
  740. # It raises an Error, if the argument "format" doesn't fit.
  741. else:
  742. raise ValueError('data_format is unknown!')
  743. # This Method does a Frame-Check. It checks the startbyte, Frame-Length, the checksum and the response-flags. It returns a
  744. # boolean-value of the result.
  745. def __frame_check(self,bytearray_of_frame):
  746. """
  747. ### Description:
  748. This Method does a Frame-Check. It checks the startbyte, Frame-Length, the checksum and the response-flags. It returns a
  749. boolean-value of the result.
  750. ### Arguments:
  751. The **<self>** argument must be an object. The **<bytearray_of_frame>** argument is a complete Byte_frame.
  752. ### Return-Value:
  753. This Method return a **boolean**.
  754. ### Example-Code:
  755. ```>>> Object = Xcom_API()
  756. >>> Byte_Frame = [0xAA, 0x37, 0x65, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0xA, 0x0, 0xA6, 0x5E, 0x2, 0x2, 0x2, 0x0, 0x53, 0x4, 0x0, 0x0, 0x5, 0x0, 0x61, 0x3C]
  757. >>> Check = Xcom_API.__frame_check(Object,Byte_Frame)
  758. >>> Check
  759. True
  760. **Or if you are not using this function inside the API:**
  761. ```>>> Object = Xcom_API()
  762. >>> Byte_Frame = [0xAA, 0x37, 0x65, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0xA, 0x0, 0xA6, 0x5E, 0x2, 0x2, 0x2, 0x0, 0x53, 0x4, 0x0, 0x0, 0x5, 0x0, 0x61, 0x3C]
  763. >>> Check = Xcom_API._Xcom_API__frame_check(Object,Byte_Frame)
  764. >>> Check
  765. True
  766. """
  767. # Define Buffer for Frame_check.
  768. Buffer = list(bytearray_of_frame)
  769. try:
  770. # Check Start-Byte available
  771. if not Buffer[0]==0xAA:
  772. raise ValueError('Can\'t find Start-Frame (0xAA)')
  773. # Check checksum if activated and check Frame-Length
  774. if self.__crc and len(Buffer)>=14:
  775. # check Header-Checksum
  776. if not Xcom_API.__calculate_checksum(Buffer[1:12])==Buffer[12:14]:
  777. raise ValueError('Header-Checksum wrong!')
  778. # check Frame-Length
  779. if not len(Buffer)==(Xcom_API.__byte_frame_to_value(Buffer[10:12],Xcom_API._format_short_int) + 16):
  780. raise ValueError('Frame is not complete!')
  781. # check Data-Checksum
  782. if not Xcom_API.__calculate_checksum(Buffer[14:(len(Buffer)-2)])==Buffer[(len(Buffer)-2):len(Buffer)]:
  783. raise ValueError('Data-Checksum wrong!')
  784. elif not self.__crc and len(Buffer)>=14:
  785. # check Frame-Length
  786. if not len(Buffer)==(Xcom_API.__byte_frame_to_value(Buffer[10:12],Xcom_API._format_short_int) + 16):
  787. raise ValueError('Frame is not complete!')
  788. else:
  789. raise ValueError('Frame is not complete!')
  790. # Check Response-Flags
  791. if not Buffer[14]>0:
  792. raise ValueError('Frame is not a Response-Frame!')
  793. return True
  794. except IndexError:
  795. raise ValueError('Frame is not complete!')
  796. ##################################################################################################################################
  797. # Public-Methods #
  798. ##################################################################################################################################
  799. # This method is used to generate a Byte-Frame for a 'read'-instruction. It Returns a bytearray.
  800. def get_read_frame_ext(self, object_type, object_id, property_id):
  801. """
  802. ### Description:
  803. This method is used to generate a Byte-Frame for a 'read'-instruction. It Returns a bytearray.
  804. ### Arguments:
  805. The **<self>** argument is pointing to the object, which calls the method.
  806. The **<object_type>** argument indicates the type of the **<object_id>**. The following shows the possibilities:
  807. +-+-+
  808. | | |
  809. +=+=+
  810. | _object_type_info | = 1 |
  811. +-+-+
  812. | _object_type_parameter | = 2 |
  813. +-+-+
  814. | _object_type_message | = 3 |
  815. +-+-+
  816. | _object_type_datalog_field | = 5 |
  817. +-+-+
  818. | _object_type_datalog_transfer | = 257 |
  819. +-+-+
  820. The **<object_id>** argument indicates, which id should be read. You can find a list of all id's in the communication protocoll
  821. at http://www.studer-innotec.com/de/downloads/.
  822. The **<property_id>** argument indicates, which type the property_data has, which you want to read. The following shows the possibilities:
  823. +-+-+
  824. | | |
  825. +=+=+
  826. | _property_id_value | = 1 |
  827. +-+-+
  828. | _property_id_string | = 1 |
  829. +-+-+
  830. | _property_id_value_qsp | = 5 |
  831. +-+-+
  832. | _property_id_min_qsp | = 6 |
  833. +-+-+
  834. | _property_id_max_qsp | = 7 |
  835. +-+-+
  836. | _property_id_level_qsp | = 8 |
  837. +-+-+
  838. | _property_id_unsaved_value_qsp | = 13 |
  839. +-+-+
  840. | _property_id_invalid_Action | = 0 |
  841. +-+-+
  842. | _property_id_sd_start | = 21 |
  843. +-+-+
  844. | _property_id_sd_datablock | = 22 |
  845. +-+-+
  846. | _property_id_sd_ack_continue | = 23 |
  847. +-+-+
  848. | _property_id_sd_nack_retry | = 24 |
  849. +-+-+
  850. | _property_id_sd_abort | = 25 |
  851. +-+-+
  852. | _property_id_sd_finish | = 26 |
  853. +-+-+
  854. ### Return-Value:
  855. This Method return a **bytearray** of the frame.
  856. ### Example-Code:
  857. ```>>> Object = Xcom_API()
  858. >>> input_current = 3116
  859. >>> Byte_frame = Object.get_read_frame_ext(Xcom_API._object_type_info, input_current, Xcom_API._property_id_value)
  860. >>> Byte_frame
  861. bytearray(b'\\xAA\\x00\\x01\\x00\\x00\\x00\\x65\\x00\\x00\\x00\\x0A\\x00\\x6F\\x71\\x00\\x01\\x01\\x00\\x2C\\x0C\\x00\\x00\\x01\\x00\\x3A\\x4D')
  862. """
  863. # Create Buffer
  864. Buffer = []
  865. # Append Buffer with Start-Byte.
  866. Buffer.append(Xcom_API.__start_byte)
  867. # Append Buffer with Frame-Flags.
  868. Buffer.append(Xcom_API.__frame_flags)
  869. # Extend Buffer with Source-Address.
  870. Buffer.extend(Xcom_API.__value_to_byte_frame(self.__source,Xcom_API._format_int32))
  871. # Extend Buffer with Destination-Address.
  872. Buffer.extend(Xcom_API.__value_to_byte_frame(self.__dest,Xcom_API._format_int32))
  873. # Extend Buffer with Data-Length.
  874. Buffer.extend(Xcom_API.__value_to_byte_frame(Xcom_API.__data_frame,Xcom_API._format_short_int))
  875. # Extend Buffer with Header-Checksum.
  876. Buffer.extend(Xcom_API.__calculate_checksum(Buffer[1:len(Buffer)]))
  877. # Append Buffer with Data-Flags.
  878. Buffer.append(Xcom_API.__data_flags)
  879. # Append Buffer with Service_ID.
  880. Buffer.append(Xcom_API.__service_read)
  881. # Extend Buffer with Opject_Type.
  882. Buffer.extend(Xcom_API.__value_to_byte_frame(object_type,Xcom_API._format_short_int))
  883. # Extend Buffer with Object_ID.
  884. Buffer.extend(Xcom_API.__value_to_byte_frame(object_id,Xcom_API._format_int32))
  885. # Extend Buffer with Property_ID.
  886. Buffer.extend(Xcom_API.__value_to_byte_frame(property_id,Xcom_API._format_short_int))
  887. # Extend Buffer with Data-Checksum.
  888. Buffer.extend(Xcom_API.__calculate_checksum(Buffer[14:len(Buffer)]))
  889. # Return Byte-Frame.
  890. return bytearray(Buffer)
  891. # This method is used to generate a Byte-Frame for a 'write'-instruction. It Returns a List of Bytes.
  892. def get_write_frame_ext(self, object_type, object_id, property_id, property_data, data_format):
  893. """
  894. ### Description:
  895. This method is used to generate a Byte-Frame for a 'write'-instruction. It Returns a bytearray.
  896. ### Arguments:
  897. The **<self>** argument is pointing to the object, which calls the method.
  898. The **<object_type>** argument indicates the type of the **<object_id>**. The following shows the possibilities:
  899. +-+-+
  900. | | |
  901. +=+=+
  902. | _object_type_info | = 1 |
  903. +-+-+
  904. | _object_type_parameter | = 2 |
  905. +-+-+
  906. | _object_type_message | = 3 |
  907. +-+-+
  908. | _object_type_datalog_field | = 5 |
  909. +-+-+
  910. | _object_type_datalog_transfer | = 257 |
  911. +-+-+
  912. The **<object_id>** argument indicates, which id should be written. You can find a list of all id's in the communication protocoll
  913. at http://www.studer-innotec.com/de/downloads/.
  914. The **<property_id>** argument indicates, which type the property_data has, which you want to read. The following shows the possibilities:
  915. +-+-+
  916. | | |
  917. +=+=+
  918. | _property_id_value | = 1 |
  919. +-+-+
  920. | _property_id_string | = 1 |
  921. +-+-+
  922. | _property_id_value_qsp | = 5 |
  923. +-+-+
  924. | _property_id_min_qsp | = 6 |
  925. +-+-+
  926. | _property_id_max_qsp | = 7 |
  927. +-+-+
  928. | _property_id_level_qsp | = 8 |
  929. +-+-+
  930. | _property_id_unsaved_value_qsp | = 13 |
  931. +-+-+
  932. | _property_id_invalid_Action | = 0 |
  933. +-+-+
  934. | _property_id_sd_start | = 21 |
  935. +-+-+
  936. | _property_id_sd_datablock | = 22 |
  937. +-+-+
  938. | _property_id_sd_ack_continue | = 23 |
  939. +-+-+
  940. | _property_id_sd_nack_retry | = 24 |
  941. +-+-+
  942. | _property_id_sd_abort | = 25 |
  943. +-+-+
  944. | _property_id_sd_finish | = 26 |
  945. +-+-+
  946. The **<property_data>** argument is the value you want to send. The format depends of the **<data_format>** argument.
  947. For the **<data_format>** argument use one of the following formats:
  948. +-+-+
  949. | | |
  950. +=+=+
  951. | _format_bool | = [1, 1] |
  952. +-+-+
  953. | _format_format | = [2, 2] |
  954. +-+-+
  955. | _format_short_int | = [3, 2] |
  956. +-+-+
  957. | _format_enum | = [4, 2] |
  958. +-+-+
  959. | _format_short_enum | = [5, 2] |
  960. +-+-+
  961. | _format_long_enum | = [6, 4] |
  962. +-+-+
  963. | _format_error | = [7, 2] |
  964. +-+-+
  965. | _format_int32 | = [8, 4] |
  966. +-+-+
  967. | _format_float | = [9, 4] |
  968. +-+-+
  969. | _format_byte | = [10, 1] |
  970. +-+-+
  971. ### Return-Value:
  972. This Method return a **bytearray** of the frame.
  973. ### Example-Code:
  974. ```>>> Object = Xcom_API()
  975. >>> Equalization_current = 1290
  976. >>> Data_in_Ampere = 120.0
  977. >>> Byte_frame = Object.get_write_frame_ext(Xcom_API._object_type_parameter, Equalization_current, Xcom_API._property_id_value, Data_in_Ampere, Xcom_API._format_float)
  978. >>> Byte_frame
  979. bytearray(b'\\xAA\\x00\\x01\\x00\\x00\\x00\\x65\\x00\\x00\\x00\\x0E\\x00\\x73\\x79\\x00\\x02\\x02\\x00\\x0A\\x05\\x00\\x00\\x01\\x00\\x00\\x00\\xF0\\x42\\x45\\xDD')
  980. """
  981. # Create Buffer
  982. Buffer = []
  983. # Append Buffer with Start-Byte.
  984. Buffer.append(Xcom_API.__start_byte)
  985. # Append Buffer with Frame-Flags.
  986. Buffer.append(Xcom_API.__frame_flags)
  987. # Extend Buffer with Source-Address.
  988. Buffer.extend(Xcom_API.__value_to_byte_frame(self.__source,Xcom_API._format_int32))
  989. # Extend Buffer with Destination-Address.
  990. Buffer.extend(Xcom_API.__value_to_byte_frame(self.__dest,Xcom_API._format_int32))
  991. # Extend Buffer with Data-Length.
  992. Buffer.extend(Xcom_API.__value_to_byte_frame(Xcom_API.__data_frame + data_format[1],Xcom_API._format_short_int))
  993. # Extend Buffer with Header-Checksum.
  994. Buffer.extend(Xcom_API.__calculate_checksum(Buffer[1:len(Buffer)]))
  995. # Append Buffer with Data-Flags.
  996. Buffer.append(Xcom_API.__data_flags)
  997. # Append Buffer with Service_ID.
  998. Buffer.append(Xcom_API.__service_write)
  999. # Extend Buffer with Opject_Type.
  1000. Buffer.extend(Xcom_API.__value_to_byte_frame(object_type,Xcom_API._format_short_int))
  1001. # Extend Buffer with Object_ID.
  1002. Buffer.extend(Xcom_API.__value_to_byte_frame(object_id,Xcom_API._format_int32))
  1003. # Extend Buffer with Property_ID.
  1004. Buffer.extend(Xcom_API.__value_to_byte_frame(property_id,Xcom_API._format_short_int))
  1005. # Extend Buffer with Property_Data.
  1006. Buffer.extend(Xcom_API.__value_to_byte_frame(property_data,data_format))
  1007. # Extend Buffer with Data-Checksum.
  1008. Buffer.extend(Xcom_API.__calculate_checksum(Buffer[14:len(Buffer)]))
  1009. # Return Byte-Frame.
  1010. return bytearray(Buffer)
  1011. # This method is used to decode Data from the received Byte-Frame, what you get from the xtender-system.
  1012. # It returns a List with the result of the returned Data and the Data itself.
  1013. def get_data_from_frame_ext(self, bytearray_of_frame, data_format):
  1014. """
  1015. ### Description:
  1016. This method is used to decode Data from the received Byte-Frame, what you get from the xtender-system.
  1017. If CRC-Check is active, it will check the byte-frame and raises a Value_Error, if a CRC-Error was detected.
  1018. It returns a List with the result of the returned Data and the Data itself.
  1019. ### Arguments:
  1020. The **<self>** argument is pointing to the object, which calls the method.
  1021. The **<bytearray_of_frame>** argument is the frame what you get, when you receive data from the serial port.
  1022. The **<data_format>** argument is needed to decode the value. For the **<data_format>** argument use one of the following formats:
  1023. +-+-+
  1024. | | |
  1025. +=+=+
  1026. | _format_bool | = [1, 1] |
  1027. +-+-+
  1028. | _format_format | = [2, 2] |
  1029. +-+-+
  1030. | _format_short_int | = [3, 2] |
  1031. +-+-+
  1032. | _format_enum | = [4, 2] |
  1033. +-+-+
  1034. | _format_short_enum | = [5, 2] |
  1035. +-+-+
  1036. | _format_long_enum | = [6, 4] |
  1037. +-+-+
  1038. | _format_error | = [7, 2] |
  1039. +-+-+
  1040. | _format_int32 | = [8, 4] |
  1041. +-+-+
  1042. | _format_float | = [9, 4] |
  1043. +-+-+
  1044. | _format_byte | = [10, 1] |
  1045. +-+-+
  1046. ### Return-Value:
  1047. This Method return a **list** with two elements. The First is a **boolean** value, which is **True**, if the xtender-system detects an error and the second
  1048. element of the **list** then contains the error-id. If no error occures, then the first element is **False** und the second element contains the answer of your request.
  1049. The returned value of the second element is a **string**, **int** or **float**, depending of the service (read/write) of the request frame and of the
  1050. **<data_format>** argument.
  1051. ### Example-Code:
  1052. ```>>> Object = Xcom_API()
  1053. >>> Frame = bytearray(b'\\xAA\\x37\\x65\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0E\\x00\\xAA\\x66\\x02\\x01\\x02\\x00\\x53\\x04\\x00\\x00\\x05\\x00\\x00\\xD0\\x14\\x42\\x86\\x8D')
  1054. >>> Answer = Object.get_data_from_frame_ext(Frame, Xcom_API._format_float)
  1055. >>> Answer
  1056. [False, 37.203125]
  1057. """
  1058. # Do a Frame-Check. If it fails, it returns a ValueError.
  1059. if not self.__frame_check_done:
  1060. if not Xcom_API.__frame_check(self, bytearray_of_frame):
  1061. raise ValueError('Frame-Check failed!')
  1062. self.__frame_check_done = False
  1063. # Check Frame for an Error and return the value.
  1064. if bytearray_of_frame[14] == 2:
  1065. # Check if property_data available
  1066. if len(bytearray_of_frame) == 26:
  1067. return [False,'value_set']
  1068. else:
  1069. return [False, Xcom_API.__byte_frame_to_value(bytearray_of_frame[24:(24+data_format[1])],data_format)]
  1070. else:
  1071. return [True, Xcom_API.__byte_frame_to_value(bytearray_of_frame[24:(24+Xcom_API._format_error[1])],Xcom_API._format_error)]
  1072. # This method is used to generate a Byte-Frame for a 'read'-instruction. It can only be used with a known Object_ID, otherwise it
  1073. # will raise a Value_Error. It Returns a bytearray.
  1074. def get_read_frame(self, object_id):
  1075. """
  1076. ### Description:
  1077. This method is used to generate a Byte-Frame for a 'read'-instruction. It can only be used with a known Object_ID, otherwise it
  1078. will raise a Value_Error. It Returns a bytearray.
  1079. ### Arguments:
  1080. The **<self>** argument is pointing to the object, which calls the method.
  1081. The **<object_id>** argument indicates, which id should be read. The following shows the possibilities:
  1082. +-+-+
  1083. | Information-Numbers | |
  1084. +=+=+
  1085. | _info_battery_voltage | = 3000 |
  1086. +-+-+
  1087. | _info_battery_temperature | = 3001 |
  1088. +-+-+
  1089. | _info_battery_charge_current | = 3005 |
  1090. +-+-+
  1091. | _info_battery_voltage_ripple | = 3006 |
  1092. +-+-+
  1093. | _info_state_of_charge | = 3007 |
  1094. +-+-+
  1095. | _info_number_of_battery_elements | = 3050 |
  1096. +-+-+
  1097. | _info_input_voltage | = 3011 |
  1098. +-+-+
  1099. | _info_input_current | = 3012 |
  1100. +-+-+
  1101. | _info_input_frequency | = 3084 |
  1102. +-+-+
  1103. | _info_input_power | = 3138 |
  1104. +-+-+
  1105. | _info_output_voltage | = 3021 |
  1106. +-+-+
  1107. | _info_output_current | = 3022 |
  1108. +-+-+
  1109. | _info_output_frequency | = 3085 |
  1110. +-+-+
  1111. | _info_output_power | = 3139 |
  1112. +-+-+
  1113. | _info_operating_state | = 3028 |
  1114. +-+-+
  1115. | _info_boost_active | = 3019 |
  1116. +-+-+
  1117. | _info_state_of_inverter | = 3049 |
  1118. +-+-+
  1119. | _info_state_of_transfer_relay | = 3020 |
  1120. +-+-+
  1121. | _info_state_of_output_relay | = 3030 |
  1122. +-+-+
  1123. | _info_state_of_aux_relay_1 | = 3031 |
  1124. +-+-+
  1125. | _info_state_of_aux_relay_2 | = 3032 |
  1126. +-+-+
  1127. | _info_state_of_ground_relay | = 3074 |
  1128. +-+-+
  1129. | _info_state_of_neutral_transfer_relay | = 3075 |
  1130. +-+-+
  1131. | _info_state_of_remote_entry | = 3086 |
  1132. +-+-+
  1133. +-+-+
  1134. | Parameter-Numbers | |
  1135. +=+=+
  1136. | _para_maximum_current_of_ac_source | = 1107 |
  1137. +-+-+
  1138. | _para_battery_charge_current | = 1138 |
  1139. +-+-+
  1140. | _para_smart_boost_allowed | = 1126 |
  1141. +-+-+
  1142. | _para_inverter_allowed | = 1124 |
  1143. +-+-+
  1144. | _para_type_of_detection_of_grid_loss | = 1552 |
  1145. +-+-+
  1146. | _para_charger_allowed | = 1125 |
  1147. +-+-+
  1148. | _para_charger_uses_only_power_from_ac | = 1646 |
  1149. +-+-+
  1150. | _para_ac_output_voltage | = 1286 |
  1151. +-+-+
  1152. | _para_inverter_frequency | = 1112 |
  1153. +-+-+
  1154. | _para_transfer_relay_allowed | = 1128 |
  1155. +-+-+
  1156. | _para_limitation_of_the_power_boost | = 1607 |
  1157. +-+-+
  1158. | _para_remote_entry_active | = 1545 |
  1159. +-+-+
  1160. ### Return-Value:
  1161. This Method return a **bytearray** of the frame.
  1162. ### Example-Code:
  1163. ```>>> Object = Xcom_API()
  1164. >>> Byte_frame = Object.get_read_frame(Xcom_API._info_battery_voltage)
  1165. >>> Byte_frame
  1166. bytearray(b'\\xAA\\x00\\x01\\x00\\x00\\x00\\x65\\x00\\x00\\x00\\x0A\\x00\\x6F\\x71\\x00\\x01\\x01\\x00\\xB8\\x0B\\x00\\x00\\x01\\x00\\xC5\\x90')
  1167. """
  1168. try:
  1169. # Read Object-ID infomations from Dictionary and store it into a Buffer.
  1170. Buffer = Xcom_API.__para_info_dict[object_id]
  1171. # Return a Byte-Frame from the Read-Extenion method.
  1172. return self.get_read_frame_ext(Buffer[0],object_id,Buffer[1])
  1173. except KeyError:
  1174. # If the Object_ID is unknown, the method raise a ValueError.
  1175. raise ValueError('Object_ID unknown!')
  1176. # This method is used to generate a Byte-Frame for a 'write'-instruction. It can only be used with a known Object_ID, otherwise it
  1177. # will raise a Value_Error. It Returns a bytearray.
  1178. def get_write_frame(self, object_id, property_data):
  1179. """
  1180. ### Description:
  1181. This method is used to generate a Byte-Frame for a 'write'-instruction. It can only be used with a known Object_ID, otherwise it
  1182. will raise a Value_Error. It Returns a bytearray.
  1183. ### Arguments:
  1184. The **<self>** argument is pointing to the object, which calls the method.
  1185. The **<object_id>** argument indicates, which id should be written. The following shows the possibilities:
  1186. +-+-+
  1187. | | |
  1188. +=+=+
  1189. | _para_maximum_current_of_ac_source | = 1107 |
  1190. +-+-+
  1191. | _para_battery_charge_current | = 1138 |
  1192. +-+-+
  1193. | _para_smart_boost_allowed | = 1126 |
  1194. +-+-+
  1195. | _para_inverter_allowed | = 1124 |
  1196. +-+-+
  1197. | _para_type_of_detection_of_grid_loss | = 1552 |
  1198. +-+-+
  1199. | _para_charger_allowed | = 1125 |
  1200. +-+-+
  1201. | _para_charger_uses_only_power_from_ac | = 1646 |
  1202. +-+-+
  1203. | _para_ac_output_voltage | = 1286 |
  1204. +-+-+
  1205. | _para_inverter_frequency | = 1112 |
  1206. +-+-+
  1207. | _para_transfer_relay_allowed | = 1128 |
  1208. +-+-+
  1209. | _para_limitation_of_the_power_boost | = 1607 |
  1210. +-+-+
  1211. | _para_remote_entry_active | = 1545 |
  1212. +-+-+
  1213. The **<property_data>** argument is the value you want to send.
  1214. ### Return-Value:
  1215. This Method return a **bytearray** of the frame.
  1216. ### Example-Code:
  1217. ```>>> Object = Xcom_API()
  1218. >>> Data_in_Ampere = 32.0
  1219. >>> Byte_frame = Object.get_write_frame(Xcom_API._para_maximum_current_of_ac_source, Data_in_Ampere)
  1220. >>> Byte_frame
  1221. bytearray(b'\\xAA\\x00\\x01\\x00\\x00\\x00\\x65\\x00\\x00\\x00\\x0E\\x00\\x73\\x79\\x00\\x02\\x02\\x00\\x53\\x04\\x00\\x00\\x05\\x00\\x00\\x00\\x00\\x42\\xA1\\xE6')
  1222. """
  1223. try:
  1224. # Read Object-ID infomations from Dictionary and store it into a Buffer.
  1225. Buffer = Xcom_API.__para_info_dict[object_id]
  1226. # Cheack for parameter
  1227. if not Buffer[0] == Xcom_API._object_type_parameter:
  1228. raise KeyError
  1229. # Return a Byte-Frame from the Read-Extenion method.
  1230. return self.get_write_frame_ext(Buffer[0],object_id,Buffer[1],property_data,Buffer[2])
  1231. except KeyError:
  1232. # If the Object_ID is unknown, the method raise a ValueError.
  1233. raise ValueError('Object_ID unknown!')
  1234. # This method is used to decode Data from the received Byte-Frame, what you get from the xtender-system. It can only be used with a known Object_ID,
  1235. # otherwise it will raise a Value_Error. It returns a List with the result of the returned Data and the Data itself.
  1236. def get_data_from_frame(self, bytearray_of_frame):
  1237. """
  1238. ### Description:
  1239. This method is used to decode Data from the received Byte-Frame, what you get from the xtender-system.
  1240. If CRC-Check is active, it will check the byte-frame and raises a Value_Error, if a CRC-Error was detected.
  1241. It can only be used with a known Object_ID, otherwise it will raise a Value_Error. It returns a List with the result of the returned Data and the Data itself.
  1242. ### Arguments:
  1243. The **<self>** argument is pointing to the object, which calls the method.
  1244. The **<bytearray_of_frame>** argument is the frame what you get, when you receive data from the serial port.
  1245. ### Return-Value:
  1246. This Method return a **list** with two elements. The First is a **boolean** value, which is **True**, if the xtender-system detects an error and the second
  1247. element of the **list** then contains the error-id. If no error occures, then the first element is **False** und the second element contains the answer of your request.
  1248. The returned value of the second element is a **string**, **int** or **float**, depending of the service (read/write) of the request frame and of the
  1249. **<data_format>** argument.
  1250. ### Example-Code:
  1251. ```>>> Object = Xcom_API()
  1252. >>> Frame = bytearray(b'\\xAA\\x37\\x65\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0E\\x00\\xAA\\x66\\x02\\x01\\x01\\x00\\xB8\\x0B\\x00\\x00\\x01\\x00\\x00\\x40\\x42\\x42\\x8B\\x46')
  1253. >>> Answer = Object.get_data_from_frame(Frame)
  1254. >>> Answer
  1255. [False, 48.5625]
  1256. """
  1257. try:
  1258. # Do a Frame-Check. If it fails, it returns a ValueError.
  1259. if Xcom_API.__frame_check(self, bytearray_of_frame):
  1260. self.__frame_check_done = True
  1261. else:
  1262. raise ValueError('Frame-Check failed!')
  1263. # Read Object-ID infomations from Dictionary and store it into a Buffer.
  1264. Buffer = Xcom_API.__para_info_dict[Xcom_API.__byte_frame_to_value(bytearray_of_frame[18:22],Xcom_API._format_int32)]
  1265. # Return a Byte-Frame from the Read-Extension method.
  1266. return self.get_data_from_frame_ext(bytearray_of_frame,Buffer[2])
  1267. except KeyError:
  1268. # If the Object_ID is unknown, the method raise a ValueError.
  1269. self.__frame_check_done = False
  1270. raise ValueError('Object_ID unknown!')
  1271. # This method is used to return the frame-flags as a binary.
  1272. def get_bin_from_frame_flags(self, bytearray_of_frame):
  1273. """
  1274. ### Description:
  1275. This method is used to return the frame-flags as a binary.
  1276. ### Arguments:
  1277. The **<self>** argument is pointing to the object, which calls the method.
  1278. The **<bytearray_of_frame>** argument is the frame what you get, when you receive data from the serial port.
  1279. ### Return-Value:
  1280. The returned value is type **binary**.
  1281. ### Example-Code:
  1282. ```>>> Object = Xcom_API()
  1283. >>> Frame = bytearray(b'\\xAA\\x37\\x65\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0E\\x00\\xAA\\x66\\x02\\x01\\x01\\x00\\xB8\\x0B\\x00\\x00\\x01\\x00\\x00\\x40\\x42\\x42\\x8B\\x46')
  1284. >>> Answer = Object.get_bin_from_frame_flags(Frame)
  1285. >>> Answer
  1286. 0b00110111
  1287. """
  1288. # Do a Frame-Check. If it fails, it returns a ValueError.
  1289. if not Xcom_API.__frame_check(self, bytearray_of_frame):
  1290. raise ValueError('Frame-Check failed!')
  1291. # Create a Buffer with binary Information.
  1292. Buffer = bin(bytearray_of_frame[1])
  1293. # Extend Buffer to 8-bit
  1294. for i in range(0,10-len(Buffer)):
  1295. Buffer = Buffer[0:2] + '0' + Buffer[2:]
  1296. # Return Buffer.
  1297. return Buffer
  1298. # This method is used to return the frame-flags as a list with explanation (string) for each bit, starting from LSB to MSB.
  1299. def get_text_from_frame_flags(self, bytearray_of_frame):
  1300. """
  1301. ### Description:
  1302. This method is used to return the frame-flags as a **list** with explanation (**string**) for each bit, starting with lsb.
  1303. ### Arguments:
  1304. The **<self>** argument is pointing to the object, which calls the method.
  1305. The **<bytearray_of_frame>** argument is the frame what you get, when you receive data from the serial port.
  1306. ### Return-Value:
  1307. The method returns a **list** with **strings** of explanation for each bit of the frame-flags, starting from LSB to MSB.
  1308. ### Example-Code:
  1309. ```>>> Object = Xcom_API()
  1310. >>> Frame = bytearray(b'\\xAA\\x37\\x65\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0E\\x00\\xAA\\x66\\x02\\x01\\x01\\x00\\xB8\\x0B\\x00\\x00\\x01\\x00\\x00\\x40\\x42\\x42\\x8B\\x46')
  1311. >>> Answer = Object.get_text_from_frame_flags(Frame)
  1312. >>> Answer
  1313. ['Messages are pending.','A reset or restart was carried out.','The SD-Card is present.','The SD-Card is not full.','New datalog file on the SD-Card.','Datalogger is supported.']
  1314. """
  1315. # Create Buffer and get binary from byte-frame.
  1316. Buffer = self.get_bin_from_frame_flags(bytearray_of_frame)
  1317. # Create Out-Buffer.
  1318. BufferOut = []
  1319. # Check bit 0.
  1320. if int(Buffer[9]) == 1:
  1321. BufferOut.append('Messages are pending.')
  1322. else:
  1323. BufferOut.append('No messages are pending.')
  1324. # Check bit 1.
  1325. if int(Buffer[8]) == 1:
  1326. BufferOut.append('A reset or restart was carried out.')
  1327. else:
  1328. BufferOut.append('No reset or restart was carried out.')
  1329. # Check bit 2.
  1330. if int(Buffer[7]) == 1:
  1331. BufferOut.append('The SD-Card is present.')
  1332. else:
  1333. BufferOut.append('No SD-Card is present')
  1334. # Check bit 3.
  1335. if int(Buffer[6]) == 1:
  1336. BufferOut.append('The SD-Card is full.')
  1337. else:
  1338. BufferOut.append('The SD-Card is not full.')
  1339. # Check bit 4.
  1340. if int(Buffer[5]) == 1:
  1341. BufferOut.append('New datalog file on the SD-Card.')
  1342. else:
  1343. BufferOut.append('No new datalog file on the SD-Card.')
  1344. # Check bit 5.
  1345. if int(Buffer[4]) == 1:
  1346. BufferOut.append('Datalogger is supported.')
  1347. else:
  1348. BufferOut.append('Datalogger is not supported.')
  1349. # Return list with Frame-flag informations.
  1350. return BufferOut
  1351. # This method is used to get the error message from the error-id.
  1352. def get_text_from_error_id(self, error_id):
  1353. """
  1354. ### Description:
  1355. This method is used to get the error message from the error-id.
  1356. ### Arguments:
  1357. The **<self>** argument is pointing to the object, which calls the method.
  1358. The **<error_id>** argument is an **int** from the xtender-system.
  1359. ### Return-Value:
  1360. The method returns a **strings** with the explanation of the error-id.
  1361. ### Example-Code:
  1362. ```>>> Object = Xcom_API()
  1363. >>> Error_ID = 0x0022
  1364. >>> Answer = Object.get_text_from_error_id(Error_ID)
  1365. >>> Answer
  1366. 'OBJECT_ID_NOT_FOUND'
  1367. """
  1368. try:
  1369. # Check ID and store error-message in Buffer
  1370. Buffer = Xcom_API.__error_code_dict[error_id]
  1371. # return error-message
  1372. return Buffer
  1373. except KeyError:
  1374. # If Error ID is unknown
  1375. return 'Error-ID is unknown.'