06-15-2016 12:48 PM
I'm using VBA to communicate with the RS485 port.
The only way I can communicate successfully with the RS485 port is when I manually change the wire mode for the port in Device Manager by changing the transceiver mode setting. I can change all other port settings programmatically.
I am not using the NI library for communicating with the RS485 port. I am using Windows API function calls similar to this here: http://dev.emcelettronica.com/serial-port-communication-in-excel-vba.
In the NI library, the command for changing the wire mode is viSetAttribute(ASRL4::INSTR (0x03EF4588), ASRL_WIRE_MODE, 3). I am looking for a way to accomplish this using Visual Basic (or VBA) without using the NI library.
Any suggestions?
06-16-2016 10:33 PM - last edited on 11-16-2024 05:28 PM by Content Cleaner
Hi Joseph,
Unfortunately even after some research, I'm still having a hard time finding a good solution for setting the RS485 Wire Mode without calling into the NI API, assuming you are using NI hardware. Just to verify - will this be with some sort of NI hardware, or is this with a serial card independent of NI hardware?
viSetAttribute calls into our VISA API which abstracts away some of lower level functionality within VISA. The function call itself uses flags defined in our VISA files, so unless the API you are calling into has similar options available, it would be difficult to use the setting. Based on your link, it looks like the CommSet() function is the closest thing to our viSetAttribute, but you can only set a few of the serial communication settings.
Out of curiosity, why are you hoping to set this without using an NI library? We do have a .NET API which should play well with Visual Basic, even if you aren't using our MeasurementStudio development environment. Would that work for your application perhaps?
06-17-2016 07:37 AM
Hi Yiran,
Thanks for your repsonse and info. I am communicating with a NI PCI Card. I think it's the PCI-8431/2. The only reason I'd like to avoid using the NI API is because I started the work without it (a mistake in retrospect) and I'd like to avoid re-writing the code from scratch unless I really have to or unless I find it's faster to re-write using the NI API. I don't have a lot of time to allocate to this.
I'm guessing there might not be an equivalent single command to change the wire-mode, but instead I would have to configure the handshaking using low-level commands whenever I send and receive data. So I'm thinking that the RTS, CTS, DSR, DCD, DTR pins need to be set or cleared differently depending on the desired wire-mode. The NI API must be doing this depending on the viSetAttribute parameter for wire-mode. Is this correct?
06-19-2016 10:08 PM
Hi Joseph,
I'd have to look deeper into it to see if setting the parameters manually is possible, but I can try to get back to you with more information if you are interested. I would recommend using our API for future cases, but we can definitely explore workarounds for the time being. One thing I'd recommend for now is using our API to set the wire mode for a different session to see if it retains the latest wire mode configuration. I have no idea whether or not it would actually work, but it shouldn't take too long to try out if nothing else.