Ankündigung

Einklappen
Keine Ankündigung bisher.

ComfoAir 500 Steuerung über RS485

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    #46
    Hmm...

    Die Daten kommen mir irgend wie bekannt vor... Wenn ich mich recht errinnere hat ein anderer User, der mein Wiregate-Plugin mit dem Wiregate und einem Moxa-NPort einsetzt, ganz ähnliche Probleme. Da werden scheinbar irgend wo die 07 F0 herausgefiltert. Vieleicht hilft hier ein raw mode!? Die Frage ist welches Programm auf dem Pi das unterstützt?
    Gruss Patrik alias swiss

    Kommentar


      #47
      Zitat von swiss Beitrag anzeigen
      Hmm...
      Vieleicht hilft hier ein raw mode!? Die Frage ist welches Programm auf dem Pi das unterstützt?
      Naja, hab ja geschrieben: minicom. Das ist ein terminal welches die Daten auf der seriellen Schnittstelle anzeigt, ohne irgendwelche Modifikationen.

      Wenn du selbst programmieren möchtest hier ein paar Codeschnipsel:

      Code:
      int CAConsoleApplication::InitSerialConnection(const char *ttyPath)
      {
          int fd = 0;
          
          open(ttyPath, O_RDWR | O_NONBLOCK | O_NOCTTY | O_NDELAY);
          if (fd < 0)
          {
            perror("Unable to open serial device");
                return fd;
          }
      
          fcntl(fd, F_SETFL, 0);
      
          struct termios options;
          
          // Get the current options for the port...
          tcgetattr(fd, &options);
          
          // Set the baud rate to 9600...
          cfsetispeed(&options, B9600);
          cfsetospeed(&options, B9600);
          
          // Enable the receiver and set local mode...
          options.c_cflag |= (CLOCAL | CREAD);
          
          // No parity (8N1):
          options.c_cflag &= ~PARENB; // remove parity bit
          options.c_cflag &= ~CSTOPB; // remove CSTOPB  to get 1 stop bit
          options.c_cflag |= CSIZE; // Mask the character size bits
          options.c_cflag |= CS8;    // Select 8 data bits
          options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // choose RAW input
          options.c_iflag &= ~(IXON | IXOFF | IXANY);
          options.c_oflag &= ~OPOST;
          
          tcsetattr(fd, TCSAFLUSH, & options);
          
          return(fd);
      }
      und hier der Empfangs-Loop:
      Code:
          // local variables for receiving
          unsigned char receiveBuffer[MAX_FRAME_SIZE];
          ssize_t nBytesRead = 0;
      
          // run the main loop
          while (1)
          {
              FD_ZERO(&m_fds);
              FD_SET(m_nSerialDeviceFileDescriptor, &m_fds);
      
              int max_fd = m_nSerialDeviceFileDescriptor;
              select(max_fd + 1, &m_fds, NULL, NULL, NULL);
      
              // check if the serial device has bytes available
              if (FD_ISSET(m_nSerialDeviceFileDescriptor, &m_fds))
              {
                  nBytesRead = read(m_nSerialDeviceFileDescriptor, &receiveBuffer, MAX_FRAME_SIZE);
                  for (int t=0; t<nBytesRead; ++t)
                  {
                      unsigned char currentByte = *(receiveBuffer+t);
                      printf("%02x", currentByte);
                      m_frameBuilder.Append(currentByte);
                  }
                  printf("End receive\n");
              }
          }
      damit bekommst du alles was an der seriellen Schnittstelle ankommt.

      MatsMan

      Kommentar


        #48
        Hallo Zusammen,

        erstmal vielen Dank für die Unterstützung.
        Ich werde das alles mal probieren und evtl. doch die andere Schnittstelle (RJ45) verwenden.
        Ich melde mich wieder wenn ich mehr weiß.
        Das beschäftigt mich jetzt erstmal

        Danke nochmal

        denghauser

        Kommentar


          #49
          Hallo Zusammen,

          danke nochmal für den code, das hat mir echt weitergeholfen.
          Ich habe nun nicht mit mono C#\CLI sondern mit C++ und g++ gearbeitet.

          Und siehe da, die Daten sehen eher korrekt aus

          Hier ein Ausschnitt aus meinem Protokoll:

          Code:
          07 f3 
          07 f0 00 3e 04 25 26 03 cc 09 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 98 14 00 00 23 00 00 00 00 23 23 00 00 00 00 00 00 00 00 00 00 00 c2 07 0f
          07 f3 
          07 f0 00 9c 01 02 4c 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 aa 08 00 00 00 00 00 00 00 00 5f 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 ce 0e 0f 10 32 0f 10 32 23 23 01 01 46 46 00 00 ff 07 0f
          07 f3 
          07 f0 00 d2 09 5a 4e 53 56 51 0f 28 28 28 b1 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 e0 07 00 00 00 00 00 00 01 95 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 e2 06 02 00 00 00 00 01 98 07 0f
          07 f3 
          07 f0 00 ec 07 07 07 17 00 0a 00 00 12 da 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 3e 04 25 26 03 cc 09 07 0f
          07 f3 
          07 f0 00 98 14 00 00 23 00 00 00 00 23 23 00 00 00 00 00 00 00 00 00 00 00 c2 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 9c 01 02 4c 07 0f
          07 f3 
          07 f0 00 aa 08 00 00 00 00 00 00 00 00 5f 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 ce 0e 0f 10 32 0f 10 32 23 23 01 01 46 46 00 00 ff 07 0f
          07 f3 
          07 f0 00 d2 09 5a 4e 53 56 51 0f 28 28 28 b1 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 3c 0a 82 76 cf 4f 07 07 77 00 00 77 e0 de 07 0f
          07 f3 
          07 f0 00 e0 07 00 00 00 00 00 00 01 95 07 0f
          07 f3 
          07 f0 00 e2 06 02 00 00 00 00 01 98 07 0f
          Also alles im grünen Bereich.

          Hier mein code den ich mit g++ serialcpp.cpp -o appser compiliert habe
          Code:
          #include <stdio.h>
          #include <iostream>
          #include <unistd.h>
          #include <string>
          #include <sys/time.h>
          #include <sys/types.h>
          #include <sys/select.h>
          #include <sys/stat.h>
          #include <fcntl.h>
          #include <termios.h>
          
          #define MAX_FRAME_SIZE 256
          
          using namespace std;
          
          class SerialHomeDevice
          {
          
          	private:
          		string m_port_name;
          		int m_nSerialDeviceFileDescriptor;
          	
          	public: 
          
          	SerialHomeDevice(string portname) {
          		m_nSerialDeviceFileDescriptor = 0;
          		m_port_name = portname;
          	}
          
          	int InitSerialConnection(const char *ttyPath)
          	{
              		int fd = 0;
          
          		printf("Serial Port Init : %s\n",ttyPath);
          
              		fd = open(ttyPath, O_RDWR | O_NONBLOCK | O_NOCTTY | O_NDELAY);
              		if (fd < 0)
              		{
                			perror("Unable to open serial device\n");
                    		return fd;
              		}
          
              		fcntl(fd, F_SETFL, 0);
          
          	    	struct termios options;
              
              	// Get the current options for the port...
              		tcgetattr(fd, &options);
              
              	// Set the baud rate to 9600...
              		cfsetispeed(&options, B9600);
          	    	cfsetospeed(&options, B9600);
              
              	// Enable the receiver and set local mode...
              		options.c_cflag |= (CLOCAL | CREAD);
              
              	// No parity (8N1):
          	    	options.c_cflag &= ~PARENB; // remove parity bit
              		options.c_cflag &= ~CSTOPB; // remove CSTOPB  to get 1 stop bit
          	    	options.c_cflag |= CSIZE; // Mask the character size bits
              		options.c_cflag |= CS8;    // Select 8 data bits
          	    	options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // choose RAW input
              		options.c_iflag &= ~(IXON | IXOFF | IXANY);
          	    	options.c_oflag &= ~OPOST;
              	
              		tcsetattr(fd, TCSAFLUSH, & options);
              
          		m_nSerialDeviceFileDescriptor = fd;
          		printf("fd : %d\n",m_nSerialDeviceFileDescriptor);
          
              		return(fd);
          	}
          
          	int receiveLoop()
          	{
          
          		unsigned char receiveBuffer[MAX_FRAME_SIZE];
          		ssize_t nBytesRead = 0;
          
          
          		fd_set m_fds;
          		string * m_frameBuilder = new string();
          
          		// run the main loop
          		while (1)
          		{
          			FD_ZERO(&m_fds);
          			FD_SET(m_nSerialDeviceFileDescriptor, &m_fds);
          
          			int max_fd = m_nSerialDeviceFileDescriptor;
          			select(max_fd + 1, &m_fds, NULL, NULL, NULL);
          
          			// check if the serial device has bytes available
          			if (FD_ISSET(m_nSerialDeviceFileDescriptor, &m_fds))
          			{
          				nBytesRead = read(m_nSerialDeviceFileDescriptor, &receiveBuffer, MAX_FRAME_SIZE);
          				for (int t=0; t<nBytesRead; ++t)
          				{
          					unsigned char currentByte = *(receiveBuffer+t);
          					printf("%02x ", currentByte);
          					m_frameBuilder += static_cast<char>(currentByte);
          				}
          				// printf("End receive\n");
          			}
          
          			
          			//if (EOF != getchar())
          			//	break;
          
          		}  
          
          	}
          
          };
          
          
          int main(int argc, char **argv)
          {
          	if (argc < 2){
          
          		printf("Please specify the serial device in the commandline");
          		return 0;
          	}
          
          	string dev_name = argv[1];
          	printf("Serial Port : %s\n",dev_name.c_str());
          
          	SerialHomeDevice * hd = new SerialHomeDevice(dev_name.c_str());
          	if (hd->InitSerialConnection(dev_name.c_str()))
          		hd->receiveLoop();
          
          }
          Ich mache zwar die Schnittstelle noch nicht ordentlich zu und man muss das mit Ctrl+C abbrechen. Aber man kann mit ./appser /dev/ttyUSB0 die Schnittstelle der Wahl benutzen. Also ein netter Datenlogger. An die Interpretations und Sendefunktionen mache ich mich nun

          Eines ist mir aufgefallen. Die Antworten sind nicht immer +1 oder -1 vom Kommando wie das von see-solutions beschrieben wird. Hat da jemand eine Idee weshalb das so ist, oder muss das in der CC-Ease Kommunikation gar nicht sein?

          Danke an alle

          denghauser

          Kommentar


            #50
            Ja die Daten sehen schon viel besser aus... Wuss ich doch, dass das Protokoll auchbei dir passt

            wegen den +1 und -1...

            Die ComfoAir antwortet nicht ganz immer direkt nach einer Anfrage. Manchmal fragt man die Temperaturen ab und erhält zuerst den Bypass Status und erst ein paar Pakete später kommt dann auch die Temperatur.

            Aber ich kann dich beruhigen das Protokoll von see solution ist korrekt
            Gruss Patrik alias swiss

            Kommentar

            Lädt...
            X