USB relay not working

I am using this USB relay:
SMAKN LCUS-1 type USB relay module USB intelligent control switch USB switch
To power a dosing pump:
Gikfun 12V DC Dosing Pump Peristaltic Dosing Head with Connector For Arduino Aquarium Lab Analytic Diy AE1207
This is the python code that gets it working and also has this .exe installed (SerialSend.exe; https://batchloaf.wordpress.com/serialsend/):
subprocess.check_output("serialsend.exe /baudrate 9600 /hex \\xA0\\x01\\x01\\xA2", shell=True)
time.sleep(10)
subprocess.check_output("serialsend.exe /baudrate 9600 /hex \\xA0\\x01\\x00\\xA1", shell=True)
Any tips in converting this to Matlab? I’ve tried this but nothing happens:
relayopen='\\xA0\\x01\\x01\\xA2';
relayclose='\\xA0\\x01\\x00\\xA1';
Ports=serialportlist;
JuicePort=Ports(3);
s=serial(JuicePort);
fopen(s)
fprintf(s,relayopen)
fclose(s)

Respuestas (1)

Walter Roberson
Walter Roberson el 27 de Ag. de 2022

0 votos

relayopen = '\xA0\x01\x01\xA2';
relayclose = '\xA0\x01\x00\xA1';
Ports = serialportlist;
JuicePort = Ports(3);
s = serial(JuicePort, 'BaudRate', 9600);
fopen(s)
fprintf(s,relayopen)
fclose(s)
Note that serial() is going to go away, and you should change to serialport()

3 comentarios

Jessica Yorzinski
Jessica Yorzinski el 28 de Ag. de 2022
Thanks for taking a look at this! Unfortunately, that doesn't quite work either. It runs without any errors but nothing happens with the pump. After the fopen(s), the port does change to being on (see below). Anything else you might suggest?
Serial Port Object : Serial-/dev/cu.usbserial-1410
Communication Settings
Port: /dev/cu.usbserial-1410
BaudRate: 9600
Terminator: 'LF'
Communication State
Status: open
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 18
Walter Roberson
Walter Roberson el 28 de Ag. de 2022
relayopen = 0xA00101A2;
relayclose = 0xA00100A1;
Ports = serialportlist;
JuicePort = Ports(3);
s = serial(JuicePort, 'BaudRate', 9600, 'ByteOrder', 'bigendian');
fopen(s);
fwrite(s, relayopen);
sleep(5);
fwrite(s, relayclose);
fclose(s)
Jessica Yorzinski
Jessica Yorzinski el 28 de Ag. de 2022
Thanks for giving me something else to try! Unfortunately, it is still the case that the pump isn't triggered (even though that Python code running on the same machine does trigger it). There are no errors-- just nothing happens. Any other things I could try?

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 27 de Ag. de 2022

Comentada:

el 28 de Ag. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by