Commit a71cae1d authored by Mateus Goto's avatar Mateus Goto

[ADD] encode

parent 3cdabf21
...@@ -23,18 +23,18 @@ class NHR9400: ...@@ -23,18 +23,18 @@ class NHR9400:
if mode < 0 and mode > 16: if mode < 0 and mode > 16:
print("INVALID INPUT") print("INVALID INPUT")
else: else:
self.__s.send("CONF:HW:MODE " + str(mode) + "\n") self.__s.send(("CONF:HW:MODE " + str(mode) + "\n").encode())
self.checkErrors() self.checkErrors()
self.validMode() self.validMode()
#check if the mode is valid for the current hardware #check if the mode is valid for the current hardware
def validMode(self): def validMode(self):
self.__s.send("CONF:HW:MODE:VAL") self.__s.send("CONF:HW:MODE:VAL".encode())
print(self.receiveString()) print(self.receiveString())
#Command configures if [SOURCe:]<Function> commands are immediately or phase-angle controlled Query returns the synchronous operating mode #Command configures if [SOURCe:]<Function> commands are immediately or phase-angle controlled Query returns the synchronous operating mode
def instrumentSync(self, value): def instrumentSync(self, value):
if value == 0 or value == 1: if value == 0 or value == 1:
self.__s.send("CONF:INST:SYNC "+ str(value) + "\n") self.__s.send(("CONF:INST:SYNC "+ str(value) + "\n").encode())
else: else:
print("INVALID INPUT") print("INVALID INPUT")
...@@ -43,26 +43,26 @@ class NHR9400: ...@@ -43,26 +43,26 @@ class NHR9400:
if value < 1 or value > 3: if value < 1 or value > 3:
print("INVALID INPUT") print("INVALID INPUT")
else: else:
self.__s.send("INST:NSEL " + str(value) + "\n") self.__s.send(("INST:NSEL " + str(value) + "\n").encode())
self.checkErrors() self.checkErrors()
#Command selects an instrument by its alias name created with INSTrument:DEFine[:NAME]. Query returns the current selected logical instrument alias name. #Command selects an instrument by its alias name created with INSTrument:DEFine[:NAME]. Query returns the current selected logical instrument alias name.
#check this command, maybe something wrong #check this command, maybe something wrong
def instrumentSelect(self): def instrumentSelect(self):
self.__s.send("INST:SEL") self.__s.send("INST:SEL".encode())
self.checkErrors() self.checkErrors()
#Command assigns an alias name allowing selection of the instrument using INSTrument:SELect <name> Query returns the alias name assigned to a specific output channel. #Command assigns an alias name allowing selection of the instrument using INSTrument:SELect <name> Query returns the alias name assigned to a specific output channel.
def instrumentDefName(self, name, num): def instrumentDefName(self, name, num):
self.instrumentNselect(num) self.instrumentNselect(num)
self.__s.send("INST:DEF:" + str(name) + "\n") self.__s.send(("INST:DEF:" + str(name) + "\n").encode())
self.checkErrors() self.checkErrors()
#Command disassociates an <identifier> alias from the logical instrument number. #Command disassociates an <identifier> alias from the logical instrument number.
#After the command executes, the default identifier is re-associated with the instrument number. #After the command executes, the default identifier is re-associated with the instrument number.
#The default identifier cannot be deleted. #The default identifier cannot be deleted.
def instDelName(self, name): def instDelName(self, name):
self.__s.send("INST:DEL:" + str(name) + "\n") self.__s.send(("INST:DEL:" + str(name) + "\n").encode())
self.checkErrors() self.checkErrors()
#Query returns the <identifier> alias for the requested instrument number. #Query returns the <identifier> alias for the requested instrument number.
#If no instrument number is provided, the <identifier> of the selected instrument is returned. #If no instrument number is provided, the <identifier> of the selected instrument is returned.
...@@ -70,7 +70,7 @@ class NHR9400: ...@@ -70,7 +70,7 @@ class NHR9400:
if num < 1 or num > 3: if num < 1 or num > 3:
print("INVALID INPUT") print("INVALID INPUT")
else: else:
self.__s.send("INST:NAME " + str(num) + "\n") self.__s.send(("INST:NAME " + str(num) + "\n").encode())
self.checkErrors() self.checkErrors()
#Function that receives messages back and transform it in a string #Function that receives messages back and transform it in a string
def receiveString(self,recv): def receiveString(self,recv):
...@@ -90,11 +90,11 @@ class NHR9400: ...@@ -90,11 +90,11 @@ class NHR9400:
return msg return msg
def identify(self): def identify(self):
self.__s.send("*IDN?\n") self.__s.send("*IDN?\n".encode())
return self.receive() return self.receive()
#Function to see if exist any error in the carry #Function to see if exist any error in the carry
def checkErrors(self): def checkErrors(self):
self.__s.send("SYST:ERR?\n") self.__s.send("SYST:ERR?\n".encode())
self.__s.timeout(5) self.__s.timeout(5)
return self.receive() return self.receive()
...@@ -108,62 +108,62 @@ class NHR9400: ...@@ -108,62 +108,62 @@ class NHR9400:
# 1 ON - Instrumento habilitado # 1 ON - Instrumento habilitado
def enableOutput(self, value): def enableOutput(self, value):
if value == 0 or value == 1: if value == 0 or value == 1:
self.__s.send("SOUR:OUTP:ON "+ str(value) + "\n") self.__s.send(("SOUR:OUTP:ON "+ str(value) + "\n").encode())
else: else:
print("INVALID INPUT") print("INVALID INPUT")
################################# Setters and Getters ################################################ ################################# Setters and Getters ################################################
#set limit voltage of all phases #set limit voltage of all phases
def setVoltage(self,voltage): def setVoltage(self,voltage):
self.__s.send("SOUR:VOLT " + str(voltage) + "\n") self.__s.send(("SOUR:VOLT " + str(voltage) + "\n").encode())
#Functions that sets the limits voltage on one phase (A, B or C) #Functions that sets the limits voltage on one phase (A, B or C)
def setVoltageA(self,voltage): def setVoltageA(self,voltage):
self.__s.send("SOUR:VOLT:APHase " + str(voltage) + "\n") self.__s.send(("SOUR:VOLT:APH " + str(voltage) + "\n").encode())
def setVoltageB(self,voltage): def setVoltageB(self,voltage):
self.__s.send("SOUR:VOLT:BPHase " + str(voltage) + "\n") self.__s.send(("SOUR:VOLT:BPHase " + str(voltage) + "\n").encode())
def setVoltageC(self,voltage): def setVoltageC(self,voltage):
self.__s.send("SOUR:VOLT:CPHase " + str(voltage) + "\n") self.__s.send(("SOUR:VOLT:CPHase " + str(voltage) + "\n").encode())
#Command establishes the True Power limit (W) as a positive value for the selected instrument. #Command establishes the True Power limit (W) as a positive value for the selected instrument.
def setPower(self, pow): def setPower(self, pow):
self.__s.send("SOUR:POW " + str(pow) + "\n") self.__s.send(("SOUR:POW " + str(pow) + "\n").encode())
#Individual command for one phase #Individual command for one phase
def setPowerA(self, pow): def setPowerA(self, pow):
self.__s.send("SOUR:POW:APHase " + str(pow) + "\n") self.__s.send(("SOUR:POW:APHase " + str(pow) + "\n").encode())
def setPowerB(self, pow): def setPowerB(self, pow):
self.__s.send("SOUR:POW:BPHase " + str(pow) + "\n") self.__s.send(("SOUR:POW:BPHase " + str(pow) + "\n").encode())
def setPowerC(self, pow): def setPowerC(self, pow):
self.__s.send("SOUR:POW:CPHase " + str(pow) + "\n") self.__s.send(("SOUR:POW:CPHase " + str(pow) + "\n").encode())
#Command establishes the operating frequency for the selected instrument. #Command establishes the operating frequency for the selected instrument.
def setFreq(self, freq): def setFreq(self, freq):
self.__s.send("SOUR:POW " + str(freq) + "\n") self.__s.send(("SOUR:POW " + str(freq) + "\n").encode())
#Fetch the average voltage of all channels #Fetch the average voltage of all channels
def getVoltage(self): def getVoltage(self):
value = self.__s.send("FETC:VOLT?\n") value = self.__s.send("FETC:VOLT?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
#fetch individual value of voltage of one channel #fetch individual value of voltage of one channel
def getVoltageA(self): def getVoltageA(self):
value = self.__s.send("FETC:VOLT:APHase?\n") value = self.__s.send("FETC:VOLT:APHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
def getVoltageB(self): def getVoltageB(self):
value = self.__s.send("FETC:VOLT:BPHase?\n") value = self.__s.send("FETC:VOLT:BPHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
def getVoltageC(self): def getVoltageC(self):
value = self.__s.send("FETC:VOLT:CPHase?\n") value = self.__s.send("FETC:VOLT:CPHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
#Fetch the average power of all channels #Fetch the average power of all channels
def getPower(self): def getPower(self):
value = self.__s.send("FETC:POW?\n") value = self.__s.send("FETC:POW?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
#fetch individual value of Power of one channel #fetch individual value of Power of one channel
def getPowerA(self): def getPowerA(self):
value = self.__s.send("FETC:POW:APHase?\n") value = self.__s.send("FETC:POW:APHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
def getPowerB(self): def getPowerB(self):
value = self.__s.send("FETC:POW:BPHase?\n") value = self.__s.send("FETC:POW:BPHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
def getPowerC(self): def getPowerC(self):
value = self.__s.send("FETC:POW:CPHase?\n") value = self.__s.send("FETC:POW:CPHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
...@@ -17,11 +17,11 @@ class NHR9430(NHR9400): ...@@ -17,11 +17,11 @@ class NHR9430(NHR9400):
print("INVALID INPUT") print("INVALID INPUT")
else: else:
if value == 0: if value == 0:
self.__s.send("CONF:INST:LOAD:NORM") self.__s.send("CONF:INST:LOAD:NORM".encode())
if value == 1: if value == 1:
self.__s.send("CONF:INST:LOAD:CR") self.__s.send("CONF:INST:LOAD:CR".encode())
if value == 2: if value == 2:
self.__s.send("CONF:INST:LOAD:RL") self.__s.send("CONF:INST:LOAD:RL".encode())
self.checkErrors() self.checkErrors()
#Command enables bi-directional power flow for the 9420 (DC outputs) and 9430 (AC outputs) Query returns if Bi-directional power flow is permitted. #Command enables bi-directional power flow for the 9420 (DC outputs) and 9430 (AC outputs) Query returns if Bi-directional power flow is permitted.
...@@ -29,40 +29,40 @@ class NHR9430(NHR9400): ...@@ -29,40 +29,40 @@ class NHR9430(NHR9400):
#1 | YES | TRUE | ON = Bi directional mode is enabled #1 | YES | TRUE | ON = Bi directional mode is enabled
def instrumentBidirec(self, value): def instrumentBidirec(self, value):
if value == 0 or value == 1: if value == 0 or value == 1:
self.__s.send("CONF:INST:BID"+ str(value) + "\n") self.__s.send(("CONF:INST:BID"+ str(value) + "\n").encode())
else: else:
print("INVALID INPUT") print("INVALID INPUT")
self.checkErrors() self.checkErrors()
#Command sets the standby detection conditions. #Command sets the standby detection conditions.
#Query returns the configured standby detection conditions for the selected instrument #Query returns the configured standby detection conditions for the selected instrument
def instrumentStndy(self): def instrumentStndy(self):
self.__s.send("CONF: INST:STBY") self.__s.send("CONF: INST:STBY".encode())
self.checkErrors() self.checkErrors()
#set the current of all phases ** Available only to NHR9430-12 #set the current of all phases ** Available only to NHR9430-12
def setCurrent(self, current): def setCurrent(self, current):
self.__s.send("SOUR:CURR " + str(current) + "\n") self.__s.send(("SOUR:CURR " + str(current) + "\n").encode())
#Functions that sets the limite currents on one phase (A, B or C) #Functions that sets the limite currents on one phase (A, B or C)
def setCurrentA(self, current): def setCurrentA(self, current):
self.__s.send("SOUR:CURR:APHase " + str(current) + "\n") self.__s.send(("SOUR:CURR:APHase " + str(current) + "\n").encode())
def setCurrentB(self, current): def setCurrentB(self, current):
self.__s.send("SOUR:CURR:BPHase " + str(current) + "\n") self.__s.send(("SOUR:CURR:BPHase " + str(current) + "\n").encode())
def setCurrentC(self, current): def setCurrentC(self, current):
self.__s.send("SOUR:CURR:CPHase " + str(current) + "\n") self.__s.send(("SOUR:CURR:CPHase " + str(current) + "\n").encode())
#Fetch the average current of all channels #Fetch the average current of all channels
def getCurrent(self): def getCurrent(self):
value = self.__s.send("FETC:CURR?\n") value = self.__s.send("FETC:CURR?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
#fetch individual value of current of one channel #fetch individual value of current of one channel
def getCurrentA(self): def getCurrentA(self):
value = self.__s.send("FETC:CURR:APHase?\n") value = self.__s.send("FETC:CURR:APHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
def getCurrentB(self): def getCurrentB(self):
value = self.__s.send("FETC:CURR:BPHase?\n") value = self.__s.send("FETC:CURR:BPHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
def getCurrentC(self): def getCurrentC(self):
value = self.__s.send("FETC:CURR:CPHase?\n") value = self.__s.send("FETC:CURR:CPHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
def locateIp(self,clients = []): def locateIp(self,clients = []):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment