Xcom_API.py 76 KB

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