Xcom_API.py 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  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. It returns a List with the result of the returned Data and the Data itself.
  1018. ### Arguments:
  1019. The **<self>** argument is pointing to the object, which calls the method.
  1020. The **<bytearray_of_frame>** argument is the frame what you get, when you receive data from the serial port.
  1021. The **<data_format>** argument is needed to decode the value. For the **<data_format>** argument use one of the following formats:
  1022. +-+-+
  1023. | | |
  1024. +=+=+
  1025. | _format_bool | = [1, 1] |
  1026. +-+-+
  1027. | _format_format | = [2, 2] |
  1028. +-+-+
  1029. | _format_short_int | = [3, 2] |
  1030. +-+-+
  1031. | _format_enum | = [4, 2] |
  1032. +-+-+
  1033. | _format_short_enum | = [5, 2] |
  1034. +-+-+
  1035. | _format_long_enum | = [6, 4] |
  1036. +-+-+
  1037. | _format_error | = [7, 2] |
  1038. +-+-+
  1039. | _format_int32 | = [8, 4] |
  1040. +-+-+
  1041. | _format_float | = [9, 4] |
  1042. +-+-+
  1043. | _format_byte | = [10, 1] |
  1044. +-+-+
  1045. ### Return-Value:
  1046. This Method return a **list** with two elements. The First is a **boolean** value, which is **False**, if the xtender-system detects an error and the second
  1047. element of the **list** then contains the error-id. If no error occures, then the first element is **True** und the second element contains the answer of your request.
  1048. 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
  1049. **<data_format>** argument.
  1050. ### Example-Code:
  1051. ```>>> Object = Xcom_API()
  1052. >>> 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')
  1053. >>> Answer = Object.get_data_from_frame_ext(Frame, Xcom_API._format_float)
  1054. >>> Answer
  1055. [False, 37.203125]
  1056. """
  1057. # Do a Frame-Check. If it fails, it returns a ValueError.
  1058. if not self.__frame_check_done:
  1059. if not Xcom_API.__frame_check(self, bytearray_of_frame):
  1060. raise ValueError('Frame-Check failed!')
  1061. self.__frame_check_done = False
  1062. # Check Frame for an Error and return the value.
  1063. if bytearray_of_frame[14] == 2:
  1064. # Check if property_data available
  1065. if len(bytearray_of_frame) == 26:
  1066. return [False,'value_set']
  1067. else:
  1068. return [False, Xcom_API.__byte_frame_to_value(bytearray_of_frame[24:(24+data_format[1])],data_format)]
  1069. else:
  1070. return [True, Xcom_API.__byte_frame_to_value(bytearray_of_frame[24:(24+Xcom_API._format_error[1])],Xcom_API._format_error)]
  1071. # 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
  1072. # will raise a Value_Error. It Returns a bytearray.
  1073. def get_read_frame(self, object_id):
  1074. """
  1075. ### Description:
  1076. 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
  1077. will raise a Value_Error. It Returns a bytearray.
  1078. ### Arguments:
  1079. The **<self>** argument is pointing to the object, which calls the method.
  1080. The **<object_id>** argument indicates, which id should be read. The following shows the possibilities:
  1081. +-+-+
  1082. | Information-Numbers | |
  1083. +=+=+
  1084. | _info_battery_voltage | = 3000 |
  1085. +-+-+
  1086. | _info_battery_temperature | = 3001 |
  1087. +-+-+
  1088. | _info_battery_charge_current | = 3005 |
  1089. +-+-+
  1090. | _info_battery_voltage_ripple | = 3006 |
  1091. +-+-+
  1092. | _info_state_of_charge | = 3007 |
  1093. +-+-+
  1094. | _info_number_of_battery_elements | = 3050 |
  1095. +-+-+
  1096. | _info_input_voltage | = 3011 |
  1097. +-+-+
  1098. | _info_input_current | = 3012 |
  1099. +-+-+
  1100. | _info_input_frequency | = 3084 |
  1101. +-+-+
  1102. | _info_input_power | = 3138 |
  1103. +-+-+
  1104. | _info_output_voltage | = 3021 |
  1105. +-+-+
  1106. | _info_output_current | = 3022 |
  1107. +-+-+
  1108. | _info_output_frequency | = 3085 |
  1109. +-+-+
  1110. | _info_output_power | = 3139 |
  1111. +-+-+
  1112. | _info_operating_state | = 3028 |
  1113. +-+-+
  1114. | _info_boost_active | = 3019 |
  1115. +-+-+
  1116. | _info_state_of_inverter | = 3049 |
  1117. +-+-+
  1118. | _info_state_of_transfer_relay | = 3020 |
  1119. +-+-+
  1120. | _info_state_of_output_relay | = 3030 |
  1121. +-+-+
  1122. | _info_state_of_aux_relay_1 | = 3031 |
  1123. +-+-+
  1124. | _info_state_of_aux_relay_2 | = 3032 |
  1125. +-+-+
  1126. | _info_state_of_ground_relay | = 3074 |
  1127. +-+-+
  1128. | _info_state_of_neutral_transfer_relay | = 3075 |
  1129. +-+-+
  1130. | _info_state_of_remote_entry | = 3086 |
  1131. +-+-+
  1132. +-+-+
  1133. | Parameter-Numbers | |
  1134. +=+=+
  1135. | _para_maximum_current_of_ac_source | = 1107 |
  1136. +-+-+
  1137. | _para_battery_charge_current | = 1138 |
  1138. +-+-+
  1139. | _para_smart_boost_allowed | = 1126 |
  1140. +-+-+
  1141. | _para_inverter_allowed | = 1124 |
  1142. +-+-+
  1143. | _para_type_of_detection_of_grid_loss | = 1552 |
  1144. +-+-+
  1145. | _para_charger_allowed | = 1125 |
  1146. +-+-+
  1147. | _para_charger_uses_only_power_from_ac | = 1646 |
  1148. +-+-+
  1149. | _para_ac_output_voltage | = 1286 |
  1150. +-+-+
  1151. | _para_inverter_frequency | = 1112 |
  1152. +-+-+
  1153. | _para_transfer_relay_allowed | = 1128 |
  1154. +-+-+
  1155. | _para_limitation_of_the_power_boost | = 1607 |
  1156. +-+-+
  1157. | _para_remote_entry_active | = 1545 |
  1158. +-+-+
  1159. ### Return-Value:
  1160. This Method return a **bytearray** of the frame.
  1161. ### Example-Code:
  1162. ```>>> Object = Xcom_API()
  1163. >>> Byte_frame = Object.get_read_frame(Xcom_API._info_battery_voltage)
  1164. >>> Byte_frame
  1165. 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')
  1166. """
  1167. try:
  1168. # Read Object-ID infomations from Dictionary and store it into a Buffer.
  1169. Buffer = Xcom_API.__para_info_dict[object_id]
  1170. # Return a Byte-Frame from the Read-Extenion method.
  1171. return self.get_read_frame_ext(Buffer[0],object_id,Buffer[1])
  1172. except KeyError:
  1173. # If the Object_ID is unknown, the method raise a ValueError.
  1174. raise ValueError('Object_ID unknown!')
  1175. # 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
  1176. # will raise a Value_Error. It Returns a bytearray.
  1177. def get_write_frame(self, object_id, property_data):
  1178. """
  1179. ### Description:
  1180. 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
  1181. will raise a Value_Error. It Returns a bytearray.
  1182. ### Arguments:
  1183. The **<self>** argument is pointing to the object, which calls the method.
  1184. The **<object_id>** argument indicates, which id should be written. The following shows the possibilities:
  1185. +-+-+
  1186. | | |
  1187. +=+=+
  1188. | _para_maximum_current_of_ac_source | = 1107 |
  1189. +-+-+
  1190. | _para_battery_charge_current | = 1138 |
  1191. +-+-+
  1192. | _para_smart_boost_allowed | = 1126 |
  1193. +-+-+
  1194. | _para_inverter_allowed | = 1124 |
  1195. +-+-+
  1196. | _para_type_of_detection_of_grid_loss | = 1552 |
  1197. +-+-+
  1198. | _para_charger_allowed | = 1125 |
  1199. +-+-+
  1200. | _para_charger_uses_only_power_from_ac | = 1646 |
  1201. +-+-+
  1202. | _para_ac_output_voltage | = 1286 |
  1203. +-+-+
  1204. | _para_inverter_frequency | = 1112 |
  1205. +-+-+
  1206. | _para_transfer_relay_allowed | = 1128 |
  1207. +-+-+
  1208. | _para_limitation_of_the_power_boost | = 1607 |
  1209. +-+-+
  1210. | _para_remote_entry_active | = 1545 |
  1211. +-+-+
  1212. The **<property_data>** argument is the value you want to send.
  1213. ### Return-Value:
  1214. This Method return a **bytearray** of the frame.
  1215. ### Example-Code:
  1216. ```>>> Object = Xcom_API()
  1217. >>> Data_in_Ampere = 32.0
  1218. >>> Byte_frame = Object.get_write_frame(Xcom_API._para_maximum_current_of_ac_source, Data_in_Ampere)
  1219. >>> Byte_frame
  1220. 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')
  1221. """
  1222. try:
  1223. # Read Object-ID infomations from Dictionary and store it into a Buffer.
  1224. Buffer = Xcom_API.__para_info_dict[object_id]
  1225. # Cheack for parameter
  1226. if not Buffer[0] == Xcom_API._object_type_parameter:
  1227. raise KeyError
  1228. # Return a Byte-Frame from the Read-Extenion method.
  1229. return self.get_write_frame_ext(Buffer[0],object_id,Buffer[1],property_data,Buffer[2])
  1230. except KeyError:
  1231. # If the Object_ID is unknown, the method raise a ValueError.
  1232. raise ValueError('Object_ID unknown!')
  1233. # 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,
  1234. # otherwise it will raise a Value_Error. It returns a List with the result of the returned Data and the Data itself.
  1235. def get_data_from_frame(self, bytearray_of_frame):
  1236. """
  1237. ### Description:
  1238. 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,
  1239. otherwise it will raise a Value_Error. It returns a List with the result of the returned Data and the Data itself.
  1240. ### Arguments:
  1241. The **<self>** argument is pointing to the object, which calls the method.
  1242. The **<bytearray_of_frame>** argument is the frame what you get, when you receive data from the serial port.
  1243. ### Return-Value:
  1244. This Method return a **list** with two elements. The First is a **boolean** value, which is **False**, if the xtender-system detects an error and the second
  1245. element of the **list** then contains the error-id. If no error occures, then the first element is **True** und the second element contains the answer of your request.
  1246. 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
  1247. **<data_format>** argument.
  1248. ### Example-Code:
  1249. ```>>> Object = Xcom_API()
  1250. >>> 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')
  1251. >>> Answer = Object.get_data_from_frame(Frame)
  1252. >>> Answer
  1253. [False, 48.5625]
  1254. """
  1255. try:
  1256. # Do a Frame-Check. If it fails, it returns a ValueError.
  1257. if Xcom_API.__frame_check(self, bytearray_of_frame):
  1258. self.__frame_check_done = True
  1259. else:
  1260. raise ValueError('Frame-Check failed!')
  1261. # Read Object-ID infomations from Dictionary and store it into a Buffer.
  1262. Buffer = Xcom_API.__para_info_dict[Xcom_API.__byte_frame_to_value(bytearray_of_frame[18:22],Xcom_API._format_int32)]
  1263. # Return a Byte-Frame from the Read-Extension method.
  1264. return self.get_data_from_frame_ext(bytearray_of_frame,Buffer[2])
  1265. except KeyError:
  1266. # If the Object_ID is unknown, the method raise a ValueError.
  1267. self.__frame_check_done = False
  1268. raise ValueError('Object_ID unknown!')
  1269. # This method is used to return the frame-flags as a binary.
  1270. def get_bin_from_frame_flags(self, bytearray_of_frame):
  1271. """
  1272. ### Description:
  1273. This method is used to return the frame-flags as a binary.
  1274. ### Arguments:
  1275. The **<self>** argument is pointing to the object, which calls the method.
  1276. The **<bytearray_of_frame>** argument is the frame what you get, when you receive data from the serial port.
  1277. ### Return-Value:
  1278. The returned value is type **binary**.
  1279. ### Example-Code:
  1280. ```>>> Object = Xcom_API()
  1281. >>> 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')
  1282. >>> Answer = Object.get_bin_from_frame_flags(Frame)
  1283. >>> Answer
  1284. 0b00110111
  1285. """
  1286. # Do a Frame-Check. If it fails, it returns a ValueError.
  1287. if not Xcom_API.__frame_check(self, bytearray_of_frame):
  1288. raise ValueError('Frame-Check failed!')
  1289. # Create a Buffer with binary Information.
  1290. Buffer = bin(bytearray_of_frame[1])
  1291. # Extend Buffer to 8-bit
  1292. for i in range(0,10-len(Buffer)):
  1293. Buffer = Buffer[0:2] + '0' + Buffer[2:]
  1294. # Return Buffer.
  1295. return Buffer
  1296. # This method is used to return the frame-flags as a list with explanation (string) for each bit, starting from LSB to MSB.
  1297. def get_text_from_frame_flags(self, bytearray_of_frame):
  1298. """
  1299. ### Description:
  1300. This method is used to return the frame-flags as a **list** with explanation (**string**) for each bit, starting with lsb.
  1301. ### Arguments:
  1302. The **<self>** argument is pointing to the object, which calls the method.
  1303. The **<bytearray_of_frame>** argument is the frame what you get, when you receive data from the serial port.
  1304. ### Return-Value:
  1305. The method returns a **list** with **strings** of explanation for each bit of the frame-flags, starting from LSB to MSB.
  1306. ### Example-Code:
  1307. ```>>> Object = Xcom_API()
  1308. >>> 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')
  1309. >>> Answer = Object.get_text_from_frame_flags(Frame)
  1310. >>> Answer
  1311. ['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.']
  1312. """
  1313. # Create Buffer and get binary from byte-frame.
  1314. Buffer = self.get_bin_from_frame_flags(bytearray_of_frame)
  1315. # Create Out-Buffer.
  1316. BufferOut = []
  1317. # Check bit 0.
  1318. if int(Buffer[9]) == 1:
  1319. BufferOut.append('Messages are pending.')
  1320. else:
  1321. BufferOut.append('No messages are pending.')
  1322. # Check bit 1.
  1323. if int(Buffer[8]) == 1:
  1324. BufferOut.append('A reset or restart was carried out.')
  1325. else:
  1326. BufferOut.append('No reset or restart was carried out.')
  1327. # Check bit 2.
  1328. if int(Buffer[7]) == 1:
  1329. BufferOut.append('The SD-Card is present.')
  1330. else:
  1331. BufferOut.append('No SD-Card is present')
  1332. # Check bit 3.
  1333. if int(Buffer[6]) == 1:
  1334. BufferOut.append('The SD-Card is full.')
  1335. else:
  1336. BufferOut.append('The SD-Card is not full.')
  1337. # Check bit 4.
  1338. if int(Buffer[5]) == 1:
  1339. BufferOut.append('New datalog file on the SD-Card.')
  1340. else:
  1341. BufferOut.append('No new datalog file on the SD-Card.')
  1342. # Check bit 5.
  1343. if int(Buffer[4]) == 1:
  1344. BufferOut.append('Datalogger is supported.')
  1345. else:
  1346. BufferOut.append('Datalogger is not supported.')
  1347. # Return list with Frame-flag informations.
  1348. return BufferOut
  1349. # This method is used to get the error message from the error-id.
  1350. def get_text_from_error_id(self, error_id):
  1351. """
  1352. ### Description:
  1353. This method is used to get the error message from the error-id.
  1354. ### Arguments:
  1355. The **<self>** argument is pointing to the object, which calls the method.
  1356. The **<error_id>** argument is an **int** from the xtender-system.
  1357. ### Return-Value:
  1358. The method returns a **strings** with the explanation of the error-id.
  1359. ### Example-Code:
  1360. ```>>> Object = Xcom_API()
  1361. >>> Error_ID = 0x0022
  1362. >>> Answer = Object.get_text_from_error_id(Error_ID)
  1363. >>> Answer
  1364. 'OBJECT_ID_NOT_FOUND'
  1365. """
  1366. try:
  1367. # Check ID and store error-message in Buffer
  1368. Buffer = Xcom_API.__error_code_dict[error_id]
  1369. # return error-message
  1370. return Buffer
  1371. except KeyError:
  1372. # If Error ID is unknown
  1373. return 'Error-ID is unknown.'