Jump to content
  • 0

Understanding the "create_string_buffer" Digital_UART Statement


Lesiastas

Question

Greetings,

Forgive me, but I'm not that knowledgeable in python and I'm having trouble understanding the "create_string_buffer" argument in the Digital_UART.py sample code. 
How do you declare this "create_string_buffer" statement into its VB6 equivalent?

image.png.6982ef6eef5291fde2d5c43b8148da55.png

Sincerely yours, 

Lesiastas

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

Link to comment
Share on other sites

Hi @attila

Thanks for the advice about the VB String and Byte Arrays. I'm still having a hard time in understanding how to apply the "create_string_buffer" in VB6. Here's the code that I'm working on:
 

 Dim handle As Integer
        Dim rgRx() As Byte
        Dim cRx As Integer
        Dim pParity As Integer
        'Opening Device
        Call AD2_FDwfDeviceOpen(-1, handle)

        'Digital_Uart Rx Parameters
        Call AD2_FDwfDigitalUartRateSet(handle, 9600)
        Call AD2_FDwfDigitalUartRxSet(handle, 0)  '9.6kHz
        Call AD2_FDwfDigitalUartBitsSet(handle, 8) '8 bits
        Call AD2_FDwfDigitalUartParitySet(handle, 0) '0 none, 1 odd, 2 even
        Call AD2_FDwfDigitalUartStopSet(handle, 1) '1 bit stop length
        Call AD2_FDwfDigitalUartRx(handle, rgRx, (101 - 1), cRx, pParity) 'initialize RX reception

        'Done
        Call AD2_FDwfDeviceCloseAll()



I was just wondering, is it possible to use the Digital_UART for Receiving only?
What I mean by this is I only want to enable the Rx capability of the Digital_UART in receiving ASCII characters.

Regards

 

Link to comment
Share on other sites

Hi @Lesiastas

Here you have a simple VB UART loopback example, TX = RX = DIO-0

Dim hdwf As Long
        
If FDwfDeviceOpen(-1, hdwf) = False Then
    Dim szError As String
    Call FDwfGetLastErrorMsg(szError)
    MsgBox("Device open failed" & vbCrLf & szError, vbExclamation + vbOKOnly)
    End
End If

Dim szTx = "Hello\n"
Dim rgTx = System.Text.Encoding.ASCII.GetBytes(szTx)
Dim rgRx(512) As Byte
Dim fParity As Integer
Dim cRx As Integer

Call FDwfDigitalUartTxSet(hdwf, 0)
Call FDwfDigitalUartRxSet(hdwf, 0)
Call FDwfDigitalUartTx(hdwf, Nothing, 0) ' initialize TX
Call FDwfDigitalUartRx(hdwf, Nothing, 0, Nothing, Nothing) ' initialize RX

Call FDwfDigitalUartTx(hdwf, rgTx, rgTx.Length)
Call FDwfDigitalUartRx(hdwf, rgRx, rgRx.Length, cRx, fParity)

Dim szRx = System.Text.Encoding.ASCII.GetString(rgRx, 0, cRx)
System.Console.WriteLine(szRx)

 

Link to comment
Share on other sites

Hi @attila

The UART project for serial reception is now working. Thank you so much for all of your help.
I just added some APIs that I need to replicate what was being done in the WaveForms GUI.
Here's the VB6 code made with your guidance:
 

Dim handle As Long
        'Dim szTx = "Try lang"
        'Dim rgTx = System.Text.Encoding.ASCII.GetBytes(szTx)
        Dim rgRx(512) As Byte
        Dim fParity As Integer
        Dim cRx As Integer

        'Opening Device
        Call AD2_FDwfDeviceOpen(-1, Handle)

        'Initializing UART
        Call AD2_FDwfDigitalUartRateSet(handle, 9600) '9.6kHz
        'Call AD2_FDwfDigitalUartTxSet(handle, 1)
        Call AD2_FDwfDigitalUartRxSet(handle, 0)
        Call AD2_FDwfDigitalUartBitsSet(handle, 8) '8 bits
        Call AD2_FDwfDigitalUartParitySet(handle, 0) '0 none, 1 odd, 2 even
        Call AD2_FDwfDigitalUartStopSet(handle, 1) ' 1 bit stop length
        'Call AD2_FDwfDigitalUartTx(handle, Nothing, 0) ' initialize TX
        Call AD2_FDwfDigitalUartRx(handle, Nothing, 0, Nothing, Nothing) ' initialize RX

        'Capturing Samples
        'Call AD2_FDwfDigitalUartTx(handle, rgTx, rgTx.Length)
        Call AD2_FDwfDigitalUartRx(handle, rgRx, rgRx.Length, cRx, fParity)

        Dim szRx = System.Text.Encoding.ASCII.GetString(rgRx, 0, cRx)
        'System.Console.WriteLine(szRx)

        'Done
        Call AD2_FDwfDigitalUartReset(handle)
        Call AD2_FDwfDeviceCloseAll()

Here's the result we came up when we connected the UART Controller to transmit ASCII characters:

image.png.65b3b17af836f10faea738863702b980.png

Thanks for everything! More power to you and Digilent!

Regards,

Lesiastas

 

Link to comment
Share on other sites

Hi @attila

Is it possible to immediately store String values instead of Byte in the FDwfDigitalUartRx API? I created another set of code to be applied in VBA. 
Here's the code I'm working on:

Public Function AD2_FDwfDigitalUartRx(ByVal hdwf As Integer, ByRef szRx() As String, ByVal cRx As Integer, ByRef pcRx As Integer, ByRef pParity As Integer) As Integer

        Dim rgRx = System.Text.Encoding.ASCII.GetString(szRx, 0, cRx)

        Call FDwfDigitalUartRx(hdwf, rgRx, cRx, pcRx, pParity)

    End Function

But an error of: image.png.2f8e3579e4a58555ce868c174c232f7a.png always occurs.

So my main question is this: How can I post process the FDwfDigitalUartRx to display String data after reception?

Regards,

Lesiastas

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...