Skip to content

Commit

Permalink
change stdout mode to binary to fix power off issue
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinChopinet committed Jul 7, 2023
1 parent 3fa03ba commit ef5e582
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ To have a solution independent from OS and their implementation specificities
![Firmware logic](flowchart.png)


# Limitation

When using the Panduza plateform, the State send by the Client (client.py) must be True. Otherwise (False or something else) the controle of the Pico crashes.


# Build and run project

This project has a github actions workflow that build the Pico firmware. The firmware can be download and copy on the Pico in bootsel mode.
Expand Down
12 changes: 4 additions & 8 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,13 @@
print("amps real is " + str(amps_real))
time.sleep(2)

var="n"
print("Do you want to set enable->value (unsafe) ? (y/n)")
var=input()
if(var != "y" ):
print("Skip setting enable->value")
exit()

# *** POWER ON/OFF ***

#Write
state=True
print("\nset state to " + str(state))
my_psu.enable.value.set(True)
my_psu.enable.value.set(state)
time.sleep(2)
#Read
print("Get state...")
Expand All @@ -91,7 +87,7 @@
#Write
state=False
print("\nset state to " + str(state))
my_psu.enable.value.set(False)
my_psu.enable.value.set(state)
time.sleep(2)
#Read
print("Get state...")
Expand Down
5 changes: 3 additions & 2 deletions firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int main() {
ModbusErrorInfo error;

stdio_init_all();
stdio_set_translate_crlf(&stdio_usb, false);
uart_init(UART_ID, BAUDRATE);
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
Expand All @@ -76,7 +77,7 @@ int main() {
initHanmtekValue();
blink();

debug("begining of program..\r\n");
debug("\n\rbeginning of program..\r\n");


error = modbusSlaveInit(&slave, registerCallback, exceptionCallback, modbusDefaultAllocator, modbusSlaveDefaultFunctions, modbusSlaveDefaultFunctionCount);
Expand Down Expand Up @@ -283,7 +284,7 @@ ModbusError exceptionCallback(const ModbusSlave *slave, uint8_t function, Modbu
void printErrorInfo(ModbusErrorInfo err)
{
if (modbusIsOk(err)){
debug("FRAME IS SEND TO THE LIB \r\n");
//debug("FRAME IS SEND TO THE LIB \r\n");

}else{
debug("THERE IS A PROBLEM WITH THE INIT OF\r\n");
Expand Down
32 changes: 24 additions & 8 deletions tests/rsc/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
import time
import logging

import sys

#DEBUG VERBOSE
FORMAT = ('%(message)-15s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)
#END param DEBUG VERBOSE

class Client:

def __init__(self):
self.master = ModbusSerialClient(framer=ModbusRtuFramer, port = '/dev/ttyACM0', stopbits=1, bytesize=8, parity='N', baudrate=115200)
self.master = ModbusSerialClient(framer=ModbusRtuFramer, port = '/dev/ttyACM0', stopbits=1, bytesize=8, parity='N', baudrate=9600)
# self.master = ModbusSerialClient(framer=ModbusRtuFramer, port = '/dev/ttyUSB1', stopbits=1, bytesize=8, parity='N', baudrate=9600)
#self.master = ModbusSerialClient(framer=ModbusRtuFramer, port = '/dev/ttyUSB0', stopbits=1, bytesize=8, parity='N', baudrate=9600)
connexion = self.master.connect()
print(self.master)
self.writeDelay = 5
self.writeDelay = 1

# --- GETS ---

Expand Down Expand Up @@ -79,25 +89,30 @@ def read_resistor_load(self):
def write_psu_model(self, value):
""" Illegal action
"""
sending = self.master.write_registers(0x03, int(value), 0x01)
sending = self.master.write_register(0x03, int(value), 0x01)
print(sending)
time.sleep(self.writeDelay)

def write_voltage_goal(self, voltage):
sending = self.master.write_registers(0x30, int(voltage), 0x01)
sending = self.master.write_register(0x30, int(voltage), 0x01)
print(sending)
time.sleep(self.writeDelay)

def write_voltage_real(self, voltage):
""" Illegal action
"""
sending = self.master.write_registers(0x10, int(voltage), 0x01)
sending = self.master.write_register(0x10, int(voltage), 0x01)
print(sending)
time.sleep(self.writeDelay)

def write_amps_goal(self, amps):
sending = self.master.write_registers(0x31, int(amps), 0x01)
sending = self.master.write_register(0x31, int(amps), 0x01)
print(sending)
time.sleep(self.writeDelay)

def write_enable(self, state):
sending = self.master.write_registers(0x1, int(state) , 0x01)
sending = self.master.write_register(0x1, int(state) , 0x01)
print(sending)
time.sleep(self.writeDelay)

def turn_on_power_supply(self):
Expand All @@ -107,7 +122,8 @@ def turn_off_power_supply(self):
self.write_enable(0)

def write_resistor_load(self, value):
sending = self.master.write_registers(0x24, int(value) , 0x01)
sending = self.master.write_register(0x24, int(value) , 0x01)
print(sending)
time.sleep(self.writeDelay)


Expand Down

1 comment on commit ef5e582

@QuentinChopinet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solve #7

Please sign in to comment.