Serial Port data transfer between Python and C application (Running on Microblaze)

0

I am trying to use a python console from my PC to read from and write to an embedded C application running on a microblaze host. The connection between the two is USB -> UART through a FTDI chip.

Brief Note on my skills/background: RF/Microwave Engineer, lots of hardware experience and lots of HDL experience, however little to no software experience, certainly none in C or python.

Problem/Questions:

  1. I can use a PuTTy or Termite console to enter commands (such as 'frequency?')and receive the expected return values from the functions. I can even set the values using a 'set' version of the function. In my C application the uart_write_char function is using 'putchar()' and I suspect it is simply printing characters and strings rather than 'transmitting' data (bytes, doubles, floats etc.).

Here is a snippet of code describing the uart_write function:

*

void uart_write_char(char data)
{
    putchar(data);
}

* I would like to know if there is a difference between 'printing' data to console and 'transmitting' data to the other end, so I can receive it and dump it to a file.

  1. I would like to know the best way to use pyVISA on my python side to receive the data transmitted over the serial port. At the moment I open the port using ResourceManager() and openResource(), I set the baudrate accordingly, however I cannot seem to 'query' the device. Query is a pyVISA function(?) which is a write followed by a read. In this instance I would hope to transmit the command 'frequency?' to the embedded microblaze and I would expect the result to be transmitted back. If I can do this successfully using a console such as PuTTy or Termite, what is the difference in using a pyVISA query function? encoding perhaps?

Edit: I have also tried query_ascii_value() and query_binary_value() as documented in https://media.readthedocs.org/pdf/pyvisa/1.6/pyvisa.pdf The result is still the same, I receive a Timeout error in my python console.

UPDATE I have used NI-MAX to capture the Trace IO and the timeout appears to be on the read side. If I am connected to the device, I assume it will complete the write function, is this true? Here is the Ni-MAX log

  1. viOpenDefaultRM (0x00001001) Process ID: 0x000082C8 Thread ID: 0x00006F90 Start Time: 15:21:12.0642 Call Duration 00:00:00.0139 Status: 0 (VI_SUCCESS)

  2. viClose (0x00000000) Process ID: 0x000082C8 Thread ID: 0x00006F90 Start Time: 15:21:12.0781 Call Duration 00:00:00.0000 Status: 0x3FFF0082 (VI_WARN_NULL_OBJECT)

  3. viParseRsrcEx (0x00001001, "ASRL6::INSTR", 4 (0x4), 6 (0x6), "INSTR", "ASRL6::INSTR", "COM6") Process ID: 0x000082C8 Thread ID: 0x00006F90 Start Time: 15:21:12.0781 Call Duration 00:00:00.0000 Status: 0 (VI_SUCCESS)

  4. viOpen (0x00001001, "ASRL6::INSTR", 0 (0x0), 0 (0x0), 0x00000001) Process ID: 0x000082C8 Thread ID: 0x00006F90 Start Time: 15:21:12.0792 Call Duration 00:00:00.0657 Status: 0 (VI_SUCCESS)

  5. viParseRsrcEx (0x00001001, "ASRL6::INSTR", 4 (0x4), 6 (0x6), "INSTR", NULL, NULL) Process ID: 0x000082C8 Thread ID: 0x00006F90 Start Time: 15:21:12.1450 Call Duration 00:00:00.0000 Status: 0 (VI_SUCCESS)

  6. viWrite (ASRL6::INSTR (0x00000001), "tx_lo_freq?...", 14 (0xE), 14 (0xE)) Process ID: 0x000082C8 Thread ID: 0x00006F90 Start Time: 15:21:24.5897 Call Duration 00:00:00.0000 Status: 0 (VI_SUCCESS)

  1. viRead (ASRL6::INSTR (0x00000001), 0x000001DF461F5420, 20480 (0x5000), 0 (0x0)) Process ID: 0x000082C8 Thread ID: 0x00006F90 Start Time: 15:21:24.5897 Call Duration 00:00:02.0006 Status: 0xBFFF0015 (VI_ERROR_TMO)

I appreciate any advice on this issue and am happy to provide some more code snippets/info. Also keen for any feedback regarding post etiquette and potential for improving the post request

Cheers,

python
c
serial-port
microblaze
pyvisa
asked on Stack Overflow Sep 5, 2018 by p.sg_RF • edited Sep 5, 2018 by p.sg_RF

1 Answer

0

For completeness, I manage to work out a solution using NIMAX to trace all VISA transactions and a VISA test panel to achieve a working state, which I could then implement in my code

The issue: I was setting the baud rate and read/write termination characters in my instrument class definition and they were never getting implemented. It appears that I was trying to query with default settings of BAUD=9600 and incorrect read termination.

The Fix, I moved the lines of code which set the baud rate and read termination into my device class so that when I define the device as an Instrument, it sets these attributes before any transactions occur. Now I can read and write just fine.

Cheers,

answered on Stack Overflow Sep 7, 2018 by p.sg_RF

User contributions licensed under CC BY-SA 3.0