Lesiastas Posted July 23, 2019 Share Posted July 23, 2019 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? Sincerely yours, Lesiastas Link to comment Share on other sites More sharing options...
attila Posted July 23, 2019 Share Posted July 23, 2019 Hi @Lesiastas You can convert between VB String and byte arrays like this:https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/strings/how-to-convert-strings-into-an-array-of-byteshttps://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/strings/how-to-convert-an-array-of-bytes-into-a-string You could also change the argument declaration in the wrapper to: <MarshalAs(UnmanagedType.LPStr)> ByVal szRx As StringBuilder Link to comment Share on other sites More sharing options...
Lesiastas Posted July 23, 2019 Author Share Posted July 23, 2019 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 More sharing options...
Lesiastas Posted July 24, 2019 Author Share Posted July 24, 2019 Hi @attila Sorry to be a bother, but can you help me understand how to declare this in VB6 format? rgRX = create_string_buffer(101) dwf.FDwfDigitalUartRx(hdwf, rgRX, c_int(sizeof(rgRX)-1), byref(cRX), byref(fParity)) Regards, Lesiastas Link to comment Share on other sites More sharing options...
attila Posted July 24, 2019 Share Posted July 24, 2019 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 More sharing options...
Lesiastas Posted July 24, 2019 Author Share Posted July 24, 2019 Hi @attila Thank you so much for that sample codes. I'll study it well to see how I can apply the Digital_Uart to be used only to Receive ASCII characters. Regards, Lesiastas Link to comment Share on other sites More sharing options...
attila Posted July 24, 2019 Share Posted July 24, 2019 Hi @Lesiastas For reception you only need the lines with RX. See the other UART options, like FDwfDigitalUartRateSet, in the Python examples or the manual. Link to comment Share on other sites More sharing options...
Lesiastas Posted July 25, 2019 Author Share Posted July 25, 2019 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: Thanks for everything! More power to you and Digilent! Regards, Lesiastas Link to comment Share on other sites More sharing options...
attila Posted July 25, 2019 Share Posted July 25, 2019 Hi @Lesiastas You're welcome and thank you. Link to comment Share on other sites More sharing options...
Lesiastas Posted July 26, 2019 Author Share Posted July 26, 2019 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: 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 More sharing options...
attila Posted July 26, 2019 Share Posted July 26, 2019 Hi @Lesiastas You could change in the declaration of FDwfDigitalUartRx the argument to be <MarshalAs(UnmanagedType.LPStr)> ByVal szError As StringBuilder as it is for FDwfGetLastErrorMsg. Link to comment Share on other sites More sharing options...
Question
Lesiastas
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?
Sincerely yours,
Lesiastas
Link to comment
Share on other sites
10 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.