Xcom_API.py 78 KB

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