My USB send data reset my program

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I have a code in python that send data to my programming card thanks to USB.

I saw with Wireshark and my data are well transmit but the problem is that when I compile my python code to send data, that reset my code that I have in my programming card...

 

Is it normal ? And is their any techniques to make the USB transfer without a reset of the code of the programming card ?

 

For information I use the USB programming port of my programming card to communicate with my computer

Last Edited: Tue. Jun 15, 2021 - 02:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

This is my send data code thanks to USB in python :

#Python imports:
import struct
import socket
import numpy as np
import time
import sys
import math
from serial import Serial

BAUD_RATE = int(115200)

################################################################################
# SendData Class #
################################################################################

class SendData:
    def __init__(self, mode, address):
        """Initialize the SendData"""
        self.is_usb = (mode == 'USB')
        self.connect(address)
        print('Initialized at address {}'.format(address))

    def __del__(self):
        try:
            self.close()
        except Exception as err:
            pass

    ############################################################################
    # Communication protocol #
    ############################################################################

    def connect(self, address):
        self.serial_address = address
        self.open_serial_connection(self.serial_address, BAUD_RATE)

    def open_serial_connection(self, port, baud_rate):
        """Open the serial connection to the 2DMOT.

        Args:
            port (str): COM port used by the arduino
            baud_rate (int): baud rate for the serial communication
        """
        try :
            self.serial = Serial(port,baud_rate)
            self.serial.timeout = 2.
            self.serial.writeTimeout = 2.
            self.serial.readline() # remove setup bytes
            # self.serial.flushInput()
            # self.serial.flushOutput()
            print('Connected to port',port)
        except IOError as e:
            print(e)

    def close(self):
        self.serial.close()

    def send_Coils(self, msg):
        if(int(msg) >= 32768):
            print("Valeur a envoyer trop grande (coil)")
        else:
            """Send a message to the 2DMOT through the USB."""
            message = int(msg) + 32768
            self.send_serial_message(str(message).encode())

    def send_Wire(self, msg):
        if(int(msg) >= 32768):
            print("Valeur a envoyer trop grande (wire)")
        else:
            """Send a message to the 2DMOT through the USB."""
            self.send_serial_message(msg.encode())

    def send_serial_message(self, msg):
        """Send a message to the arduino through va serial communication.

        Args:
            msg (bytes): message to send to the arduino
        """
        # print("Send serial message")
        try:
            if self.serial :
                # self.serial.flushInput()
                # print(msg)
                self.serial.write(msg)

                flag = self.serial.read(4)
                self.serial.flushOutput()
                self.serial.flushInput()
                print('flag: ', flag)
                if flag == b'':
                    print('The 2DMOT encountered some issue while treating '
                        ' flag ', msg[0])

        except Exception as err:
            print(err)

###########################################
# Constants #
###########################################

MODE = 'USB'
BOX_SERIAL_ADDRESS = 'COM7'

################################################################################
# Initialize #
################################################################################

CTRL_SendData = CTRL_SendData.SendData(MODE, BOX_SERIAL_ADDRESS)

################################################################################
# Send values #
################################################################################

if __name__ == '__main__':

    CTRL_SendData.send_Coils('400');
    CTRL_SendData.send_Wire('450');

With Wireshark, I can see that my data is well send :

 

But the program in my programming card reset when I compile the python code... And I know that the program reset because this program have a display which display randoms values and when I compile the python code, the display reset and the randoms values too (the 1st random value is 0 so I can see the reset).

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is your "programming card" and what software is running in it? Logically that is where the problem is.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My programming card is one design by someone in my company... But my microcontroller is the Atmel SAM3X8E. 

I notice that everytime I use the programming port (like with putty, with my python program, ...) the code of my programming card reset. I think I need to make the send of my data thanks to the other USB port I have. The problem is when I try to send my data with this other USB port that doesn't works (datas are not send) and I have some error messages.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


This is the error messages I have when I use the other USB port to send my data :

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's maybe because I supply my development board thanks to my USB port and there may be a conflict when I send my data which resets the code. 
I will try to supply my board with an electric power supply

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried to supply my board with another power supply but that doesn't change the reset code. I think the error is because I am using the programming USB port. But I don't understand why I get an error message when I try to use the other USB port to send my data.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You really haven't given anywhere near enough detail for anyone to know what you're even trying to do - let alone where it's going wrong.

 

Remember that we know nothing about you, or your project, or any homebrew tools you're using, etc, etc, ...

 

PierreBoss wrote:
My programming card is one design by someone in my company...

Can you not get that person to help you with debugging their board?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah sorry my bad !

 

I try to send some data with my Computer (thanks to the python code) at a development board thanks to USB connection.  

I want to send some data in USB and after with a running program (developed with Atmel Studio 7) in my development board I want to stock the data in a variable.

 

My development board use the microcontroller Atmel SAM3X8E (data sheet : https://ww1.microchip.com/downlo...)

 

I have 2 USB ports with my development board : 1 native USB port and 1 programming USB port. 

When I try to send data (with the python code) at my programming USB port that works but that makes my running program reset so I can't store the data in a variable.

I am 100% sure that I need to send my data to the native USB port to make the send without a reset. The problem is that when I try to send my data to the native USB port I have some error message. I can connect to the port (with Putty or with my python program) but can't send some data...

 

The person who design the board is in holidays until the end of the week. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would be far clearer to describe this with a diagram.

 

I still have no idea what is the purpose of this "programming board"? how does it connect to your target?

 

I have some error message.

and you expect people to guess what those messages say?

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The purpose of my programming board is to pilot somes Hardware components (coils and heating wires). These components are here to "control" some rubidium atomes and to put them into a vacuum chamber (I am in quantum physics company).

I need to develop first a USB control of these hardware component (I just need to send a data with my computer and to store them into variable in my programming board).

I use USB 2.0 and a native port USB to connect my computer to my programming board. My USB native port is a USB micro B port. This port is link to an microcontroller ( ATMEGA16U2 ) to convert USB informations in UART. 

 

awneil wrote:
and you expect people to guess what those messages say?

 

I put a screen of messages up (the 5th post of this discussion).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Still awaiting a diagram!

 

PierreBoss wrote:
I put a screen of messages up (the 5th post of this discussion).

Where are they coming from? What is a "2DMOT" ?

 

If it's from your own software, then only you know what they mean ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Jun 17, 2021 - 01:33 PM