LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

viRead and viWrite not working over serial connection to device

Hi all,

 

I am new to programming with VISA.  I have some test code I am using to start the process, but I'm having some issues with it.  The device I am trying to connect with is a serial device that is proprietary to my company.  We have a very simple communications protocol - a 16-byte frame of characters - that we use to communicate back and forth.  The device echoes the first two bytes of all commands sent.  There are no start/stop characters.  I have the device at 9600 bps, with parity off, 8 bits, 1 stop bit, no flow control.  All of these are the default settings for serial communications using the VISA protocols, so that should not be the issue.  I can open the session and instrument with no trouble, but when I write, I can see by the display on the device that the command is not going through.  I then get a timeout error 0xBFFF0015 when I try to read.  I am posting the test code below.  VISAIC shows me the device is seen on COM 1 (ASRL1) with no apparent problems.  Any suggestions?  Do I need any special settings to enable the viRead and viWrite commands to work properly on a serial device?  I've been following the instructions in the manual and I can't find anything totally out of whack here.  I am attaching the file to this post.

 

Thanks in advance for any help.

 

Judy Harrigan

 

PS This code is modified from examples in the NI-VISA manual.  I am trying to do some very simple read and writes.  The Hello command should get the device's address and version number as replies (all in the 16-byte frame format).  The GUIOk notifies the device that the GUI is connected.  The Reset command simply has the device reset some readings to 0 so that I can see on the front display that the command was received and executed.

 

0 Kudos
Message 1 of 3
(3,608 Views)

You are not setting communications parameters after opening the port (speed, parity, flow control...) so I suppose the device will be set in some default settings which could be different from what the ones your device is using: try adding some viSetAttribute with those elements and see if now you can commuicate with the device. Prior to this you may try to communicate with it with HyperTerminal or some other high level communications program, just to check that cabling is correct.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,595 Views)

Hi Roberto,

 

You are a gentleman and a scholar!  I tried to talk to the device with our regular software and found that it would not connect at 9600 bps (legacy junk on an old board I am using to test).  I changed the baud rate on both sides to a higher one, added the other settings (parity, data bits, stop bit, and flow control), but that still didn't work.  I checked the manual again for serial communications and found a couple of more attributes (VI_ATTR_ASRL_END_IN, and VI_ATTR_ASRL_END_OUT) that I set to none just to be safe.  Then I made sure all the read and writes used the entire frame length of the frames sent (16 bytes) rather than the length of the string that was to be read and written.  Finally it works.  You really started me off in the right direction and I appreciate your help.

 

Judy

0 Kudos
Message 3 of 3
(3,577 Views)