Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    DDA output not showing over serial communication with Rpi?

    Scheduled Pinned Locked Moved
    Firmware developers
    1
    2
    209
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jazbaatbadalgayeundefined
      jazbaatbadalgaye
      last edited by jazbaatbadalgaye

      I am trying to capture the DDA output over serial on a Raspberry Pi. However the only data I am able to read over serial is the heater warning.

      Warning: Tool 0 was not driven because its heater temperatures were not high enough or it has a heater fault
      

      I am able to read the DDA output when I use a python script for serial communication but I am only getting the warning when I use C for serial communication.

      The expected output i.e. the output from the python script is as follows :

      N 0.500000 174.949997 112.449997 0.300000 0.000000 0.000000 0.000000 41926.273438 0.000000 41926.273438 83852 0.0000e+0 1.1926e-5 0.0000e+0 1 0.500000
      
      N 15.100006 174.949997 112.449997 0.300000 15.100006 0.000000 0.000000 53037.558594 917231.625000 970269.187500 970269 0.0000e+0 1.6000e-5 1.6000e-5 1 1.265568
      
      Warning: Tool 0 was not driven because its heater temperatures were not high enough or it has a heater fault
      
      N 15.100006 190.050003 112.449997 0.300000 0.000000 15.100006 0.000000 0.000000 943750.375000 943750.375000 943750 1.6000e-5 1.6000e-5 1.6000e-5 1 1.265663
      
      N 6.769390 169.649002 108.239998 0.300000 5.300995 4.209999 0.000000 96530.593750 0.000000 96530.593750 193061 0.0000e+0 7.0127e-5 0.0000e+0 1 0.000000
          
      N 0.500000 174.949997 112.449997 0.300000 0.000000 0.000000 0.000000 41926.273438 0.000000 41926.273438 83852 0.0000e+0 1.1926e-5 0.0000e+0 1 0.500000
          
      N 15.100006 174.949997 112.449997 0.300000 15.100006 0.000000 0.000000 53037.558594 917231.625000 970269.187500 970269 0.0000e+0 1.6000e-5 1.6000e-5 1 1.265568
      
      Warning: Tool 0 was not driven because its heater temperatures were not high enough or it has a heater fault
          
      N 15.100006 190.050003 112.449997 0.300000 0.000000 15.100006 0.000000 0.000000 943750.375000 943750.375000 943750 1.6000e-5 1.6000e-5 1.6000e-5 1 1.265663
      

      i.e. a line starting with N and followed by some numerical values and occasionally get some warnings about the heater.

      However, the output I am getting is

      Warning: Tool 0 was not driven because its heater temperatures were not high enough or it has a heater fault
       
      Warning: Tool 0 was not driven because its heater temperatures were not high enough or it has a heater fault
       
      Warning: Tool 0 was not driven because its heater temperatures were not high enough or it has a heater fault
       
      Warning: Tool 0 was not driven because its heater temperatures were not high enough or it has a heater fault
       
      Warning: Tool 0 was not driven because its heater temperatures were not high enough or it has a heater fault
      

      The c code that I am using is

      #include <stdio.h>
      #include <string.h>
      #include <unistd.h>
      #include <fcntl.h>
      #include <errno.h>
      #include <termios.h>
      
      int main(int argc, char ** argv) {
        int fd;
      
        // Open the Port. We want read/write, no "controlling tty" status, and open it no matter what state DCD is in
        fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);
        
        struct termios SerialPortSettings;
        
        cfsetispeed(&SerialPortSettings,B115200);
        cfsetospeed(&SerialPortSettings,B115200);
      		
        tcsetattr(fd, TCSAFLUSH, &SerialPortSettings);
      
          
        if (fd == -1) 
        {
          perror("open_port: Unable to open /dev/ttyACM0 - ");
          return(-1);
        }
      
        // Turn off blocking for reads, use (fd, F_SETFL, FNDELAY) if you want that
        fcntl(fd, F_SETFL, 0);
      
        // Write to the port
      
      
        // Read up to 255 characters from the port if they are there
      
        char buf[255];
        
        while (1)
        {
          ssize_t k = read(fd, buf, sizeof(buf)-1);
          if (k < 0) 
          {
            perror("Read failed - ");
            return -1;
          } 
          else if (k == 0) 
          {
            printf("No data on port\n");
          }
          else 
          {
            buf[k] = '\0';
            printf(buf);
            
          }
        }
        
        close(fd);
        return 0;
      }
      

      I have used the same code to get some values from an accelerometer so I am confident that the code works, albeit bad code, but works. Does anyone have any idea why am I not able to read the numerical data but able to read the heater warnings?

      Here is the python code which works properly :

      import serial
      import time
      import subprocess
      
      LINUX = 1
      
      output = subprocess.check_output("python -m serial.tools.list_ports", shell=True) # sending command to terminal 
      output = output.decode('utf-8') # the output is of type b'somestring' This removes that
      output = output.splitlines() # so we can access the COM part
      
      if LINUX:
          temp = output[0].split()
          port = temp[0]
      else:
          port =  output[0]
          
      data = open("Input.txt", "w")
      ser = serial.Serial(port, 115200, timeout=30)
      print("Serial Port opened on : " + ser.name)
      
      counter = 0
      while (1):
          response = ser.readline().decode('utf-8')
          print(response)
          data.write(response)
          if response == "":
              break
      
      time.sleep(1)
      data.close()
      
      jazbaatbadalgayeundefined 1 Reply Last reply Reply Quote 0
      • jazbaatbadalgayeundefined
        jazbaatbadalgaye @jazbaatbadalgaye
        last edited by

        @jazbaatbadalgaye Just commenting in case anyone runs into the same issue.

        The C code was working fine, void DDA::DebugPrint in DDA.cpp was the culprit. The debugPrintf() function in void DDA::DebugPrint did not output to the serial (at least in C, it worked fine in Python). So I declared variables in Platform.h, set values in DDA.cpp and used debugPrintf() in Platform.cpp to print all the values to serial. I have no idea why it works and I have no idea why the debugPrintf() function in void DDA::DebugPrint doesn't work in C. Maybe need to sacrifice a goat to the C Gods.

        Note : All this is not required if using python to read serial data. For python, just print values using debugPrintf() function in void DDA::DebugPrint. Those values will show up on the serial.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Unless otherwise noted, all forum content is licensed under CC-BY-SA