LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW serial port programming using the WinAPI and CreateFile() and CloseHandle()? Yes or no?

Solved!
Go to solution

btw, "One way to get rid of those excessive COMM port numbers"

 

Already known and done. However, how to do it and not also be running as administrator, yep, please share.

0 Kudos
Message 31 of 75
(1,459 Views)

@3d0g wrote:

What's the real reason I want help with my code?  What kind of a question is that?  I'm here. I have an issue. In the past I've been told to post my code lest I (or others have heard it) can't be helped. (Frankly, I find this forum more helpful than NI. Did I say that out loud?)  I have now posted my code. There is a problem with it, and I still have yet to get it debugged. That's the reason I created this thread. If you want to get deeply philosophical about it, I exist. Frankly, I'm trying to learn and I need to learn and I don't learn by being sent away to go read something or download things. I learn by getting those more experienced than I to show me my error, how I went wrong. Now please help me by examining my code.

 

Incidentally, if I find my error, I will be sure to post it, here, in this thread.   


The "kind of question" you refer to above is the kind of question that gets asked when someone wants to do something in a strange and non-standard way and their benefactor(s) are hoping that, by understanding the reason behind the strange request, they can help them to an alternative solution.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 32 of 75
(1,534 Views)

Are you saying that you want to connect to a COM port with a known "COM" address? You can just use a string control with the name "COM123" to the "VISA resource name" and it'll connect.

 


@3d0g wrote:
But what I know of VISA, which I admit is not a whole lot, is it uses ASRL to identify serial devices AND those numbers do not always align with Windows' numbers, for starters.

Yeah this is wrong. It can use ASRL but doesn't have to. It uses COM port numbers too. I've used VISA for more than a decade and have used the ASRL format in maybe two instances. I always just use "COM9" or whatever as my VISA resource name.

 

 

VISA example.png

 

Also I will echo the rest of the people here... you're being REALLY combative for people trying to help you for free. The fact that we're on page 3 and we're still trying to figure out what you're trying to do indicates you haven't posed a clear question.

Message 33 of 75
(1,530 Views)
Solution
Accepted by topic author 3d0g

At first: I don't know which communication parameters you want to use. It looks like 7 data bits, 1 stop bit, no parity and no handshake and no termination character.

 

The FileWrite() is wrong - your code write the pointer address plus some more bytes. Change lpBuffer to Numeric, Unsigned Pointer-sized integer, pass Value

 

With this modification, the vi transmits the correct string:

Screenshot_2023-03-21_001902_0.png

BTW: Your code uses synchronious communication, which is in most cases not the best option. 

 

 

Message 34 of 75
(1,524 Views)

What's that red dot about?

0 Kudos
Message 35 of 75
(1,522 Views)

Martin: Thank you.  ...for looking at my code.

 

Now I'll go take a look.  Seriously, thank you. 

0 Kudos
Message 36 of 75
(1,517 Views)

negative 😞

 

3d0g_0-1679355178827.png

 

The issue being debugged is threefold.

1. Why is fOutCtsFlow B1 and B2 needing to be $02 $07, respectively, such that I get success from ret_set_comm_state? (Those are bytes 1 and 2 of the DWORD.)

2.  Why does it take two shots to get even a decent looking RXBuffer?

3. Why can't it be the correct RXBuffer contents as opposed to just decent looking?

 

Clearly my code is botched somewhere.

 

Also, to address the comm state for you.

What you have there is a choice between what it got (in the get comm state, state) and what you want it to be (in the set comm state, state.)  Now, I have to explain, getting it to what you see there in the default values you see was not the easiest road. Basically, I ended frustratingly just dumping LabVIEW and firing up the LabWindows/CVI. I wrote what I wanted in C, got it working (didn't take too long, frankly,) and then used those verbose results to fine tune that set and get comm state part into operation. Once it was in operation, then I felt I was getting some where.

 

Look out to the far right, and you'll see the number of bits is 8, parity is none, stop bits is none. Look to the far left and you'll see $80 25 00 00, little endian for 9600 baud.

 

It wasn't so much about exactly what I wanted. It was about how I could take what it gave me, which it rewrote just fine, which proved my code was likely sound, and then finesse it into the config I needed, enough that it was useful. (My C code's output was the key.) 

 

Seriously, thank you for reading my code, Martin! ...and that THIS IS A TEST was a nice touch, 🙂 

 

 

0 Kudos
Message 37 of 75
(1,509 Views)

one other thing:

 

WriteFile function (fileapi.h)

Writes data to the specified file or input/output (I/O) device.

This function is designed for both synchronous and asynchronous operation. For a similar function designed solely for asynchronous operation, see WriteFileEx.

 

WriteFile() is actually what's being called in the code.

 

0 Kudos
Message 38 of 75
(1,507 Views)

FWIW,

 

before dcb get:
======= DCB start ========
DCBlength: 0x001C
BaudRate: 0x0000
fBinary: 0
fParity: 0
fOutxCtsFlow: 0
fOutxDsrFlow: 0
fDtrControl: 0
fDsrSensitivity: 0
fTXContinueOnXoff: 0
fOutX: 0
fInX: 0
fErrorChar: 0
fNull: 0
fRtsControl: 0
fAbortOnError: 0
fDummy2: 0
wReserved: 0
XonLim: 0
XoffLim: 0
ByteSize: 0
Parity: 0
StopBits: 0
XonChar: 0
XoffChar: 0
ErrorChar: 0
EofChar: 0
EvtChar: 0
wReserved1: 0
====== DCB end ======

after dcb set:
======= DCB start ========
DCBlength: 0x001C
BaudRate: 0x2580
fBinary: 1
fParity: 0
fOutxCtsFlow: 0
fOutxDsrFlow: 0
fDtrControl: 0
fDsrSensitivity: 0
fTXContinueOnXoff: 0
fOutX: 0
fInX: 0
fErrorChar: 0
fNull: 0
fRtsControl: 0
fAbortOnError: 0
fDummy2: 0
wReserved: 0
XonLim: 2048
XoffLim: 512
ByteSize: 8
Parity: 0
StopBits: 0
XonChar: 0
XoffChar: 0
ErrorChar: 0
EofChar: 1
EvtChar: 0
wReserved1: 0
====== DCB end ======

before CTO set:
======= CTO start =======
ReadIntervalTimeout: 50
ReadTotalTimeoutMultiplier: 10
ReadTotalTimeoutConstant: 50
WriteTotalTimeoutMultiplier: 10
WriteTotalTimeoutConstant: 50
======= CTO end =======

after CTO set:
======= CTO start =======
ReadIntervalTimeout: 50
ReadTotalTimeoutMultiplier: 10
ReadTotalTimeoutConstant: 50
WriteTotalTimeoutMultiplier: 10
WriteTotalTimeoutConstant: 50
======= CTO end =======
Serial port COM216 successfully configured.

Bytes written: 15

Bytes read: 15


0x54 0x48 0x49 0x53 0x20 0x49 0x53 0x20
0x41 0x20 0x54 0x45 0x53 0x54 0x0D

Closed port COM216

 

The above was my guide to getting the LabVIEW version to the state that it is...even though it is still quite broken. It's nice to have a second opinion when the LabVIEW isn't working correctly.  It's not as broken as it was last week. 🙂

0 Kudos
Message 39 of 75
(1,502 Views)

Actually, Martin, yours may be the solution.  I'd forgotten I didn't go as far with this code as with the C.  You may have just done it!

 

I'll get back with you once I know for sure we have the solution.

 

And I say we. You at least looked at my code, and I very much thank you.

 

 

0 Kudos
Message 40 of 75
(1,494 Views)