简体   繁体   中英

STM32F4 USB CDC, can't use Data with pyserial

I have a problem with the combination of STM32F4 USB CDC and pyserial. If my Code in the STM32 wants to work with the received Data in the main.c I can't open the Port. If not, I can send and receive with no problem, the information is stored successfully in the UserRxBufferFS.

I get following error:

>>> ser.open() Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "C:\Program Files\Anaconda2\lib\site-packages\serial\serialwin32.py", line 78, in open
    self._reconfigure_port()   File "C:\Program Files\Anaconda2\lib\site-packages\serial\serialwin32.py", line 222, in
_reconfigure_port
    'Original message: {!r}'.format(ctypes.WinError())) serial.serialutil.SerialException: Cannot configure port, something went wrong. Original message: WindowsError(87, 'Falscher Parameter.')

I tried to store the Data in a global variable that I declared in the usbd_cdc_if.h:

usbd_cdc_if.h: extern int my_buf[8];
usbd_cdc_if.c: my_buf[0]=UserRxBufferFS[0];

--> error

Tried to call a function in the callback that brings the information to my main.c --> error

Tried a global pointer that points to the buffer --> error

All of this is working when I use a windows terminal. But I need to use pyserial. When I don't work with the data I can connect, send and receive everything with no problem.

Has anyone an idea of the problem and a way to solve it?

WindowsError(87, 'Falscher Parameter.')

I suppose you know that means 'wrong parameter'. Did you send an invalid parameter to the routine?

Note that, very probably, UserRxBufferFS will be defined as something like an unsigned char (1 byte long) because the communication is byte by byte. You are defining your buffer as int , which probably is either 2 or 4 bytes long.

Maybe you as passing int to the transmission or initializing routine, where that routine expects bytes? (or unsigned char s)

my_buf[0]=UserRxBufferFS[0];

transfers the first element from UserRxBufferFS to my_buf , which probably copies an unsigned char into an int , which can also give unexpected results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM