Closed CloudyPadmal closed 3 years ago
Implemented old I2C raw functions to support old power source access using SET_DAC method
Control power source instrument using two parameters
0 - PCS
1 - PV3
2 - PV2
3 - PV1
21/10/25 (Monday) 14:24:31
Old Power Source
Implemented old I2C raw functions to support old power source access using SET_DAC method
New Power Source
Control power source instrument using two parameters
0 - PCS
,1 - PV3
,2 - PV2
,3 - PV1
Python helpers
Python methods to set power
```python def set_power(self, channel, power): self._device.send_byte(Byte.pack(6)) # CP.DAC self._device.send_byte(Byte.pack(3)) self._device.send_byte(Byte.pack(channel)) self._device.send_int(power) status = self._device.get_ack() if (status == 1): print("Power Set") else: print("Error") ```Real Time Clock
Register structure:
Python helpers
Python methods to set time
```python def set_time(self): from datetime import datetime now=datetime.now() seconds = int(now.second) sec_1 = '{0:04b}'.format(seconds % 10) sec_2 = '{0:04b}'.format(int(seconds / 10)) b_seconds = sec_2 + sec_1 minutes = int(now.minute) min_1 = '{0:04b}'.format(minutes % 10) min_2 = '{0:04b}'.format(int(minutes / 10)) b_minutes = min_2 + min_1 hours = int(now.hour) hour_1 = '{0:04b}'.format(hours % 10) hour_2 = '{0:02b}'.format(int(hours / 10)) b_hours = '01' + hour_2 + hour_1 # 24 hour format b_day = '{0:08b}'.format(now.isoweekday()) date = int(now.day) date_1 = '{0:04b}'.format(date % 10) date_2 = '{0:02b}'.format(int(date / 10)) b_date = '00' + date_2 + date_1 month = int(now.month) month_1 = '{0:04b}'.format(month % 10) month_2 = '{0:01b}'.format(int(month / 10)) b_month = '000' + month_2 + month_1 year = int(str(now.year)[2:]) year_1 = '{0:04b}'.format(year % 10) year_2 = '{0:01b}'.format(int(year / 10)) b_year = '000' + year_2 + year_1 self._device.send_byte(CP.SENSORS) self._device.send_byte(CP.SET_TIME) self._device.send_byte(Byte.pack(int(b_seconds, 2))) self._device.send_byte(Byte.pack(int(b_minutes, 2))) self._device.send_byte(Byte.pack(int(b_hours, 2))) self._device.send_byte(Byte.pack(int(b_day, 2))) self._device.send_byte(Byte.pack(int(b_date, 2))) self._device.send_byte(Byte.pack(int(b_month, 2))) self._device.send_byte(Byte.pack(int(b_year, 2))) self._device.send_byte(Byte.pack(128)) status = self._device.get_ack() if (status == 1): print("Date set") else: print("Error") ```Python methods to get time
```python def get_time(self): self._device.send_byte(CP.SENSORS) self._device.send_byte(CP.GET_TIME) A = [] for i in range(7): A.append('{0:08b}'.format((self._device.get_byte()))) self._device.get_ack() # Seconds sec_1 = A[0][4:] sec_2 = A[0][:4] seconds = str(int(sec_2, 2)) + '' + str(int(sec_1, 2)) # Minutes min_1 = A[1][4:] min_2 = A[1][:4] minutes = str(int(min_2, 2)) + '' + str(int(min_1, 2)) # Hours hr_1 = A[2][4:] hr_2 = A[2][3] hours = str(int(hr_2, 2)) + '' + str(int(hr_1, 2)) # Day of week import calendar day = str(int(A[3][5:], 2) - 1) day = calendar.day_name[int(day)] # Date date_1 = A[4][4:] date_2 = A[4][2:4] date = str(int(date_2, 2)) + '' + str(int(date_1, 2)) # Month month_1 = A[5][4:] month_2 = A[5][3] month = str(int(month_2, 2)) + '' + str(int(month_1, 2)) # Year year_1 = A[6][4:] year_2 = A[6][:4] year = str(int(year_2, 2)) + '' + str(int(year_1, 2)) K = str(year + '/' + month + '/' + date + ' (' + day + ') ' + hours + ':' + minutes + ':' + seconds) print(K) ```Output