Hallo Zusammen
Ich per kontakt ein Befehl über RS232 senden können und beim loslassen einen weiteren Befehl senden.
Es geht um ein Beamer den ich Ein/Ausschalten muss.
https://www.canon.co.uk/Images/WUX450ST_UserCommands_E_YT1-1465-000_tcm14-1455893.pdf
Meiner Meinung nach muss ich "504F5745523D4F4E0D" (HEX) zum Einschalten senden
Zudem ist bei diesem Beamer so das man 2 Stop bit braucht nicht wie sonst nur 1s
Kann mir hier jemand weiterhelfen?
Ich habe hier einen code aus dem Internet der ein wenig angepasst wurde
Hier versucht das Arduino den Befehl noch ins HEX umzuwandeln, was ich aber nicht unbedingt brauche.
/*
Software serial multple serial test
Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.
The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)
Note:
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
Not all pins on the Leonardo and Micro support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
boolean lastState = false;
boolean manuallyState = false;
//Ab hier anpassen
long baudRate = 19200; //BaudRate Serial-Kommunikation RS232 und PC
int pinRelais = 2; //Pin fuer Relais
int pinManuell_On = 3; //Pin fuer manueller Schalter <ON>
int pinManuell_Off = 4; //Pin fuer manueller Schalter <OFF>
int repeate = 1; //Wie viel mal soll das Kommando gesendet werden
long sleep = 1100; //Wie lange soll zwischen den Wiederholungen gewartet werden
char commandOn[] = "POWER=ON"; //Was ueber RS232 gesendet wird, sobald Pin <Relais> geschlossen wird
char commandOff[] = "POWER=OFF"; //Was ueber RS232 gesendet wird, sobald Pin <Relais> geoeffnet wird
//Bis hier anpassen
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(baudRate);
mySerial.begin(baudRate);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Good morning!");
//PinMode
pinMode(pinRelais, INPUT_PULLUP);
pinMode(pinManuell_On, INPUT_PULLUP);
pinMode(pinManuell_Off, INPUT_PULLUP);
}
void loop() {
//Hat sich etwas veraendert?
if(!lastState && digitalRead(pinRelais) == LOW){ //Voher aus, nun an
lastState = true;
sendCommand(commandOn, sizeof(commandOn));
}else if(lastState && digitalRead(pinRelais) == HIGH){ //Voher an, nun aus
lastState = false;
sendCommand(commandOff, sizeof(commandOff));
}
if(!manuallyState && digitalRead(pinManuell_On) == LOW){
manuallyState = true;
sendCommand(commandOn, sizeof(commandOn));
}else if(!manuallyState && digitalRead(pinManuell_Off) == LOW){
manuallyState = true;
sendCommand(commandOff, sizeof(commandOff));
}else if(digitalRead(pinManuell_On) == HIGH && digitalRead(pinManuell_Off) == HIGH){
manuallyState = false;
}
//Kommunikation zwischen Serial Pc und Serial Beamer
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
//Send command to mySerial
void sendCommand(char command[], int command_size){
for(int j=0; j<repeate; j++){
for (int i=0; i < command_size-1; i++){
Serial.println((int)command[i],HEX); //Char zu Int konventiere (ASCII) und dann als HEX ausgeben
mySerial.print((int)command[i],HEX); //Char zu Int konventiere (ASCII) und dann als HEX ausgeben
}
mySerial.print("0D");
Serial.println("0D");
// Notfallweise auskommentieren CR
// mySerial.print(13, HEX);
// Serial.println(13, HEX);
delay(sleep);
}
}
Ich bin froh um jede Antwort!
Danke schon im Voraus!